19 use \DAOResultFactory;
22 use \PKP\Services\interfaces\EntityPropertyInterface;
23 use \PKP\Services\interfaces\EntityReadInterface;
24 use \PKP\Services\interfaces\EntityWriteInterface;
25 use \PKP\Services\QueryBuilders\PKPAuthorQueryBuilder;
27 class PKPAuthorService implements EntityReadInterface, EntityWriteInterface, EntityPropertyInterface {
32 public function get($authorId) {
34 return $authorDao->getById($authorId);
63 public function getMany($args = array()) {
66 $result = $authorDao->retrieveRange($authorQO->toSql(), $authorQO->getBindings());
69 return $queryResults->toIterator();
91 'publicationIds' =>
null,
94 $args = array_merge($defaultArgs, $args);
97 $authorQB->filterByName($args[
'givenName'], $args[
'familyName']);
98 if (!empty($args[
'publicationIds'])) {
99 $authorQB->filterByPublicationIds($args[
'publicationIds']);
101 if (!empty($args[
'contextIds'])) {
102 $authorQB->filterByContextIds($args[
'contextIds']);
104 if (!empty($args[
'country'])) {
105 $authorQB->filterByCountry($args[
'country']);
107 if (!empty($args[
'affiliation'])) {
108 $authorQB->filterByAffiliation($args[
'affiliation']);
120 $request = $args[
'request'];
124 foreach ($props as $prop) {
127 $values[$prop] = $author->getData($prop);
132 $locales = $request->getContext()->getSupportedFormLocales();
135 \HookRegistry::call(
'Author::getProperties::values', array(&$values, $author, $props, $args));
163 public function validate($action, $props, $allowedLocales, $primaryLocale) {
166 import(
'lib.pkp.classes.validation.ValidatorFactory');
169 $schemaService->getValidationRules(
SCHEMA_AUTHOR, $allowedLocales)
186 $validator->after(
function($validator) use ($props) {
187 if (isset($props[
'publicationId']) && !$validator->errors()->get(
'publicationId')) {
188 $publication = Services::get(
'publication')->get($props[
'publicationId']);
190 $validator->errors()->add(
'publicationId', __(
'author.publicationNotFound'));
191 }
else if ($publication->getData(
'status') === STATUS_PUBLISHED) {
192 $validator->errors()->add(
'publicationId', __(
'author.editPublishedDisabled'));
197 if ($validator->fails()) {
198 $errors = $schemaService->formatValidationErrors($validator->errors(), $schemaService->get(
SCHEMA_AUTHOR), $allowedLocales);
201 \HookRegistry::call(
'Author::validate', array(&$errors, $action, $props, $allowedLocales, $primaryLocale));
209 public function add($author, $request) {
211 $authorId = $authorDao->insertObject($author);
212 $author = $this->
get($authorId);
222 public function edit($author, $params, $request) {
225 $newAuthor = $authorDao->newDataObject();
226 $newAuthor->_data = array_merge($author->_data, $params);
230 $authorDao->updateObject($newAuthor);
231 $newAuthor = $this->
get($newAuthor->getId());
239 public function delete($author) {
242 $authorDao->deleteObject($author);