• Main Page
  • Modules
  • Classes
  • Files
  • File List

classes/monograph/ChapterAuthorDAO.inc.php

00001 <?php
00002 
00019 import('classes.monograph.Chapter');
00020 import('classes.monograph.ChapterAuthor');
00021 
00022 class ChapterAuthorDAO extends DAO {
00026    function ChapterAuthorDAO() {
00027       parent::DAO();
00028    }
00029 
00036    function &getAuthors($monographId = null, $chapterId = null) {
00037       $params = array(
00038          'affiliation', AppLocale::getPrimaryLocale(),
00039          'affiliation', AppLocale::getLocale()
00040       );
00041       if (isset($monographId)) $params[] = (int) $monographId;
00042       if (isset($chapterId)) $params[] = (int) $chapterId;
00043       // get all the monograph_author fields,
00044       // but replace the primary_contact and seq with monograph_chapter_authors.primary_contact
00045 
00046       $sql = 'SELECT ma.author_id,
00047             ma.submission_id,
00048             mca.chapter_id,
00049             mca.primary_contact,
00050             mca.seq,
00051             ma.first_name,
00052             ma.middle_name,
00053             ma.last_name,
00054             asl.setting_value AS affiliation_l,
00055             asl.locale,
00056             aspl.setting_value AS affiliation_pl,
00057             aspl.locale AS primary_locale,
00058             ma.country,
00059             ma.email,
00060             ma.url,
00061             ma.user_group_id
00062          FROM  authors ma
00063             JOIN monograph_chapter_authors mca ON (ma.author_id = mca.author_id)
00064             LEFT JOIN author_settings aspl ON (mca.author_id = aspl.author_id AND aspl.setting_name = ? AND aspl.locale = ?)
00065             LEFT JOIN author_settings asl ON (mca.author_id = asl.author_id AND asl.setting_name = ? AND asl.locale = ?)' .
00066          ( (count($params)> 0)?' WHERE':'' ) .
00067          (  isset($monographId)?' ma.submission_id = ?':'' ) .
00068          (  (isset($monographId) && isset($chapterId))?' AND':'' ) .
00069          (  isset($chapterId)?' mca.chapter_id = ?':'' ) .
00070          ' ORDER BY mca.chapter_id, mca.seq';
00071 
00072       $result =& $this->retrieve($sql, $params);
00073 
00074       $returner = new DAOResultFactory($result, $this, '_returnFromRow', array('id'));
00075       return $returner;
00076    }
00077 
00084    function getAuthorIdsByChapterId($chapterId, $monographId = null) {
00085       $params = array((int) $chapterId);
00086       if ($monographId) $params[] = (int) $monographId;
00087 
00088       $result =& $this->retrieve(
00089          'SELECT author_id
00090          FROM monograph_chapter_authors
00091          WHERE chapter_id = ?
00092          ' . ($monographId?' AND monograph_id = ?':''),
00093          $params
00094       );
00095 
00096       $authorIds = array();
00097       while (!$result->EOF) {
00098          $authorIds[] = $result->fields[0];
00099          $result->MoveNext();
00100       }
00101 
00102       $result->Close();
00103       unset($result);
00104 
00105       return $authorIds;
00106    }
00107 
00114    function insertChapterAuthor($authorId, $chapterId, $monographId, $isPrimary = false, $sequence = 0) {
00115       //FIXME: How to handle sequence?
00116       $this->update(
00117          'INSERT INTO monograph_chapter_authors
00118             (author_id, chapter_id, monograph_id, primary_contact, seq)
00119             VALUES
00120             (?, ?, ?, ?, ?)',
00121          array(
00122             (int) $authorId,
00123             (int) $chapterId,
00124             (int) $monographId,
00125             (int) $isPrimary,
00126             (int) $sequence
00127          )
00128       );
00129    }
00130 
00135    function deleteChapterAuthorById($authorId, $chapterId = null) {
00136       $params = array((int) $authorId);
00137       if ($chapterId) $params[] = (int) $chapterId;
00138 
00139       $this->update(
00140          'DELETE FROM monograph_chapter_authors WHERE author_id = ?' .
00141          ($chapterId?' AND chapter_id = ?':''),
00142          $params
00143       );
00144    }
00145 
00151    function _returnFromRow(&$row) {
00152       // Start with an Author object and copy the common elements
00153       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00154       $author =& $authorDao->_returnAuthorFromRow($row);
00155 
00156       $chapterAuthor = new ChapterAuthor();
00157       $chapterAuthor->setId($author->getId());
00158       $chapterAuthor->setSubmissionId($author->getSubmissionId());
00159       $chapterAuthor->setFirstName($author->getFirstName());
00160       $chapterAuthor->setMiddleName($author->getMiddleName());
00161       $chapterAuthor->setLastName($author->getLastName());
00162       $chapterAuthor->setAffiliation($author->getAffiliation(null), null);
00163       $chapterAuthor->setCountry($author->getCountry());
00164       $chapterAuthor->setEmail($author->getEmail());
00165       $chapterAuthor->setUrl($author->getUrl());
00166       $chapterAuthor->setUserGroupId($author->getUserGroupId());
00167 
00168       // Add additional data that is chapter author specific
00169       $chapterAuthor->setPrimaryContact($row['primary_contact']);
00170       $chapterAuthor->setSequence($row['seq']);    ;
00171       $chapterAuthor->setChapterId($row['chapter_id']);
00172 
00173       return $chapterAuthor;
00174    }
00175 }
00176 
00177 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1