Open Journal Systems  2.4.3
 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  $returner = new DAOResultFactory($result, $this, '_returnVersionFromRow');
119  return $returner;
120  }
121 
122  function _versionCacheMiss(&$cache, $id) {
123  $ids = explode('-', $id);
124  $version =& $this->getVersion($ids[0], $ids[1], false);
125  $cache->setCache($id, $version);
126  return $version;
127  }
128 
129  function &_getVersionCache() {
130  if (!isset($this->versionCache)) {
131  $cacheManager =& CacheManager::getManager();
132  $this->versionCache =& $cacheManager->getObjectCache('rtVersions', 0, array(&$this, '_versionCacheMiss'));
133  }
134  return $this->versionCache;
135  }
136 
143  function &getVersion($versionId, $journalId = null, $useCache = null) {
144  if ($useCache) {
145  $cache =& $this->_getVersionCache();
146  $returner = $cache->get((int) $versionId . '-' . (int) $journalId);
147  return $returner;
148  }
149 
150  $result =& $this->retrieve(
151  'SELECT * FROM rt_versions WHERE version_id = ? AND journal_id = ?',
152  array((int) $versionId, (int) $journalId)
153  );
154 
155  $returner = null;
156  if ($result->RecordCount() != 0) {
157  $returner =& $this->_returnVersionFromRow($result->GetRowAssoc(false));
158  }
159 
160  $result->Close();
161  unset($result);
162 
163  return $returner;
164  }
165 
171  function insertVersion($journalId, &$version) {
172  $this->update(
173  'INSERT INTO rt_versions
174  (journal_id, version_key, locale, title, description)
175  VALUES
176  (?, ?, ?, ?, ?)',
177  array((int) $journalId, $version->key, $version->locale, $version->title, $version->description)
178  );
179 
180  $version->versionId = $this->getInsertId('rt_versions', 'version_id');
181 
182  foreach ($version->contexts as $context) {
183  $context->versionId = $version->versionId;
184  $this->insertContext($context);
185  }
186 
187  return $version->versionId;
188  }
189 
195  function updateVersion($journalId, &$version) {
196  // FIXME Update contexts and searches?
197  return $this->update(
198  'UPDATE rt_versions
199  SET
200  title = ?,
201  description = ?,
202  version_key = ?,
203  locale = ?
204  WHERE version_id = ? AND journal_id = ?',
205  array(
206  $version->getTitle(),
207  $version->getDescription(),
208  $version->getKey(),
209  $version->getLocale(),
210  (int) $version->getVersionId(),
211  (int) $journalId
212  )
213  );
214 
215  $cache =& $this->_getVersionCache();
216  $cache->flush();
217  }
218 
223  function deleteVersionsByJournalId($journalId) {
224  $versions =& $this->getVersions($journalId);
225  foreach ($versions->toArray() as $version) {
226  $this->deleteVersion($version->getVersionId(), $journalId);
227  }
228  }
229 
235  function deleteVersion($versionId, $journalId) {
236  $this->deleteContextsByVersionId($versionId);
237  return $this->update(
238  'DELETE FROM rt_versions WHERE version_id = ? AND journal_id = ?',
239  array((int) $versionId, (int) $journalId)
240  );
241 
242  $cache =& $this->_getVersionCache();
243  $cache->flush();
244  }
245 
250  function deleteVersionsByJournal($journalId) {
251  $versions =& RTDAO::getVersions($journalId);
252  while (!$versions->eof()) {
253  $version =& $versions->next();
254  $this->deleteVersion($version->getVersionId(), $journalId);
255  }
256  }
257 
263  function &_returnVersionFromRow(&$row) {
264  $version = new RTVersion();
265  $version->setVersionId($row['version_id']);
266  $version->setKey($row['version_key']);
267  $version->setLocale($row['locale']);
268  $version->setTitle($row['title']);
269  $version->setDescription($row['description']);
270 
271  if (!HookRegistry::call('RTDAO::_returnVersionFromRow', array(&$version, &$row))) {
272  $contextsIterator =& $this->getContexts($row['version_id']);
273  $version->setContexts($contextsIterator->toArray());
274  }
275 
276  return $version;
277  }
278 
284  function &_returnSearchFromRow(&$row) {
285  $search = new RTSearch();
286  $search->setSearchId($row['search_id']);
287  $search->setContextId($row['context_id']);
288  $search->setTitle($row['title']);
289  $search->setDescription($row['description']);
290  $search->setUrl($row['url']);
291  $search->setSearchUrl($row['search_url']);
292  $search->setSearchPost($row['search_post']);
293  $search->setOrder($row['seq']);
294 
295  HookRegistry::call('RTDAO::_returnSearchFromRow', array(&$search, &$row));
296 
297  return $search;
298  }
299 
300 
301 
302  //
303  // RT Contexts
304  //
305 
311  function &getContext($contextId) {
312  $result =& $this->retrieve(
313  'SELECT * FROM rt_contexts WHERE context_id = ?',
314  array((int) $contextId)
315  );
316 
317  $returner = null;
318  if ($result->RecordCount() != 0) {
319  $returner =& $this->_returnContextFromRow($result->GetRowAssoc(false));
320  }
321 
322  $result->Close();
323  unset($result);
324 
325  return $returner;
326  }
327 
334  function &getContexts($versionId, $pagingInfo = null) {
335  $contexts = array();
336 
337  $result =& $this->retrieveRange(
338  'SELECT * FROM rt_contexts WHERE version_id = ? ORDER BY seq',
339  array((int) $versionId),
340  $pagingInfo
341  );
342 
343  $returner = new DAOResultFactory($result, $this, '_returnContextFromRow');
344  return $returner;
345  }
346 
352  function insertContext(&$context) {
353  $this->update(
354  'INSERT INTO rt_contexts
355  (version_id, title, abbrev, description, cited_by, author_terms, geo_terms, define_terms, seq)
356  VALUES
357  (?, ?, ?, ?, ?, ?, ?, ?, ?)',
358  array(
359  (int) $context->versionId,
360  $context->title,
361  $context->abbrev,
362  $context->description,
363  $context->citedBy?1:0,
364  $context->authorTerms?1:0,
365  $context->geoTerms?1:0,
366  $context->defineTerms?1:0,
367  (int) $context->order
368  )
369  );
370 
371  $context->contextId = $this->getInsertId('rt_contexts', 'context_id');
372 
373  foreach ($context->searches as $search) {
374  $search->contextId = $context->contextId;
375  $this->insertSearch($search);
376  }
377 
378  return $context->contextId;
379  }
380 
385  function updateContext(&$context) {
386  // FIXME Update searches?
387  return $this->update(
388  'UPDATE rt_contexts
389  SET title = ?, abbrev = ?, description = ?, cited_by = ?, author_terms = ?, geo_terms = ?, define_terms = ?, seq = ?
390  WHERE context_id = ? AND version_id = ?',
391  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)
392  );
393  }
394 
399  function deleteContextsByVersionId($versionId) {
400  $contexts =& $this->getContexts($versionId);
401  foreach ($contexts->toArray() as $context) {
402  $this->deleteContext(
403  $context->getContextId(),
404  $context->getVersionId()
405  );
406  }
407  }
408 
414  function deleteContext($contextId, $versionId) {
415  $result = $this->update(
416  'DELETE FROM rt_contexts WHERE context_id = ? AND version_id = ?',
417  array((int) $contextId, (int) $versionId)
418  );
419  if ($result) $this->deleteSearchesByContextId($contextId);
420  return $result;
421  }
422 
426  function resequenceContexts($versionId) {
427  $result =& $this->retrieve(
428  'SELECT context_id FROM rt_contexts WHERE version_id = ? ORDER BY seq',
429  array((int) $versionId)
430  );
431 
432  for ($i=1; !$result->EOF; $i++) {
433  list($contextId) = $result->fields;
434  $this->update(
435  'UPDATE rt_contexts SET seq = ? WHERE context_id = ?',
436  array(
437  $i,
438  $contextId
439  )
440  );
441 
442  $result->moveNext();
443  }
444 
445  $result->close();
446  unset($result);
447  }
448 
454  function &_returnContextFromRow(&$row) {
455  $context = new RTContext();
456  $context->setContextId($row['context_id']);
457  $context->setVersionId($row['version_id']);
458  $context->setTitle($row['title']);
459  $context->setAbbrev($row['abbrev']);
460  $context->setDescription($row['description']);
461  $context->setCitedBy($row['cited_by']);
462  $context->setAuthorTerms($row['author_terms']);
463  $context->setGeoTerms($row['geo_terms']);
464  $context->setDefineTerms($row['define_terms']);
465  $context->setOrder($row['seq']);
466 
467  if (!HookRegistry::call('RTDAO::_returnContextFromRow', array(&$context, &$row))) {
468  $searchesIterator =& $this->getSearches($row['context_id']);
469  $context->setSearches($searchesIterator->toArray());
470  }
471 
472  return $context;
473  }
474 
475 
476 
477  //
478  // RT Searches
479  //
480 
486  function &getSearch($searchId) {
487  $result =& $this->retrieve(
488  'SELECT * FROM rt_searches WHERE search_id = ?',
489  array((int) $searchId)
490  );
491 
492  $returner = null;
493  if ($result->RecordCount() != 0) {
494  $returner =& $this->_returnSearchFromRow($result->GetRowAssoc(false));
495  }
496 
497  $result->Close();
498  unset($result);
499 
500  return $returner;
501  }
502 
509  function &getSearches($contextId, $pagingInfo = null) {
510  $searches = array();
511 
512  $result =& $this->retrieveRange(
513  'SELECT * FROM rt_searches WHERE context_id = ? ORDER BY seq',
514  array((int) $contextId),
515  $pagingInfo
516  );
517 
518  $returner = new DAOResultFactory($result, $this, '_returnSearchFromRow');
519  return $returner;
520  }
521 
526  function insertSearch(&$search) {
527  $this->update(
528  'INSERT INTO rt_searches
529  (context_id, title, description, url, search_url, search_post, seq)
530  VALUES
531  (?, ?, ?, ?, ?, ?, ?)',
532  array(
533  (int) $search->getContextId(),
534  $search->getTitle(),
535  $search->getDescription(),
536  $search->getUrl(),
537  $search->getSearchUrl(),
538  $search->getSearchPost(),
539  (int) $search->getOrder()
540  )
541  );
542 
543  $search->searchId = $this->getInsertId('rt_searches', 'search_id');
544  return $search->searchId;
545  }
546 
551  function updateSearch(&$search) {
552  return $this->update(
553  'UPDATE rt_searches
554  SET title = ?, description = ?, url = ?, search_url = ?, search_post = ?, seq = ?
555  WHERE search_id = ? AND context_id = ?',
556  array(
557  $search->getTitle(),
558  $search->getDescription(),
559  $search->getUrl(),
560  $search->getSearchUrl(),
561  $search->getSearchPost(),
562  (int) $search->getOrder(),
563  (int) $search->getSearchId(),
564  (int) $search->getContextId()
565  )
566  );
567  }
568 
573  function deleteSearchesByContextId($contextId) {
574  return $this->update(
575  'DELETE FROM rt_searches WHERE context_id = ?',
576  array((int) $contextId)
577  );
578  }
579 
585  function deleteSearch($searchId, $contextId) {
586  return $this->update(
587  'DELETE FROM rt_searches WHERE search_id = ? AND context_id = ?',
588  array((int) $searchId, (int) $contextId)
589  );
590  }
591 
595  function resequenceSearches($contextId) {
596  $result =& $this->retrieve(
597  'SELECT search_id FROM rt_searches WHERE context_id = ? ORDER BY seq',
598  array((int) $contextId)
599  );
600 
601  for ($i=1; !$result->EOF; $i++) {
602  list($searchId) = $result->fields;
603  $this->update(
604  'UPDATE rt_searches SET seq = ? WHERE search_id = ?',
605  array(
606  $i,
607  $searchId
608  )
609  );
610 
611  $result->moveNext();
612  }
613 
614  $result->close();
615  unset($result);
616  }
617 }
618 
619 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
updateVersion($journalId, &$version)
Definition: RTDAO.inc.php:195
setEnabled($enabled)
Definition: RT.inc.php:69
& getSearch($searchId)
Definition: RTDAO.inc.php:486
& getSearches($contextId, $pagingInfo=null)
Definition: RTDAO.inc.php:509
& _returnVersionFromRow(&$row)
Definition: RTDAO.inc.php:263
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
deleteVersionsByJournal($journalId)
Definition: RTDAO.inc.php:250
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
updateContext(&$context)
Definition: RTDAO.inc.php:385
& getContexts($versionId, $pagingInfo=null)
Definition: RTDAO.inc.php:334
resequenceSearches($contextId)
Definition: RTDAO.inc.php:595
deleteVersion($versionId, $journalId)
Definition: RTDAO.inc.php:235
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
insertVersion($journalId, &$version)
Definition: RTDAO.inc.php:171
resequenceContexts($versionId)
Definition: RTDAO.inc.php:426
& getVersions($journalId, $pagingInfo=null)
Definition: RTDAO.inc.php:109
updateSearch(&$search)
Definition: RTDAO.inc.php:551
& _returnContextFromRow(&$row)
Definition: RTDAO.inc.php:454
Data structures associated with the Reading Tools component.
deleteSearchesByContextId($contextId)
Definition: RTDAO.inc.php:573
deleteContextsByVersionId($versionId)
Definition: RTDAO.inc.php:399
& getDAO($name, $dbconn=null)
deleteVersionsByJournalId($journalId)
Definition: RTDAO.inc.php:223
insertContext(&$context)
Definition: RTDAO.inc.php:352
insertSearch(&$search)
Definition: RTDAO.inc.php:526
& _returnSearchFromRow(&$row)
Definition: RTDAO.inc.php:284
call($hookName, $args=null)
deleteContext($contextId, $versionId)
Definition: RTDAO.inc.php:414
OJS-specific Reading Tools end-user interface.
& getVersion($versionId, $journalId=null, $useCache=null)
Definition: RTDAO.inc.php:143
& getJournalRTByJournal(&$journal)
Definition: RTDAO.inc.php:31
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
& getContext($contextId)
Definition: RTDAO.inc.php:311
insertJournalRT(&$rt)
Definition: RTDAO.inc.php:95
deleteSearch($searchId, $contextId)
Definition: RTDAO.inc.php:585