Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
RTDAO.inc.php
1 <?php
2 
17 import('classes.rt.ojs.JournalRT');
18 
19 class RTDAO extends DAO {
20  var $versionCache;
21 
22  //
23  // RT
24  //
25 
31  function getJournalRTByJournal($journal) {
32  $rt = new JournalRT($journal->getId());
33  $rt->setEnabled($journal->getSetting('rtEnabled')?true:false);
34  $rt->setVersion((int) $journal->getSetting('rtVersionId'));
35  $rt->setAbstract($journal->getSetting('rtAbstract')?true:false);
36  $rt->setCaptureCite($journal->getSetting('rtCaptureCite')?true:false);
37  $rt->setViewMetadata($journal->getSetting('rtViewMetadata')?true:false);
38  $rt->setSupplementaryFiles($journal->getSetting('rtSupplementaryFiles')?true:false);
39  $rt->setPrinterFriendly($journal->getSetting('rtPrinterFriendly')?true:false);
40  $rt->setDefineTerms($journal->getSetting('rtDefineTerms')?true:false);
41  $rt->setEmailAuthor($journal->getSetting('rtEmailAuthor')?true:false);
42  $rt->setEmailOthers($journal->getSetting('rtEmailOthers')?true:false);
43  $rt->setFindingReferences($journal->getSetting('rtFindingReferences')?true:false);
44  $rt->setViewReviewPolicy($journal->getSetting('rtViewReviewPolicy')?true:false);
45 
46  $rt->setSharingEnabled($journal->getSetting("rtSharingEnabled") ? $journal->getSetting("rtSharingEnabled") : "");
47  $rt->setSharingUserName($journal->getSetting("rtSharingUserName") ? $journal->getSetting("rtSharingUserName") : "");
48  $rt->setSharingButtonStyle($journal->getSetting("rtSharingButtonStyle") ? $journal->getSetting("rtSharingButtonStyle") : "");
49  $rt->setSharingDropDownMenu($journal->getSetting("rtSharingDropDownMenu") ? $journal->getSetting("rtSharingDropDownMenu") : "");
50  $rt->setSharingBrand($journal->getSetting("rtSharingBrand") ? $journal->getSetting("rtSharingBrand") : "");
51  $rt->setSharingDropDown($journal->getSetting("rtSharingDropDown") ? $journal->getSetting("rtSharingDropDown") : "");
52  $rt->setSharingLanguage($journal->getSetting("rtSharingLanguage") ? $journal->getSetting("rtSharingLanguage") : "");
53  $rt->setSharingLogo($journal->getSetting("rtSharingLogo") ? $journal->getSetting("rtSharingLogo") : "");
54  $rt->setSharingLogoBackground($journal->getSetting("rtSharingLogoBackground") ? $journal->getSetting("rtSharingLogoBackground") : "");
55  $rt->setSharingLogoColor($journal->getSetting("rtSharingLogoColor") ? $journal->getSetting("rtSharingLogoColor") : "");
56 
57  return $rt;
58  }
59 
60  function updateJournalRT($rt) {
61  $journalDao = DAORegistry::getDAO('JournalDAO');
62  $journal = $journalDao->getById($rt->getJournalId());
63 
64  $journal->updateSetting('rtEnabled', $rt->getEnabled(), 'bool');
65  $journal->updateSetting('rtVersionId', $rt->getVersion(), 'int');
66  $journal->updateSetting('rtAbstract', $rt->getAbstract(), 'bool');
67  $journal->updateSetting('rtCaptureCite', $rt->getCaptureCite(), 'bool');
68  $journal->updateSetting('rtViewMetadata', $rt->getViewMetadata(), 'bool');
69  $journal->updateSetting('rtSupplementaryFiles', $rt->getSupplementaryFiles(), 'bool');
70  $journal->updateSetting('rtPrinterFriendly', $rt->getPrinterFriendly(), 'bool');
71  $journal->updateSetting('rtDefineTerms', $rt->getDefineTerms(), 'bool');
72  $journal->updateSetting('rtEmailAuthor', $rt->getEmailAuthor(), 'bool');
73  $journal->updateSetting('rtEmailOthers', $rt->getEmailOthers(), 'bool');
74  $journal->updateSetting('rtFindingReferences', $rt->getFindingReferences());
75  $journal->updateSetting('rtViewReviewPolicy', $rt->getViewReviewPolicy());
76 
77  $journal->updateSetting("rtSharingEnabled", $rt->getSharingEnabled());
78  $journal->updateSetting("rtSharingUserName", $rt->getSharingUserName());
79  $journal->updateSetting("rtSharingButtonStyle", $rt->getSharingButtonStyle());
80  $journal->updateSetting("rtSharingDropDownMenu", $rt->getSharingDropDownMenu());
81  $journal->updateSetting("rtSharingBrand", $rt->getSharingBrand());
82  $journal->updateSetting("rtSharingDropDown", $rt->getSharingDropDown());
83  $journal->updateSetting("rtSharingLanguage", $rt->getSharingLanguage());
84  $journal->updateSetting("rtSharingLogo", $rt->getSharingLogo());
85  $journal->updateSetting("rtSharingLogoBackground", $rt->getSharingLogoBackground());
86  $journal->updateSetting("rtSharingLogoColor", $rt->getSharingLogoColor());
87 
88  return true;
89  }
90 
95  function insertJournalRT($rt) {
96  return $this->updateJournalRT($rt);
97  }
98 
99  //
100  // RT Versions
101  //
102 
109  function getVersions($journalId, $pagingInfo = null) {
110  $versions = array();
111 
112  $result = $this->retrieveRange(
113  'SELECT * FROM rt_versions WHERE journal_id = ? ORDER BY version_key',
114  $journalId,
115  $pagingInfo
116  );
117 
118  return new DAOResultFactory($result, $this, '_returnVersionFromRow');
119  }
120 
121  function _versionCacheMiss($cache, $id) {
122  $ids = explode('-', $id);
123  $version = $this->getVersion($ids[0], $ids[1], false);
124  $cache->setCache($id, $version);
125  return $version;
126  }
127 
128  function _getVersionCache() {
129  if (!isset($this->versionCache)) {
130  $cacheManager = CacheManager::getManager();
131  $this->versionCache = $cacheManager->getObjectCache('rtVersions', 0, array($this, '_versionCacheMiss'));
132  }
133  return $this->versionCache;
134  }
135 
142  function getVersion($versionId, $journalId = null, $useCache = null) {
143  if ($useCache) {
144  $cache = $this->_getVersionCache();
145  return $cache->get((int) $versionId . '-' . (int) $journalId);
146  }
147 
148  $result = $this->retrieve(
149  'SELECT * FROM rt_versions WHERE version_id = ? AND journal_id = ?',
150  array((int) $versionId, (int) $journalId)
151  );
152 
153  $returner = null;
154  if ($result->RecordCount() != 0) {
155  $returner = $this->_returnVersionFromRow($result->GetRowAssoc(false));
156  }
157 
158  $result->Close();
159  return $returner;
160  }
161 
167  function insertVersion($journalId, $version) {
168  $this->update(
169  'INSERT INTO rt_versions
170  (journal_id, version_key, locale, title, description)
171  VALUES
172  (?, ?, ?, ?, ?)',
173  array((int) $journalId, $version->key, $version->locale, $version->title, $version->description)
174  );
175 
176  $version->versionId = $this->_getInsertId('rt_versions', 'version_id');
177 
178  foreach ($version->contexts as $context) {
179  $context->versionId = $version->versionId;
180  $this->insertContext($context);
181  }
182 
183  return $version->versionId;
184  }
185 
191  function updateVersion($journalId, $version) {
192  // FIXME Update contexts and searches?
193  return $this->update(
194  'UPDATE rt_versions
195  SET
196  title = ?,
197  description = ?,
198  version_key = ?,
199  locale = ?
200  WHERE version_id = ? AND journal_id = ?',
201  array(
202  $version->getTitle(),
203  $version->getDescription(),
204  $version->getKey(),
205  $version->getLocale(),
206  (int) $version->getVersionId(),
207  (int) $journalId
208  )
209  );
210 
211  $cache = $this->_getVersionCache();
212  $cache->flush();
213  }
214 
219  function deleteVersionsByJournalId($journalId) {
220  $versions = $this->getVersions($journalId);
221  foreach ($versions->toArray() as $version) {
222  $this->deleteVersion($version->getVersionId(), $journalId);
223  }
224  }
225 
231  function deleteVersion($versionId, $journalId) {
232  $this->deleteContextsByVersionId($versionId);
233  return $this->update(
234  'DELETE FROM rt_versions WHERE version_id = ? AND journal_id = ?',
235  array((int) $versionId, (int) $journalId)
236  );
237 
238  $cache = $this->_getVersionCache();
239  $cache->flush();
240  }
241 
246  function deleteVersionsByJournal($journalId) {
247  $versions = RTDAO::getVersions($journalId);
248  while ($version = $versions->next()) {
249  $this->deleteVersion($version->getVersionId(), $journalId);
250  }
251  }
252 
258  function _returnVersionFromRow($row) {
259  $version = new RTVersion();
260  $version->setVersionId($row['version_id']);
261  $version->setKey($row['version_key']);
262  $version->setLocale($row['locale']);
263  $version->setTitle($row['title']);
264  $version->setDescription($row['description']);
265 
266  if (!HookRegistry::call('RTDAO::_returnVersionFromRow', array($version, $row))) {
267  $contextsIterator = $this->getContexts($row['version_id']);
268  $version->setContexts($contextsIterator->toArray());
269  }
270 
271  return $version;
272  }
273 
279  function _returnSearchFromRow($row) {
280  $search = new RTSearch();
281  $search->setSearchId($row['search_id']);
282  $search->setContextId($row['context_id']);
283  $search->setTitle($row['title']);
284  $search->setDescription($row['description']);
285  $search->setUrl($row['url']);
286  $search->setSearchUrl($row['search_url']);
287  $search->setSearchPost($row['search_post']);
288  $search->setOrder($row['seq']);
289 
290  HookRegistry::call('RTDAO::_returnSearchFromRow', array($search, $row));
291 
292  return $search;
293  }
294 
295 
296 
297  //
298  // RT Contexts
299  //
300 
306  function getContext($contextId) {
307  $result = $this->retrieve(
308  'SELECT * FROM rt_contexts WHERE context_id = ?',
309  array((int) $contextId)
310  );
311 
312  $returner = null;
313  if ($result->RecordCount() != 0) {
314  $returner = $this->_returnContextFromRow($result->GetRowAssoc(false));
315  }
316 
317  $result->Close();
318  return $returner;
319  }
320 
327  function getContexts($versionId, $pagingInfo = null) {
328  $contexts = array();
329 
330  $result = $this->retrieveRange(
331  'SELECT * FROM rt_contexts WHERE version_id = ? ORDER BY seq',
332  array((int) $versionId),
333  $pagingInfo
334  );
335 
336  return new DAOResultFactory($result, $this, '_returnContextFromRow');
337  }
338 
344  function insertContext($context) {
345  $this->update(
346  'INSERT INTO rt_contexts
347  (version_id, title, abbrev, description, cited_by, author_terms, geo_terms, define_terms, seq)
348  VALUES
349  (?, ?, ?, ?, ?, ?, ?, ?, ?)',
350  array(
351  (int) $context->versionId,
352  $context->title,
353  $context->abbrev,
354  $context->description,
355  $context->citedBy?1:0,
356  $context->authorTerms?1:0,
357  $context->geoTerms?1:0,
358  $context->defineTerms?1:0,
359  (int) $context->order
360  )
361  );
362 
363  $context->contextId = $this->_getInsertId('rt_contexts', 'context_id');
364 
365  foreach ($context->searches as $search) {
366  $search->contextId = $context->contextId;
367  $this->insertSearch($search);
368  }
369 
370  return $context->contextId;
371  }
372 
377  function updateContext($context) {
378  // FIXME Update searches?
379  return $this->update(
380  'UPDATE rt_contexts
381  SET title = ?, abbrev = ?, description = ?, cited_by = ?, author_terms = ?, geo_terms = ?, define_terms = ?, seq = ?
382  WHERE context_id = ? AND version_id = ?',
383  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)
384  );
385  }
386 
391  function deleteContextsByVersionId($versionId) {
392  $contexts = $this->getContexts($versionId);
393  foreach ($contexts->toArray() as $context) {
394  $this->deleteContext(
395  $context->getContextId(),
396  $context->getVersionId()
397  );
398  }
399  }
400 
406  function deleteContext($contextId, $versionId) {
407  $result = $this->update(
408  'DELETE FROM rt_contexts WHERE context_id = ? AND version_id = ?',
409  array((int) $contextId, (int) $versionId)
410  );
411  if ($result) $this->deleteSearchesByContextId($contextId);
412  return $result;
413  }
414 
418  function resequenceContexts($versionId) {
419  $result = $this->retrieve(
420  'SELECT context_id FROM rt_contexts WHERE version_id = ? ORDER BY seq',
421  array((int) $versionId)
422  );
423 
424  for ($i=1; !$result->EOF; $i++) {
425  list($contextId) = $result->fields;
426  $this->update(
427  'UPDATE rt_contexts SET seq = ? WHERE context_id = ?',
428  array(
429  $i,
430  $contextId
431  )
432  );
433 
434  $result->MoveNext();
435  }
436  $result->Close();
437  }
438 
444  function _returnContextFromRow($row) {
445  $context = new RTContext();
446  $context->setContextId($row['context_id']);
447  $context->setVersionId($row['version_id']);
448  $context->setTitle($row['title']);
449  $context->setAbbrev($row['abbrev']);
450  $context->setDescription($row['description']);
451  $context->setCitedBy($row['cited_by']);
452  $context->setAuthorTerms($row['author_terms']);
453  $context->setGeoTerms($row['geo_terms']);
454  $context->setDefineTerms($row['define_terms']);
455  $context->setOrder($row['seq']);
456 
457  if (!HookRegistry::call('RTDAO::_returnContextFromRow', array(&$context, &$row))) {
458  $searchesIterator = $this->getSearches($row['context_id']);
459  $context->setSearches($searchesIterator->toArray());
460  }
461 
462  return $context;
463  }
464 
465 
466 
467  //
468  // RT Searches
469  //
470 
476  function getSearch($searchId) {
477  $result = $this->retrieve(
478  'SELECT * FROM rt_searches WHERE search_id = ?',
479  array((int) $searchId)
480  );
481 
482  $returner = null;
483  if ($result->RecordCount() != 0) {
484  $returner = $this->_returnSearchFromRow($result->GetRowAssoc(false));
485  }
486 
487  $result->Close();
488  return $returner;
489  }
490 
497  function getSearches($contextId, $pagingInfo = null) {
498  $searches = array();
499 
500  $result = $this->retrieveRange(
501  'SELECT * FROM rt_searches WHERE context_id = ? ORDER BY seq',
502  array((int) $contextId),
503  $pagingInfo
504  );
505 
506  return new DAOResultFactory($result, $this, '_returnSearchFromRow');
507  }
508 
513  function insertSearch($search) {
514  $this->update(
515  'INSERT INTO rt_searches
516  (context_id, title, description, url, search_url, search_post, seq)
517  VALUES
518  (?, ?, ?, ?, ?, ?, ?)',
519  array(
520  (int) $search->getContextId(),
521  $search->getTitle(),
522  $search->getDescription(),
523  $search->getUrl(),
524  $search->getSearchUrl(),
525  $search->getSearchPost(),
526  (int) $search->getOrder()
527  )
528  );
529 
530  $search->searchId = $this->_getInsertId('rt_searches', 'search_id');
531  return $search->searchId;
532  }
533 
538  function updateSearch($search) {
539  return $this->update(
540  'UPDATE rt_searches
541  SET title = ?, description = ?, url = ?, search_url = ?, search_post = ?, seq = ?
542  WHERE search_id = ? AND context_id = ?',
543  array(
544  $search->getTitle(),
545  $search->getDescription(),
546  $search->getUrl(),
547  $search->getSearchUrl(),
548  $search->getSearchPost(),
549  (int) $search->getOrder(),
550  (int) $search->getSearchId(),
551  (int) $search->getContextId()
552  )
553  );
554  }
555 
560  function deleteSearchesByContextId($contextId) {
561  return $this->update(
562  'DELETE FROM rt_searches WHERE context_id = ?',
563  array((int) $contextId)
564  );
565  }
566 
572  function deleteSearch($searchId, $contextId) {
573  return $this->update(
574  'DELETE FROM rt_searches WHERE search_id = ? AND context_id = ?',
575  array((int) $searchId, (int) $contextId)
576  );
577  }
578 
582  function resequenceSearches($contextId) {
583  $result = $this->retrieve(
584  'SELECT search_id FROM rt_searches WHERE context_id = ? ORDER BY seq',
585  array((int) $contextId)
586  );
587 
588  for ($i=1; !$result->EOF; $i++) {
589  list($searchId) = $result->fields;
590  $this->update(
591  'UPDATE rt_searches SET seq = ? WHERE search_id = ?',
592  array(
593  $i,
594  $searchId
595  )
596  );
597 
598  $result->MoveNext();
599  }
600  $result->Close();
601  }
602 }
603 
604 ?>
static & getDAO($name, $dbconn=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
setEnabled($enabled)
Definition: RT.inc.php:109
updateVersion($journalId, $version)
Definition: RTDAO.inc.php:191
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
deleteVersionsByJournal($journalId)
Definition: RTDAO.inc.php:246
getContexts($versionId, $pagingInfo=null)
Definition: RTDAO.inc.php:327
_returnVersionFromRow($row)
Definition: RTDAO.inc.php:258
insertJournalRT($rt)
Definition: RTDAO.inc.php:95
insertSearch($search)
Definition: RTDAO.inc.php:513
getContext($contextId)
Definition: RTDAO.inc.php:306
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
getSearch($searchId)
Definition: RTDAO.inc.php:476
static call($hookName, $args=null)
_returnSearchFromRow($row)
Definition: RTDAO.inc.php:279
resequenceSearches($contextId)
Definition: RTDAO.inc.php:582
deleteVersion($versionId, $journalId)
Definition: RTDAO.inc.php:231
getVersions($journalId, $pagingInfo=null)
Definition: RTDAO.inc.php:109
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
DAO operations for the OJS Reading Tools interface.
Definition: RTDAO.inc.php:19
_returnContextFromRow($row)
Definition: RTDAO.inc.php:444
resequenceContexts($versionId)
Definition: RTDAO.inc.php:418
updateSearch($search)
Definition: RTDAO.inc.php:538
getVersion($versionId, $journalId=null, $useCache=null)
Definition: RTDAO.inc.php:142
Data structures associated with the Reading Tools component.
deleteSearchesByContextId($contextId)
Definition: RTDAO.inc.php:560
deleteContextsByVersionId($versionId)
Definition: RTDAO.inc.php:391
deleteVersionsByJournalId($journalId)
Definition: RTDAO.inc.php:219
getSearches($contextId, $pagingInfo=null)
Definition: RTDAO.inc.php:497
insertVersion($journalId, $version)
Definition: RTDAO.inc.php:167
deleteContext($contextId, $versionId)
Definition: RTDAO.inc.php:406
OJS-specific Reading Tools end-user interface.
updateContext($context)
Definition: RTDAO.inc.php:377
insertContext($context)
Definition: RTDAO.inc.php:344
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
getJournalRTByJournal($journal)
Definition: RTDAO.inc.php:31
deleteSearch($searchId, $contextId)
Definition: RTDAO.inc.php:572