00001 <?php
00002
00016
00017
00018
00019 import('rt.ojs.JournalRT');
00020
00021 class RTDAO extends DAO {
00022
00023
00024
00025
00031 function &getJournalRTByJournal(&$journal) {
00032 $rt = &new JournalRT($journal->getJournalId());
00033 $rt->setEnabled($journal->getSetting('rtEnabled')?true:false);
00034 $rt->setVersion((int) $journal->getSetting('rtVersionId'));
00035 $rt->setAbstract($journal->getSetting('rtAbstract')?true:false);
00036 $rt->setCaptureCite($journal->getSetting('rtCaptureCite')?true:false);
00037 $rt->setViewMetadata($journal->getSetting('rtViewMetadata')?true:false);
00038 $rt->setSupplementaryFiles($journal->getSetting('rtSupplementaryFiles')?true:false);
00039 $rt->setPrinterFriendly($journal->getSetting('rtPrinterFriendly')?true:false);
00040 $rt->setAuthorBio($journal->getSetting('rtAuthorBio')?true:false);
00041 $rt->setDefineTerms($journal->getSetting('rtDefineTerms')?true:false);
00042 $rt->setEmailAuthor($journal->getSetting('rtEmailAuthor')?true:false);
00043 $rt->setEmailOthers($journal->getSetting('rtEmailOthers')?true:false);
00044 $rt->setFindingReferences($journal->getSetting('rtFindingReferences')?true:false);
00045 return $rt;
00046 }
00047
00048 function updateJournalRT(&$rt) {
00049 $journalDao =& DAORegistry::getDAO('JournalDAO');
00050 $journal =& $journalDao->getJournal($rt->getJournalId());
00051
00052 $journal->updateSetting('rtEnabled', $rt->getEnabled(), 'bool');
00053 $journal->updateSetting('rtVersionId', $rt->getVersion(), 'int');
00054 $journal->updateSetting('rtAbstract', $rt->getAbstract(), 'bool');
00055 $journal->updateSetting('rtCaptureCite', $rt->getCaptureCite(), 'bool');
00056 $journal->updateSetting('rtViewMetadata', $rt->getViewMetadata(), 'bool');
00057 $journal->updateSetting('rtSupplementaryFiles', $rt->getSupplementaryFiles(), 'bool');
00058 $journal->updateSetting('rtPrinterFriendly', $rt->getPrinterFriendly(), 'bool');
00059 $journal->updateSetting('rtAuthorBio', $rt->getAuthorBio(), 'bool');
00060 $journal->updateSetting('rtDefineTerms', $rt->getDefineTerms(), 'bool');
00061 $journal->updateSetting('rtEmailAuthor', $rt->getEmailAuthor(), 'bool');
00062 $journal->updateSetting('rtEmailOthers', $rt->getEmailOthers(), 'bool');
00063 $journal->updateSetting('rtFindingReferences', $rt->getFindingReferences());
00064 return true;
00065 }
00066
00071 function insertJournalRT(&$rt) {
00072 return $this->updateJournalRT($rt);
00073 }
00074
00075
00076
00077
00078
00085 function &getVersions($journalId, $pagingInfo = null) {
00086 $versions = array();
00087
00088 $result = &$this->retrieveRange(
00089 'SELECT * FROM rt_versions WHERE journal_id = ? ORDER BY version_key',
00090 $journalId,
00091 $pagingInfo
00092 );
00093
00094 $returner = &new DAOResultFactory($result, $this, '_returnVersionFromRow');
00095 return $returner;
00096 }
00097
00104 function &getVersion($versionId, $journalId) {
00105 $result = &$this->retrieve(
00106 'SELECT * FROM rt_versions WHERE version_id = ? AND journal_id = ?',
00107 array($versionId, $journalId)
00108 );
00109
00110 $returner = null;
00111 if ($result->RecordCount() != 0) {
00112 $returner = &$this->_returnVersionFromRow($result->GetRowAssoc(false));
00113 }
00114
00115 $result->Close();
00116 unset($result);
00117
00118 return $returner;
00119 }
00120
00126 function insertVersion($journalId, &$version) {
00127 $this->update(
00128 'INSERT INTO rt_versions
00129 (journal_id, version_key, locale, title, description)
00130 VALUES
00131 (?, ?, ?, ?, ?)',
00132 array((int) $journalId, $version->key, $version->locale, $version->title, $version->description)
00133 );
00134
00135 $version->versionId = $this->getInsertId('rt_versions', 'version_id');
00136
00137 foreach ($version->contexts as $context) {
00138 $context->versionId = $version->versionId;
00139 $this->insertContext($context);
00140 }
00141
00142 return $version->versionId;
00143 }
00144
00150 function updateVersion($journalId, &$version) {
00151
00152 return $this->update(
00153 'UPDATE rt_versions
00154 SET
00155 title = ?,
00156 description = ?,
00157 version_key = ?,
00158 locale = ?
00159 WHERE version_id = ? AND journal_id = ?',
00160 array(
00161 $version->getTitle(),
00162 $version->getDescription(),
00163 $version->getKey(),
00164 $version->getLocale(),
00165 (int) $version->getVersionId(),
00166 (int) $journalId
00167 )
00168 );
00169 }
00170
00175 function deleteVersionsByJournalId($journalId) {
00176 $versions = &$this->getVersions($journalId);
00177 foreach ($versions->toArray() as $version) {
00178 $this->deleteVersion($version->getVersionId(), $journalId);
00179 }
00180 }
00181
00187 function deleteVersion($versionId, $journalId) {
00188 $this->deleteContextsByVersionId($versionId);
00189 return $this->update(
00190 'DELETE FROM rt_versions WHERE version_id = ? AND journal_id = ?',
00191 array((int) $versionId, (int) $journalId)
00192 );
00193 }
00194
00199 function deleteVersionsByJournal($journalId) {
00200 $versions = &RTDAO::getVersions($journalId);
00201 while (!$versions->eof()) {
00202 $version = &$versions->next();
00203 $this->deleteVersion($version->getVersionId(), $journalId);
00204 }
00205 }
00206
00212 function &_returnJournalRTFromRow(&$row) {
00213 $rt = &new JournalRT($row['journal_id']);
00214 $rt->setVersion($row['version_id']);
00215 $rt->setCaptureCite($row['capture_cite']);
00216 $rt->setViewMetadata($row['view_metadata']);
00217 $rt->setSupplementaryFiles($row['supplementary_files']);
00218 $rt->setPrinterFriendly($row['printer_friendly']);
00219 $rt->setAuthorBio($row['author_bio']);
00220 $rt->setDefineTerms($row['define_terms']);
00221 $rt->setEmailAuthor($row['email_author']);
00222 $rt->setEmailOthers($row['email_others']);
00223
00224 HookRegistry::call('RTDAO::_returnJournalRTFromRow', array(&$rt, &$row));
00225
00226 return $rt;
00227 }
00228
00234 function &_returnVersionFromRow(&$row) {
00235 $version = &new RTVersion();
00236 $version->setVersionId($row['version_id']);
00237 $version->setKey($row['version_key']);
00238 $version->setLocale($row['locale']);
00239 $version->setTitle($row['title']);
00240 $version->setDescription($row['description']);
00241
00242 if (!HookRegistry::call('RTDAO::_returnVersionFromRow', array(&$version, &$row))) {
00243 $contextsIterator = &$this->getContexts($row['version_id']);
00244 $version->setContexts($contextsIterator->toArray());
00245 }
00246
00247 return $version;
00248 }
00249
00255 function &_returnSearchFromRow(&$row) {
00256 $search = &new RTSearch();
00257 $search->setSearchId($row['search_id']);
00258 $search->setContextId($row['context_id']);
00259 $search->setTitle($row['title']);
00260 $search->setDescription($row['description']);
00261 $search->setUrl($row['url']);
00262 $search->setSearchUrl($row['search_url']);
00263 $search->setSearchPost($row['search_post']);
00264 $search->setOrder($row['seq']);
00265
00266 HookRegistry::call('RTDAO::_returnSearchFromRow', array(&$search, &$row));
00267
00268 return $search;
00269 }
00270
00271
00272
00273
00274
00275
00276
00282 function &getContext($contextId) {
00283 $result = &$this->retrieve(
00284 'SELECT * FROM rt_contexts WHERE context_id = ?',
00285 array((int) $contextId)
00286 );
00287
00288 $returner = null;
00289 if ($result->RecordCount() != 0) {
00290 $returner = &$this->_returnContextFromRow($result->GetRowAssoc(false));
00291 }
00292
00293 $result->Close();
00294 unset($result);
00295
00296 return $returner;
00297 }
00298
00305 function &getContexts($versionId, $pagingInfo = null) {
00306 $contexts = array();
00307
00308 $result = &$this->retrieveRange(
00309 'SELECT * FROM rt_contexts WHERE version_id = ? ORDER BY seq',
00310 array((int) $versionId),
00311 $pagingInfo
00312 );
00313
00314 $returner = &new DAOResultFactory($result, $this, '_returnContextFromRow');
00315 return $returner;
00316 }
00317
00323 function insertContext(&$context) {
00324 $this->update(
00325 'INSERT INTO rt_contexts
00326 (version_id, title, abbrev, description, cited_by, author_terms, geo_terms, define_terms, seq)
00327 VALUES
00328 (?, ?, ?, ?, ?, ?, ?, ?, ?)',
00329 array(
00330 (int) $context->versionId,
00331 $context->title,
00332 $context->abbrev,
00333 $context->description,
00334 $context->citedBy?1:0,
00335 $context->authorTerms?1:0,
00336 $context->geoTerms?1:0,
00337 $context->defineTerms?1:0,
00338 (int) $context->order
00339 )
00340 );
00341
00342 $context->contextId = $this->getInsertId('rt_contexts', 'context_id');
00343
00344 foreach ($context->searches as $search) {
00345 $search->contextId = $context->contextId;
00346 $this->insertSearch($search);
00347 }
00348
00349 return $context->contextId;
00350 }
00351
00356 function updateContext(&$context) {
00357
00358 return $this->update(
00359 'UPDATE rt_contexts
00360 SET title = ?, abbrev = ?, description = ?, cited_by = ?, author_terms = ?, geo_terms = ?, define_terms = ?, seq = ?
00361 WHERE context_id = ? AND version_id = ?',
00362 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)
00363 );
00364 }
00365
00370 function deleteContextsByVersionId($versionId) {
00371 $contexts = &$this->getContexts($versionId);
00372 foreach ($contexts->toArray() as $context) {
00373 $this->deleteContext(
00374 $context->getContextId(),
00375 $context->getVersionId()
00376 );
00377 }
00378 }
00379
00385 function deleteContext($contextId, $versionId) {
00386 $result = $this->update(
00387 'DELETE FROM rt_contexts WHERE context_id = ? AND version_id = ?',
00388 array((int) $contextId, (int) $versionId)
00389 );
00390 if ($result) $this->deleteSearchesByContextId($contextId);
00391 return $result;
00392 }
00393
00397 function resequenceContexts($versionId) {
00398 $result = &$this->retrieve(
00399 'SELECT context_id FROM rt_contexts WHERE version_id = ? ORDER BY seq',
00400 array((int) $versionId)
00401 );
00402
00403 for ($i=1; !$result->EOF; $i++) {
00404 list($contextId) = $result->fields;
00405 $this->update(
00406 'UPDATE rt_contexts SET seq = ? WHERE context_id = ?',
00407 array(
00408 $i,
00409 $contextId
00410 )
00411 );
00412
00413 $result->moveNext();
00414 }
00415
00416 $result->close();
00417 unset($result);
00418 }
00419
00425 function &_returnContextFromRow(&$row) {
00426 $context = &new RTContext();
00427 $context->setContextId($row['context_id']);
00428 $context->setVersionId($row['version_id']);
00429 $context->setTitle($row['title']);
00430 $context->setAbbrev($row['abbrev']);
00431 $context->setDescription($row['description']);
00432 $context->setCitedBy($row['cited_by']);
00433 $context->setAuthorTerms($row['author_terms']);
00434 $context->setGeoTerms($row['geo_terms']);
00435 $context->setDefineTerms($row['define_terms']);
00436 $context->setOrder($row['seq']);
00437
00438 if (!HookRegistry::call('RTDAO::_returnContextFromRow', array(&$context, &$row))) {
00439 $searchesIterator = &$this->getSearches($row['context_id']);
00440 $context->setSearches($searchesIterator->toArray());
00441 }
00442
00443 return $context;
00444 }
00445
00446
00447
00448
00449
00450
00451
00457 function &getSearch($searchId) {
00458 $result = &$this->retrieve(
00459 'SELECT * FROM rt_searches WHERE search_id = ?',
00460 array((int) $searchId)
00461 );
00462
00463 $returner = null;
00464 if ($result->RecordCount() != 0) {
00465 $returner = &$this->_returnSearchFromRow($result->GetRowAssoc(false));
00466 }
00467
00468 $result->Close();
00469 unset($result);
00470
00471 return $returner;
00472 }
00473
00480 function &getSearches($contextId, $pagingInfo = null) {
00481 $searches = array();
00482
00483 $result = &$this->retrieveRange(
00484 'SELECT * FROM rt_searches WHERE context_id = ? ORDER BY seq',
00485 array((int) $contextId),
00486 $pagingInfo
00487 );
00488
00489 $returner = &new DAOResultFactory($result, $this, '_returnSearchFromRow');
00490 return $returner;
00491 }
00492
00497 function insertSearch(&$search) {
00498 $this->update(
00499 'INSERT INTO rt_searches
00500 (context_id, title, description, url, search_url, search_post, seq)
00501 VALUES
00502 (?, ?, ?, ?, ?, ?, ?)',
00503 array(
00504 (int) $search->getContextId(),
00505 $search->getTitle(),
00506 $search->getDescription(),
00507 $search->getUrl(),
00508 $search->getSearchUrl(),
00509 $search->getSearchPost(),
00510 (int) $search->getOrder()
00511 )
00512 );
00513
00514 $search->searchId = $this->getInsertId('rt_searches', 'search_id');
00515 return $search->searchId;
00516 }
00517
00522 function updateSearch(&$search) {
00523 return $this->update(
00524 'UPDATE rt_searches
00525 SET title = ?, description = ?, url = ?, search_url = ?, search_post = ?, seq = ?
00526 WHERE search_id = ? AND context_id = ?',
00527 array(
00528 $search->getTitle(),
00529 $search->getDescription(),
00530 $search->getUrl(),
00531 $search->getSearchUrl(),
00532 $search->getSearchPost(),
00533 (int) $search->getOrder(),
00534 (int) $search->getSearchId(),
00535 (int) $search->getContextId()
00536 )
00537 );
00538 }
00539
00544 function deleteSearchesByContextId($contextId) {
00545 return $this->update(
00546 'DELETE FROM rt_searches WHERE context_id = ?',
00547 array((int) $contextId)
00548 );
00549 }
00550
00556 function deleteSearch($searchId, $contextId) {
00557 return $this->update(
00558 'DELETE FROM rt_searches WHERE search_id = ? AND context_id = ?',
00559 array((int) $searchId, (int) $contextId)
00560 );
00561 }
00562
00566 function resequenceSearches($contextId) {
00567 $result = &$this->retrieve(
00568 'SELECT search_id FROM rt_searches WHERE context_id = ? ORDER BY seq',
00569 array((int) $contextId)
00570 );
00571
00572 for ($i=1; !$result->EOF; $i++) {
00573 list($searchId) = $result->fields;
00574 $this->update(
00575 'UPDATE rt_searches SET seq = ? WHERE search_id = ?',
00576 array(
00577 $i,
00578 $searchId
00579 )
00580 );
00581
00582 $result->moveNext();
00583 }
00584
00585 $result->close();
00586 unset($result);
00587 }
00588 }
00589
00590 ?>