classes/paper/AuthorDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('paper.Author');
00019 import('paper.Paper');
00020 
00021 class AuthorDAO extends DAO {
00027    function &getAuthor($authorId) {
00028       $result =& $this->retrieve(
00029          'SELECT * FROM paper_authors WHERE author_id = ?', $authorId
00030       );
00031 
00032       $returner = null;
00033       if ($result->RecordCount() != 0) {
00034          $returner =& $this->_returnAuthorFromRow($result->GetRowAssoc(false));
00035       }
00036 
00037       $result->Close();
00038       unset($result);
00039 
00040       return $returner;
00041    }
00042 
00048    function &getAuthorsByPaper($paperId) {
00049       $authors = array();
00050 
00051       $result =& $this->retrieve(
00052          'SELECT * FROM paper_authors WHERE paper_id = ? ORDER BY seq',
00053          $paperId
00054       );
00055 
00056       while (!$result->EOF) {
00057          $authors[] =& $this->_returnAuthorFromRow($result->GetRowAssoc(false));
00058          $result->moveNext();
00059       }
00060 
00061       $result->Close();
00062       unset($result);
00063 
00064       return $authors;
00065    }
00066 
00077    function &getPublishedPapersForAuthor($schedConfId, $firstName, $middleName, $lastName, $affiliation, $country) {
00078       $publishedPapers = array();
00079       $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00080       $params = array($firstName, $middleName, $lastName, $affiliation, $country);
00081       if ($schedConfId !== null) $params[] = $schedConfId;
00082 
00083       $result =& $this->retrieve(
00084          'SELECT DISTINCT
00085             aa.paper_id
00086          FROM paper_authors aa
00087             LEFT JOIN papers a ON (aa.paper_id = a.paper_id)
00088          WHERE aa.first_name = ? AND
00089             a.status = ' . STATUS_PUBLISHED . ' AND
00090             (aa.middle_name = ?' . (empty($middleName)?' OR aa.middle_name IS NULL':'') .  ') AND
00091             aa.last_name = ? AND
00092             (aa.affiliation = ?' . (empty($affiliation)?' OR aa.affiliation IS NULL':'') . ') AND
00093             (aa.country = ?' . (empty($country)?' OR aa.country IS NULL':'') . ')' .
00094             ($schedConfId!==null?(' AND a.sched_conf_id = ?'):''),
00095          $params
00096       );
00097 
00098       while (!$result->EOF) {
00099          $row =& $result->getRowAssoc(false);
00100          $publishedPaper =& $publishedPaperDao->getPublishedPaperByPaperId($row['paper_id']);
00101          if ($publishedPaper) {
00102             $publishedPapers[] =& $publishedPaper;
00103          }
00104          $result->moveNext();
00105       }
00106 
00107       $result->Close();
00108       unset($result);
00109 
00110       return $publishedPapers;
00111    }
00112 
00123    function &getAuthorsAlphabetizedBySchedConf($schedConfId = null, $initial = null, $rangeInfo = null, $includeEmail = false) {
00124       $params = array();
00125 
00126       if (isset($schedConfId)) $params[] = $schedConfId;
00127       if (isset($initial)) {
00128          $params[] = String::strtolower($initial) . '%';
00129          $initialSql = ' AND LOWER(aa.last_name) LIKE LOWER(?)';
00130       } else {
00131          $initialSql = '';
00132       }
00133 
00134       $result =& $this->retrieveRange(
00135          'SELECT  DISTINCT CAST(\'\' AS CHAR) AS url,
00136             0 AS author_id,
00137             0 AS paper_id,
00138             ' . ($includeEmail?'aa.email AS email,':'CAST(\'\' AS CHAR) AS email,') . '
00139             0 AS primary_contact,
00140             0 AS seq,
00141             aa.first_name AS first_name,
00142             aa.middle_name AS middle_name,
00143             aa.last_name AS last_name,
00144             aa.affiliation AS affiliation,
00145             aa.country FROM paper_authors aa,
00146             papers a,
00147             published_papers pa,
00148             sched_confs e
00149          WHERE e.sched_conf_id = pa.sched_conf_id
00150             AND aa.paper_id = a.paper_id
00151             ' . (isset($schedConfId)?'AND a.sched_conf_id = ? ':'') . '
00152             AND pa.paper_id = a.paper_id
00153             AND a.status = ' . STATUS_PUBLISHED . '
00154             AND (aa.last_name IS NOT NULL
00155             AND aa.last_name <> \'\')' . $initialSql . ' ORDER BY aa.last_name, aa.first_name',
00156          empty($params)?false:$params,
00157          $rangeInfo
00158       );
00159 
00160       $returner = new DAOResultFactory($result, $this, '_returnAuthorFromRow');
00161       return $returner;
00162    }
00163 
00169    function &getAuthorIdsByPaper($paperId) {
00170       $authors = array();
00171 
00172       $result =& $this->retrieve(
00173          'SELECT author_id FROM paper_authors WHERE paper_id = ? ORDER BY seq',
00174          $paperId
00175       );
00176 
00177       while (!$result->EOF) {
00178          $authors[] = $result->fields[0];
00179          $result->moveNext();
00180       }
00181 
00182       $result->Close();
00183       unset($result);
00184 
00185       return $authors;
00186    }
00187 
00192    function getLocaleFieldNames() {
00193       return array('biography');
00194    }
00195 
00200    function updateLocaleFields(&$author) {
00201       $this->updateDataObjectSettings('paper_author_settings', $author, array(
00202          'author_id' => $author->getId()
00203       ));
00204 
00205    }
00206 
00212    function &_returnAuthorFromRow(&$row) {
00213       $author = new Author();
00214       $author->setId($row['author_id']);
00215       $author->setPaperId($row['paper_id']);
00216       $author->setFirstName($row['first_name']);
00217       $author->setMiddleName($row['middle_name']);
00218       $author->setLastName($row['last_name']);
00219       $author->setAffiliation($row['affiliation']);
00220       $author->setCountry($row['country']);
00221       $author->setEmail($row['email']);
00222       $author->setUrl($row['url']);
00223       $author->setPrimaryContact($row['primary_contact']);
00224       $author->setSequence($row['seq']);
00225 
00226       $this->getDataObjectSettings('paper_author_settings', 'author_id', $row['author_id'], $author);
00227 
00228       HookRegistry::call('AuthorDAO::_returnAuthorFromRow', array(&$author, &$row));
00229 
00230       return $author;
00231    }
00232 
00237    function insertAuthor(&$author) {
00238       $this->update(
00239          'INSERT INTO paper_authors
00240             (paper_id, first_name, middle_name, last_name, affiliation, country, email, url, primary_contact, seq)
00241             VALUES
00242             (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
00243          array(
00244             $author->getPaperId(),
00245             $author->getFirstName(),
00246             $author->getMiddleName() . '', // make non-null
00247             $author->getLastName(),
00248             $author->getAffiliation() . '', // make non-null
00249             $author->getCountry(),
00250             $author->getEmail(),
00251             $author->getUrl(),
00252             (int) $author->getPrimaryContact(),
00253             (float) $author->getSequence()
00254          )
00255       );
00256 
00257       $author->setId($this->getInsertAuthorId());
00258       $this->updateLocaleFields($author);
00259 
00260       return $author->getId();
00261    }
00262 
00267    function updateAuthor(&$author) {
00268       $returner = $this->update(
00269          'UPDATE paper_authors
00270             SET
00271                first_name = ?,
00272                middle_name = ?,
00273                last_name = ?,
00274                affiliation = ?,
00275                country = ?,
00276                email = ?,
00277                url = ?,
00278                primary_contact = ?,
00279                seq = ?
00280             WHERE author_id = ?',
00281          array(
00282             $author->getFirstName(),
00283             $author->getMiddleName() . '', // make non-null
00284             $author->getLastName(),
00285             $author->getAffiliation() . '', // make non-null
00286             $author->getCountry(),
00287             $author->getEmail(),
00288             $author->getUrl(),
00289             $author->getPrimaryContact(),
00290             $author->getSequence(),
00291             $author->getId()
00292          )
00293       );
00294       $this->updateLocaleFields($author);
00295       return $returner;
00296    }
00297 
00302    function deleteAuthor(&$author) {
00303       return $this->deleteAuthorById($author->getId());
00304    }
00305 
00311    function deleteAuthorById($authorId, $paperId = null) {
00312       $params = array($authorId);
00313       if ($paperId) $params[] = $paperId;
00314       $returner = $this->update(
00315          'DELETE FROM paper_authors WHERE author_id = ?' .
00316          ($paperId?' AND paper_id = ?':''),
00317          $params
00318       );
00319       if ($returner) $this->update('DELETE FROM paper_author_settings WHERE author_id = ?', array($authorId));
00320    }
00321 
00326    function deleteAuthorsByPaper($paperId) {
00327       $authors =& $this->getAuthorsByPaper($paperId);
00328       foreach ($authors as $author) {
00329          $this->deleteAuthor($author);
00330       }
00331    }
00332 
00337    function resequenceAuthors($paperId) {
00338       $result =& $this->retrieve(
00339          'SELECT author_id FROM paper_authors WHERE paper_id = ? ORDER BY seq', $paperId
00340       );
00341 
00342       for ($i=1; !$result->EOF; $i++) {
00343          list($authorId) = $result->fields;
00344          $this->update(
00345             'UPDATE paper_authors SET seq = ? WHERE author_id = ?',
00346             array(
00347                $i,
00348                $authorId
00349             )
00350          );
00351 
00352          $result->moveNext();
00353       }
00354 
00355       $result->close();
00356       unset($result);
00357    }
00358 
00363    function getInsertAuthorId() {
00364       return $this->getInsertId('paper_authors', 'author_id');
00365    }
00366 }
00367 
00368 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7