00001 <?php
00002
00019 import('classes.monograph.Author');
00020 import('classes.monograph.Monograph');
00021 import('lib.pkp.classes.submission.PKPAuthorDAO');
00022
00023 class AuthorDAO extends PKPAuthorDAO {
00027 function AuthorDAO() {
00028 parent::PKPAuthorDAO();
00029 }
00030
00041 function &getAuthorsAlphabetizedByPress($pressId = null, $initial = null, $rangeInfo = null) {
00042 $authors = array();
00043 $params = array(
00044 'affiliation', AppLocale::getPrimaryLocale(),
00045 'affiliation', AppLocale::getLocale()
00046 );
00047
00048 if (isset($pressId)) $params[] = $pressId;
00049 if (isset($initial)) {
00050 $params[] = String::strtolower($initial) . '%';
00051 $initialSql = ' AND LOWER(ma.last_name) LIKE LOWER(?)';
00052 } else {
00053 $initialSql = '';
00054 }
00055
00056 $result =& $this->retrieveRange(
00057 'SELECT DISTINCT
00058 CAST(\'\' AS CHAR) AS url,
00059 ma.author_id AS author_id,
00060 ma.submission_id AS submission_id,
00061 CAST(\'\' AS CHAR) AS email,
00062 0 AS primary_contact,
00063 0 AS seq,
00064 ma.first_name AS first_name,
00065 ma.middle_name AS middle_name,
00066 ma.last_name AS last_name,
00067 asl.setting_value AS affiliation_l,
00068 asl.locale,
00069 aspl.setting_value AS affiliation_pl,
00070 aspl.locale AS primary_locale,
00071 ma.suffix AS suffix,
00072 ma.user_group_id AS user_group_id,
00073 ma.country
00074 FROM authors ma
00075 LEFT JOIN author_settings aspl ON (ma.author_id = aspl.author_id AND aspl.setting_name = ? AND aspl.locale = ?)
00076 LEFT JOIN author_settings asl ON (ma.author_id = asl.author_id AND asl.setting_name = ? AND asl.locale = ?)
00077 JOIN monographs a ON (ma.submission_id = a.monograph_id)
00078 WHERE a.status = ' . STATUS_PUBLISHED . ' ' .
00079 (isset($pressId)?'AND a.press_id = ? ':'') . '
00080 AND (ma.last_name IS NOT NULL AND ma.last_name <> \'\')' .
00081 $initialSql . '
00082 ORDER BY ma.last_name, ma.first_name',
00083 $params,
00084 $rangeInfo
00085 );
00086
00087 $returner = new DAOResultFactory($result, $this, '_returnAuthorFromRow');
00088 return $returner;
00089 }
00090
00095 function newDataObject() {
00096 return new Author();
00097 }
00098
00103 function insertAuthor(&$author) {
00104
00105 if(!$author->getSequence()) {
00106 $authorCount = $this->getAuthorCountBySubmissionId($author->getSubmissionId());
00107 $author->setSequence($authorCount + 1);
00108 }
00109
00110 if ($author->getPrimaryContact()) {
00111 $this->resetPrimaryContact($author->getId(), $author->getSubmissionId());
00112 }
00113
00114 $this->update(
00115 'INSERT INTO authors
00116 (submission_id, first_name, middle_name, last_name, suffix, country, email, url, user_group_id, primary_contact, seq)
00117 VALUES
00118 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
00119 array(
00120 $author->getSubmissionId(),
00121 $author->getFirstName(),
00122 $author->getMiddleName() . '',
00123 $author->getLastName(),
00124 $author->getSuffix() . '',
00125 $author->getCountry(),
00126 $author->getEmail(),
00127 $author->getUrl(),
00128 (int) $author->getUserGroupId(),
00129 (int) $author->getPrimaryContact(),
00130 (float) $author->getSequence()
00131 )
00132 );
00133
00134 $author->setId($this->getInsertAuthorId());
00135 $this->updateLocaleFields($author);
00136
00137 return $author->getId();
00138 }
00139
00144 function updateAuthor($author) {
00145
00146 if ($author->getPrimaryContact()) {
00147 $this->resetPrimaryContact($author->getId(), $author->getSubmissionId());
00148 }
00149 $returner = $this->update(
00150 'UPDATE authors
00151 SET first_name = ?,
00152 middle_name = ?,
00153 last_name = ?,
00154 suffix = ?,
00155 country = ?,
00156 email = ?,
00157 url = ?,
00158 user_group_id = ?,
00159 primary_contact = ?,
00160 seq = ?
00161 WHERE author_id = ?',
00162 array(
00163 $author->getFirstName(),
00164 $author->getMiddleName() . '',
00165 $author->getLastName(),
00166 $author->getSuffix() . '',
00167 $author->getCountry(),
00168 $author->getEmail(),
00169 $author->getUrl(),
00170 (int) $author->getUserGroupId(),
00171 (int) $author->getPrimaryContact(),
00172 (float) $author->getSequence(),
00173 (int) $author->getId()
00174 )
00175 );
00176 $this->updateLocaleFields($author);
00177 return $returner;
00178 }
00179
00184 function deleteAuthorsByMonograph($submissionId) {
00185 $authors =& $this->getAuthorsBySubmissionId($submissionId);
00186 foreach ($authors as $author) {
00187 $this->deleteAuthor($author);
00188 }
00189 }
00190 }
00191
00192 ?>