classes/rt/ocs/RTDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('rt.ocs.ConferenceRT');
00019 
00020 class RTDAO extends DAO {
00021    //
00022    // RT
00023    //
00024 
00030    function &getConferenceRTByConference(&$conference) {
00031       $rt = new ConferenceRT($conference->getId());
00032       $rt->setEnabled($conference->getSetting('rtEnabled')?true:false);
00033       $rt->setVersion((int) $conference->getSetting('rtVersionId'));
00034       $rt->setAbstract($conference->getSetting('rtAbstract')?true:false);
00035       $rt->setCaptureCite($conference->getSetting('rtCaptureCite')?true:false);
00036       $rt->setViewMetadata($conference->getSetting('rtViewMetadata')?true:false);
00037       $rt->setSupplementaryFiles($conference->getSetting('rtSupplementaryFiles')?true:false);
00038       $rt->setPrinterFriendly($conference->getSetting('rtPrinterFriendly')?true:false);
00039       $rt->setAuthorBio($conference->getSetting('rtAuthorBio')?true:false);
00040       $rt->setDefineTerms($conference->getSetting('rtDefineTerms')?true:false);
00041       $rt->setAddComment($conference->getSetting('rtAddComment')?true:false);
00042       $rt->setEmailAuthor($conference->getSetting('rtEmailAuthor')?true:false);
00043       $rt->setEmailOthers($conference->getSetting('rtEmailOthers')?true:false);
00044       $rt->setFindingReferences($conference->getSetting('rtFindingReferences')?true:false);
00045       return $rt;
00046    }
00047 
00048    function updateConferenceRT(&$rt) {
00049       $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00050       $conference =& $conferenceDao->getConference($rt->getConferenceId());
00051 
00052       $conference->updateSetting('rtEnabled', $rt->getEnabled(), 'bool');
00053       $conference->updateSetting('rtVersionId', $rt->getVersion(), 'int');
00054       $conference->updateSetting('rtAbstract', $rt->getAbstract(), 'bool');
00055       $conference->updateSetting('rtCaptureCite', $rt->getCaptureCite(), 'bool');
00056       $conference->updateSetting('rtViewMetadata', $rt->getViewMetadata(), 'bool');
00057       $conference->updateSetting('rtSupplementaryFiles', $rt->getSupplementaryFiles(), 'bool');
00058       $conference->updateSetting('rtPrinterFriendly', $rt->getPrinterFriendly(), 'bool');
00059       $conference->updateSetting('rtAuthorBio', $rt->getAuthorBio(), 'bool');
00060       $conference->updateSetting('rtDefineTerms', $rt->getDefineTerms(), 'bool');
00061       $conference->updateSetting('rtAddComment', $rt->getAddComment(), 'bool');
00062       $conference->updateSetting('rtEmailAuthor', $rt->getEmailAuthor(), 'bool');
00063       $conference->updateSetting('rtEmailOthers', $rt->getEmailOthers(), 'bool');
00064       $conference->updateSetting('rtFindingReferences', $rt->getFindingReferences());
00065       return true;
00066    }
00067 
00072    function insertConferenceRT(&$rt) {
00073       return $this->updateConferenceRT($rt);
00074    }
00075 
00076    //
00077    // RT Versions
00078    //
00079 
00086    function &getVersions($conferenceId, $pagingInfo = null) {
00087       $versions = array();
00088 
00089       $result =& $this->retrieveRange(
00090          'SELECT * FROM rt_versions WHERE conference_id = ? ORDER BY version_key',
00091          (int) $conferenceId,
00092          $pagingInfo
00093       );
00094 
00095       $returner = new DAOResultFactory($result, $this, '_returnVersionFromRow');
00096       return $returner;
00097    }
00098 
00105    function &getVersion($versionId, $conferenceId) {
00106       $result =& $this->retrieve(
00107          'SELECT * FROM rt_versions WHERE version_id = ? AND conference_id = ?',
00108          array((int) $versionId, (int) $conferenceId)
00109       );
00110 
00111       $returner = null;
00112       if ($result->RecordCount() != 0) {
00113          $returner =& $this->_returnVersionFromRow($result->GetRowAssoc(false));
00114       }
00115 
00116       $result->Close();
00117       unset($result);
00118 
00119       return $returner;
00120    }
00121 
00127    function insertVersion($conferenceId, &$version) {
00128       $this->update(
00129          'INSERT INTO rt_versions
00130          (conference_id, version_key, locale, title, description)
00131          VALUES
00132          (?, ?, ?, ?, ?)',
00133          array((int) $conferenceId, $version->key, $version->locale, $version->title, $version->description)
00134       );
00135 
00136       $version->versionId = $this->getInsertId('rt_versions', 'version_id');
00137 
00138       foreach ($version->contexts as $context) {
00139          $context->versionId = $version->versionId;
00140          $this->insertContext($context);
00141       }
00142 
00143       return $version->versionId;
00144    }
00145 
00151    function updateVersion($conferenceId, &$version) {
00152       // FIXME Update contexts and searches?
00153       return $this->update(
00154          'UPDATE rt_versions
00155          SET
00156             title = ?,
00157             description = ?,
00158             version_key = ?,
00159             locale = ?
00160          WHERE version_id = ? AND conference_id = ?',
00161          array(
00162             $version->getTitle(),
00163             $version->getDescription(),
00164             $version->getKey(),
00165             $version->getLocale(),
00166             (int) $version->getVersionId(),
00167             (int) $conferenceId
00168          )
00169       );
00170    }
00171 
00176    function deleteVersionsByConferenceId($conferenceId) {
00177       $versions =& $this->getVersions($conferenceId);
00178       foreach ($versions->toArray() as $version) {
00179          $this->deleteVersion($version->getVersionId(), $conferenceId);
00180       }
00181    }
00182 
00188    function deleteVersion($versionId, $conferenceId) {
00189       $this->deleteContextsByVersionId($versionId);
00190       return $this->update(
00191          'DELETE FROM rt_versions WHERE version_id = ? AND conference_id = ?',
00192          array((int) $versionId, (int) $conferenceId)
00193       );
00194    }
00195 
00200    function deleteVersionsByConference($conferenceId) {
00201       $versions =& RTDAO::getVersions($conferenceId);
00202       while (!$versions->eof()) {
00203          $version =& $versions->next();
00204          $this->deleteVersion($version->getVersionId(), $conferenceId);
00205       }
00206    }
00207 
00213    function &_returnVersionFromRow(&$row) {
00214       $version = new RTVersion();
00215       $version->setVersionId($row['version_id']);
00216       $version->setKey($row['version_key']);
00217       $version->setLocale($row['locale']);
00218       $version->setTitle($row['title']);
00219       $version->setDescription($row['description']);
00220 
00221       if (!HookRegistry::call('RTDAO::_returnVersionFromRow', array(&$version, &$row))) {
00222          $contextsIterator =& $this->getContexts($row['version_id']);
00223          $version->setContexts($contextsIterator->toArray());
00224       }
00225 
00226       return $version;
00227    }
00228 
00234    function &_returnSearchFromRow(&$row) {
00235       $search = new RTSearch();
00236       $search->setSearchId($row['search_id']);
00237       $search->setContextId($row['context_id']);
00238       $search->setTitle($row['title']);
00239       $search->setDescription($row['description']);
00240       $search->setUrl($row['url']);
00241       $search->setSearchUrl($row['search_url']);
00242       $search->setSearchPost($row['search_post']);
00243       $search->setOrder($row['seq']);
00244 
00245       HookRegistry::call('RTDAO::_returnSearchFromRow', array(&$search, &$row));
00246 
00247       return $search;
00248    }
00249 
00250 
00251 
00252    //
00253    // RT Contexts
00254    //
00255 
00261    function &getContext($contextId) {
00262       $result =& $this->retrieve(
00263          'SELECT * FROM rt_contexts WHERE context_id = ?',
00264          array((int) $contextId)
00265       );
00266 
00267       $returner = null;
00268       if ($result->RecordCount() != 0) {
00269          $returner =& $this->_returnContextFromRow($result->GetRowAssoc(false));
00270       }
00271 
00272       $result->Close();
00273       unset($result);
00274 
00275       return $returner;
00276    }
00277 
00284    function &getContexts($versionId, $pagingInfo = null) {
00285       $contexts = array();
00286 
00287       $result =& $this->retrieveRange(
00288          'SELECT * FROM rt_contexts WHERE version_id = ? ORDER BY seq',
00289          array((int) $versionId),
00290          $pagingInfo
00291       );
00292 
00293       $returner = new DAOResultFactory($result, $this, '_returnContextFromRow');
00294       return $returner;
00295    }
00296 
00302    function insertContext(&$context) {
00303       $this->update(
00304          'INSERT INTO rt_contexts
00305          (version_id, title, abbrev, description, cited_by, author_terms, geo_terms, define_terms, seq)
00306          VALUES
00307          (?, ?, ?, ?, ?, ?, ?, ?, ?)',
00308          array(
00309             (int) $context->versionId,
00310             $context->title,
00311             $context->abbrev,
00312             $context->description,
00313             $context->citedBy?1:0,
00314             $context->authorTerms?1:0,
00315             $context->geoTerms?1:0,
00316             $context->defineTerms?1:0,
00317             (int) $context->order
00318          )
00319       );
00320 
00321       $context->contextId = $this->getInsertId('rt_contexts', 'context_id');
00322 
00323       foreach ($context->searches as $search) {
00324          $search->contextId = $context->contextId;
00325          $this->insertSearch($search);
00326       }
00327 
00328       return $context->contextId;
00329    }
00330 
00335    function updateContext(&$context) {
00336       // FIXME Update searches?
00337       return $this->update(
00338          'UPDATE rt_contexts
00339          SET title = ?, abbrev = ?, description = ?, cited_by = ?, author_terms = ?, geo_terms = ?, define_terms = ?, seq = ?
00340          WHERE context_id = ? AND version_id = ?',
00341          array($context->title, $context->abbrev, $context->description, $context->citedBy?1:0, $context->authorTerms?1:0, $context->geoTerms?1:0, $context->defineTerms?1:0, (int) $context->order, (int) $context->contextId, (int) $context->versionId)
00342       );
00343    }
00344 
00349    function deleteContextsByVersionId($versionId) {
00350       $contexts =& $this->getContexts($versionId);
00351       foreach ($contexts->toArray() as $context) {
00352          $this->deleteContext(
00353             $context->getContextId(),
00354             $context->getVersionId()
00355          );
00356       }
00357    }
00358 
00364    function deleteContext($contextId, $versionId) {
00365       $result = $this->update(
00366          'DELETE FROM rt_contexts WHERE context_id = ? AND version_id = ?',
00367          array((int) $contextId, (int) $versionId)
00368       );
00369       if ($result) $this->deleteSearchesByContextId($contextId);
00370       return $result;
00371    }
00372 
00376    function resequenceContexts($versionId) {
00377       $result =& $this->retrieve(
00378          'SELECT context_id FROM rt_contexts WHERE version_id = ? ORDER BY seq',
00379          array((int) $versionId)
00380       );
00381 
00382       for ($i=1; !$result->EOF; $i++) {
00383          list($contextId) = $result->fields;
00384          $this->update(
00385             'UPDATE rt_contexts SET seq = ? WHERE context_id = ?',
00386             array(
00387                $i,
00388                $contextId
00389             )
00390          );
00391 
00392          $result->moveNext();
00393       }
00394 
00395       $result->close();
00396       unset($result);
00397    }
00398 
00404    function &_returnContextFromRow(&$row) {
00405       $context = new RTContext();
00406       $context->setContextId($row['context_id']);
00407       $context->setVersionId($row['version_id']);
00408       $context->setTitle($row['title']);
00409       $context->setAbbrev($row['abbrev']);
00410       $context->setDescription($row['description']);
00411       $context->setCitedBy($row['cited_by']);
00412       $context->setAuthorTerms($row['author_terms']);
00413       $context->setGeoTerms($row['geo_terms']);
00414       $context->setDefineTerms($row['define_terms']);
00415       $context->setOrder($row['seq']);
00416 
00417       if (!HookRegistry::call('RTDAO::_returnContextFromRow', array(&$context, &$row))) {
00418          $searchesIterator =& $this->getSearches($row['context_id']);
00419          $context->setSearches($searchesIterator->toArray());
00420       }
00421 
00422       return $context;
00423    }
00424 
00425 
00426 
00427    //
00428    // RT Searches
00429    //
00430 
00436    function &getSearch($searchId) {
00437       $result =& $this->retrieve(
00438          'SELECT * FROM rt_searches WHERE search_id = ?',
00439          array((int) $searchId)
00440       );
00441 
00442       $returner = null;
00443       if ($result->RecordCount() != 0) {
00444          $returner =& $this->_returnSearchFromRow($result->GetRowAssoc(false));
00445       }
00446 
00447       $result->Close();
00448       unset($result);
00449 
00450       return $returner;
00451    }
00452 
00459    function &getSearches($contextId, $pagingInfo = null) {
00460       $searches = array();
00461 
00462       $result =& $this->retrieveRange(
00463          'SELECT * FROM rt_searches WHERE context_id = ? ORDER BY seq',
00464          array((int) $contextId),
00465          $pagingInfo
00466       );
00467 
00468       $returner = new DAOResultFactory($result, $this, '_returnSearchFromRow');
00469       return $returner;
00470    }
00471 
00476    function insertSearch(&$search) {
00477       $this->update(
00478          'INSERT INTO rt_searches
00479          (context_id, title, description, url, search_url, search_post, seq)
00480          VALUES
00481          (?, ?, ?, ?, ?, ?, ?)',
00482          array(
00483             (int) $search->getContextId(),
00484             $search->getTitle(),
00485             $search->getDescription(),
00486             $search->getUrl(),
00487             $search->getSearchUrl(),
00488             $search->getSearchPost(),
00489             (int) $search->getOrder()
00490          )
00491       );
00492 
00493       $search->searchId = $this->getInsertId('rt_searches', 'search_id');
00494       return $search->searchId;
00495    }
00496 
00501    function updateSearch(&$search) {
00502       return $this->update(
00503          'UPDATE rt_searches
00504          SET title = ?, description = ?, url = ?, search_url = ?, search_post = ?, seq = ?
00505          WHERE search_id = ? AND context_id = ?',
00506          array(
00507             $search->getTitle(),
00508             $search->getDescription(),
00509             $search->getUrl(),
00510             $search->getSearchUrl(),
00511             $search->getSearchPost(),
00512             (int) $search->getOrder(),
00513             (int) $search->getSearchId(),
00514             (int) $search->getContextId()
00515          )
00516       );
00517    }
00518 
00523    function deleteSearchesByContextId($contextId) {
00524       return $this->update(
00525          'DELETE FROM rt_searches WHERE context_id = ?',
00526          array((int) $contextId)
00527       );
00528    }
00529 
00535    function deleteSearch($searchId, $contextId) {
00536       return $this->update(
00537          'DELETE FROM rt_searches WHERE search_id = ? AND context_id = ?',
00538          array((int) $searchId, (int) $contextId)
00539       );
00540    }
00541 
00545    function resequenceSearches($contextId) {
00546       $result =& $this->retrieve(
00547          'SELECT search_id FROM rt_searches WHERE context_id = ? ORDER BY seq',
00548          array((int) $contextId)
00549       );
00550 
00551       for ($i=1; !$result->EOF; $i++) {
00552          list($searchId) = $result->fields;
00553          $this->update(
00554             'UPDATE rt_searches SET seq = ? WHERE search_id = ?',
00555             array(
00556                $i,
00557                $searchId
00558             )
00559          );
00560 
00561          $result->moveNext();
00562       }
00563 
00564       $result->close();
00565       unset($result);
00566    }
00567 }
00568 
00569 ?>

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