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

classes/monograph/MonographSubjectDAO.inc.php

00001 <?php
00002 
00016 import('lib.pkp.classes.controlledVocab.ControlledVocabDAO');
00017 
00018 define('CONTROLLED_VOCAB_MONOGRAPH_SUBJECT', 'monographSubject');
00019 
00020 class MonographSubjectDAO extends ControlledVocabDAO {
00024    function MonographSubjectDAO() {
00025       parent::ControlledVocabDAO();
00026    }
00027 
00033    function build($monographId) {
00034       // may return an array of ControlledVocabs
00035       return parent::build(CONTROLLED_VOCAB_MONOGRAPH_SUBJECT, ASSOC_TYPE_MONOGRAPH, $monographId);
00036    }
00037 
00042    function getLocaleFieldNames() {
00043       return array('monographSubject');
00044    }
00045 
00052    function getSubjects($monographId, $locales) {
00053 
00054       $returner = array();
00055       foreach ($locales as $locale) {
00056          $returner[$locale] = array();
00057          $subjects = $this->build($monographId);
00058          $monographSubjectEntryDao =& DAORegistry::getDAO('MonographSubjectEntryDAO');
00059          $monographSubjects = $monographSubjectEntryDao->getByControlledVocabId($subjects->getId());
00060 
00061          while ($subject =& $monographSubjects->next()) {
00062             $subject = $subject->getSubject();
00063             if (array_key_exists($locale, $subject)) { // quiets PHP when there are no Subjects for a given locale
00064                $returner[$locale][] = $subject[$locale];
00065                unset($subject);
00066             }
00067          }
00068       }
00069       return $returner;
00070    }
00071 
00076    function getAllUniqueSubjects() {
00077       $subjects = array();
00078 
00079       $result =& $this->retrieve(
00080          'SELECT DISTINCT setting_value FROM controlled_vocab_entry_settings WHERE setting_name = ?', CONTROLLED_VOCAB_MONOGRAPH_SUBJECT
00081       );
00082 
00083       while (!$result->EOF) {
00084          $subjects[] = $result->fields[0];
00085          $result->MoveNext();
00086       }
00087 
00088       $result->Close();
00089       unset($result);
00090 
00091       return $subjects;
00092    }
00093 
00099    function getMonographIdsBySubject($subject) {
00100       $result =& $this->retrieve(
00101          'SELECT assoc_id
00102           FROM controlled_vocabs cv
00103           LEFT JOIN controlled_vocab_entries cve ON cv.controlled_vocab_id = cve.controlled_vocab_id
00104           INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id
00105           WHERE cves.setting_name = ? AND cves.setting_value = ?',
00106          array(CONTROLLED_VOCAB_MONOGRAPH_SUBJECT, $subject)
00107       );
00108 
00109       $returner = array();
00110       while (!$result->EOF) {
00111          $row = $result->GetRowAssoc(false);
00112          $returner[] = $row['assoc_id'];
00113          $result->MoveNext();
00114       }
00115       $result->Close();
00116       return $returner;
00117    }
00118 
00126    function insertSubjects($subjects, $monographId, $deleteFirst = true) {
00127       $subjectDao =& DAORegistry::getDAO('MonographSubjectDAO');
00128       $monographSubjectEntryDao =& DAORegistry::getDAO('MonographSubjectEntryDAO');
00129       $currentSubjects = $this->build($monographId);
00130 
00131       if ($deleteFirst) {
00132          $existingEntries = $subjectDao->enumerate($currentSubjects->getId(), CONTROLLED_VOCAB_MONOGRAPH_SUBJECT);
00133 
00134          foreach ($existingEntries as $id => $entry) {
00135             $entry = trim($entry);
00136             $monographSubjectEntryDao->deleteObjectById($id);
00137          }
00138       }
00139       if (is_array($subjects)) { // localized, array of arrays
00140 
00141          foreach ($subjects as $locale => $list) {
00142             if (is_array($list)) {
00143                $list = array_unique($list); // Remove any duplicate Subjects
00144                $i = 1;
00145                foreach ($list as $subject) {
00146                   $subjectEntry = $monographSubjectEntryDao->newDataObject();
00147                   $subjectEntry->setControlledVocabId($currentSubjects->getID());
00148                   $subjectEntry->setSubject(urldecode($subject), $locale);
00149                   $subjectEntry->setSequence($i);
00150                   $i ++;
00151                   $subjectEntryId = $monographSubjectEntryDao->insertObject($subjectEntry);
00152                }
00153             }
00154          }
00155       }
00156    }
00157 }
00158 ?>

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