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  $result = $this->retrieveRange(
111  'SELECT * FROM rt_versions WHERE journal_id = ? ORDER BY version_key',
112  $journalId,
113  $pagingInfo
114  );
115 
116  return new DAOResultFactory($result, $this, '_returnVersionFromRow');
117  }
118 
119  function _versionCacheMiss($cache, $id) {
120  $ids = explode('-', $id);
121  $version = $this->getVersion($ids[0], $ids[1], false);
122  $cache->setCache($id, $version);
123  return $version;
124  }
125 
126  function _getVersionCache() {
127  if (!isset($this->versionCache)) {
128  $cacheManager = CacheManager::getManager();
129  $this->versionCache = $cacheManager->getObjectCache('rtVersions', 0, array($this, '_versionCacheMiss'));
130  }
131  return $this->versionCache;
132  }
133 
140  function getVersion($versionId, $journalId = null, $useCache = null) {
141  if ($useCache) {
142  $cache = $this->_getVersionCache();
143  return $cache->get((int) $versionId . '-' . (int) $journalId);
144  }
145 
146  $result = $this->retrieve(
147  'SELECT * FROM rt_versions WHERE version_id = ? AND journal_id = ?',
148  array((int) $versionId, (int) $journalId)
149  );
150 
151  $returner = null;
152  if ($result->RecordCount() != 0) {
153  $returner = $this->_returnVersionFromRow($result->GetRowAssoc(false));
154  }
155 
156  $result->Close();
157  return $returner;
158  }
159 
165  function insertVersion($journalId, $version) {
166  $this->update(
167  'INSERT INTO rt_versions
168  (journal_id, version_key, locale, title, description)
169  VALUES
170  (?, ?, ?, ?, ?)',
171  array((int) $journalId, $version->key, $version->locale, $version->title, $version->description)
172  );
173 
174  $version->versionId = $this->_getInsertId('rt_versions', 'version_id');
175 
176  foreach ($version->contexts as $context) {
177  $context->versionId = $version->versionId;
178  $this->insertContext($context);
179  }
180 
181  return $version->versionId;
182  }
183 
189  function updateVersion($journalId, $version) {
190  // FIXME Update contexts and searches?
191  return $this->update(
192  'UPDATE rt_versions
193  SET
194  title = ?,
195  description = ?,
196  version_key = ?,
197  locale = ?
198  WHERE version_id = ? AND journal_id = ?',
199  array(
200  $version->getTitle(),
201  $version->getDescription(),
202  $version->getKey(),
203  $version->getLocale(),
204  (int) $version->getVersionId(),
205  (int) $journalId
206  )
207  );
208 
209  $cache = $this->_getVersionCache();
210  $cache->flush();
211  }
212 
217  function deleteVersionsByJournalId($journalId) {
218  $versions = $this->getVersions($journalId);
219  foreach ($versions->toArray() as $version) {
220  $this->deleteVersion($version->getVersionId(), $journalId);
221  }
222  }
223 
229  function deleteVersion($versionId, $journalId) {
230  $this->deleteContextsByVersionId($versionId);
231  return $this->update(
232  'DELETE FROM rt_versions WHERE version_id = ? AND journal_id = ?',
233  array((int) $versionId, (int) $journalId)
234  );
235 
236  $cache = $this->_getVersionCache();
237  $cache->flush();
238  }
239 
244  function deleteVersionsByJournal($journalId) {
245  $versions = RTDAO::getVersions($journalId);
246  while ($version = $versions->next()) {
247  $this->deleteVersion($version->getVersionId(), $journalId);
248  }
249  }
250 
256  function _returnVersionFromRow($row) {
257  $version = new RTVersion();
258  $version->setVersionId($row['version_id']);
259  $version->setKey($row['version_key']);
260  $version->setLocale($row['locale']);
261  $version->setTitle($row['title']);
262  $version->setDescription($row['description']);
263 
264  if (!HookRegistry::call('RTDAO::_returnVersionFromRow', array($version, $row))) {
265  $contextsIterator = $this->getContexts($row['version_id']);
266  $version->setContexts($contextsIterator->toArray());
267  }
268 
269  return $version;
270  }
271 
277  function _returnSearchFromRow($row) {
278  $search = new RTSearch();
279  $search->setSearchId($row['search_id']);
280  $search->setContextId($row['context_id']);
281  $search->setTitle($row['title']);
282  $search->setDescription($row['description']);
283  $search->setUrl($row['url']);
284  $search->setSearchUrl($row['search_url']);
285  $search->setSearchPost($row['search_post']);
286  $search->setOrder($row['seq']);
287 
288  HookRegistry::call('RTDAO::_returnSearchFromRow', array($search, $row));
289 
290  return $search;
291  }
292 
293 
294 
295  //
296  // RT Contexts
297  //
298 
304  function getContext($contextId) {
305  $result = $this->retrieve(
306  'SELECT * FROM rt_contexts WHERE context_id = ?',
307  array((int) $contextId)
308  );
309 
310  $returner = null;
311  if ($result->RecordCount() != 0) {
312  $returner = $this->_returnContextFromRow($result->GetRowAssoc(false));
313  }
314 
315  $result->Close();
316  return $returner;
317  }
318 
325  function getContexts($versionId, $pagingInfo = null) {
326  $result = $this->retrieveRange(
327  'SELECT * FROM rt_contexts WHERE version_id = ? ORDER BY seq',
328  array((int) $versionId),
329  $pagingInfo
330  );
331 
332  return new DAOResultFactory($result, $this, '_returnContextFromRow');
333  }
334 
340  function insertContext($context) {
341  $this->update(
342  'INSERT INTO rt_contexts
343  (version_id, title, abbrev, description, cited_by, author_terms, geo_terms, define_terms, seq)
344  VALUES
345  (?, ?, ?, ?, ?, ?, ?, ?, ?)',
346  array(
347  (int) $context->versionId,
348  $context->title,
349  $context->abbrev,
350  $context->description,
351  $context->citedBy?1:0,
352  $context->authorTerms?1:0,
353  $context->geoTerms?1:0,
354  $context->defineTerms?1:0,
355  (int) $context->order
356  )
357  );
358 
359  $context->contextId = $this->_getInsertId('rt_contexts', 'context_id');
360 
361  foreach ($context->searches as $search) {
362  $search->contextId = $context->contextId;
363  $this->insertSearch($search);
364  }
365 
366  return $context->contextId;
367  }
368 
373  function updateContext($context) {
374  // FIXME Update searches?
375  return $this->update(
376  'UPDATE rt_contexts
377  SET title = ?, abbrev = ?, description = ?, cited_by = ?, author_terms = ?, geo_terms = ?, define_terms = ?, seq = ?
378  WHERE context_id = ? AND version_id = ?',
379  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)
380  );
381  }
382 
387  function deleteContextsByVersionId($versionId) {
388  $contexts = $this->getContexts($versionId);
389  foreach ($contexts->toArray() as $context) {
390  $this->deleteContext(
391  $context->getContextId(),
392  $context->getVersionId()
393  );
394  }
395  }
396 
402  function deleteContext($contextId, $versionId) {
403  $result = $this->update(
404  'DELETE FROM rt_contexts WHERE context_id = ? AND version_id = ?',
405  array((int) $contextId, (int) $versionId)
406  );
407  if ($result) $this->deleteSearchesByContextId($contextId);
408  return $result;
409  }
410 
414  function resequenceContexts($versionId) {
415  $result = $this->retrieve(
416  'SELECT context_id FROM rt_contexts WHERE version_id = ? ORDER BY seq',
417  array((int) $versionId)
418  );
419 
420  for ($i=1; !$result->EOF; $i++) {
421  list($contextId) = $result->fields;
422  $this->update(
423  'UPDATE rt_contexts SET seq = ? WHERE context_id = ?',
424  array(
425  $i,
426  $contextId
427  )
428  );
429 
430  $result->MoveNext();
431  }
432  $result->Close();
433  }
434 
440  function _returnContextFromRow($row) {
441  $context = new RTContext();
442  $context->setContextId($row['context_id']);
443  $context->setVersionId($row['version_id']);
444  $context->setTitle($row['title']);
445  $context->setAbbrev($row['abbrev']);
446  $context->setDescription($row['description']);
447  $context->setCitedBy($row['cited_by']);
448  $context->setAuthorTerms($row['author_terms']);
449  $context->setGeoTerms($row['geo_terms']);
450  $context->setDefineTerms($row['define_terms']);
451  $context->setOrder($row['seq']);
452 
453  if (!HookRegistry::call('RTDAO::_returnContextFromRow', array(&$context, &$row))) {
454  $searchesIterator = $this->getSearches($row['context_id']);
455  $context->setSearches($searchesIterator->toArray());
456  }
457 
458  return $context;
459  }
460 
461 
462 
463  //
464  // RT Searches
465  //
466 
472  function getSearch($searchId) {
473  $result = $this->retrieve(
474  'SELECT * FROM rt_searches WHERE search_id = ?',
475  array((int) $searchId)
476  );
477 
478  $returner = null;
479  if ($result->RecordCount() != 0) {
480  $returner = $this->_returnSearchFromRow($result->GetRowAssoc(false));
481  }
482 
483  $result->Close();
484  return $returner;
485  }
486 
493  function getSearches($contextId, $pagingInfo = null) {
494  $result = $this->retrieveRange(
495  'SELECT * FROM rt_searches WHERE context_id = ? ORDER BY seq',
496  array((int) $contextId),
497  $pagingInfo
498  );
499 
500  return new DAOResultFactory($result, $this, '_returnSearchFromRow');
501  }
502 
507  function insertSearch($search) {
508  $this->update(
509  'INSERT INTO rt_searches
510  (context_id, title, description, url, search_url, search_post, seq)
511  VALUES
512  (?, ?, ?, ?, ?, ?, ?)',
513  array(
514  (int) $search->getContextId(),
515  $search->getTitle(),
516  $search->getDescription(),
517  $search->getUrl(),
518  $search->getSearchUrl(),
519  $search->getSearchPost(),
520  (int) $search->getOrder()
521  )
522  );
523 
524  $search->searchId = $this->_getInsertId('rt_searches', 'search_id');
525  return $search->searchId;
526  }
527 
532  function updateSearch($search) {
533  return $this->update(
534  'UPDATE rt_searches
535  SET title = ?, description = ?, url = ?, search_url = ?, search_post = ?, seq = ?
536  WHERE search_id = ? AND context_id = ?',
537  array(
538  $search->getTitle(),
539  $search->getDescription(),
540  $search->getUrl(),
541  $search->getSearchUrl(),
542  $search->getSearchPost(),
543  (int) $search->getOrder(),
544  (int) $search->getSearchId(),
545  (int) $search->getContextId()
546  )
547  );
548  }
549 
554  function deleteSearchesByContextId($contextId) {
555  return $this->update(
556  'DELETE FROM rt_searches WHERE context_id = ?',
557  array((int) $contextId)
558  );
559  }
560 
566  function deleteSearch($searchId, $contextId) {
567  return $this->update(
568  'DELETE FROM rt_searches WHERE search_id = ? AND context_id = ?',
569  array((int) $searchId, (int) $contextId)
570  );
571  }
572 
576  function resequenceSearches($contextId) {
577  $result = $this->retrieve(
578  'SELECT search_id FROM rt_searches WHERE context_id = ? ORDER BY seq',
579  array((int) $contextId)
580  );
581 
582  for ($i=1; !$result->EOF; $i++) {
583  list($searchId) = $result->fields;
584  $this->update(
585  'UPDATE rt_searches SET seq = ? WHERE search_id = ?',
586  array(
587  $i,
588  $searchId
589  )
590  );
591 
592  $result->MoveNext();
593  }
594  $result->Close();
595  }
596 }
597 
598 ?>
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:189
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
deleteVersionsByJournal($journalId)
Definition: RTDAO.inc.php:244
getContexts($versionId, $pagingInfo=null)
Definition: RTDAO.inc.php:325
_returnVersionFromRow($row)
Definition: RTDAO.inc.php:256
insertJournalRT($rt)
Definition: RTDAO.inc.php:95
insertSearch($search)
Definition: RTDAO.inc.php:507
getContext($contextId)
Definition: RTDAO.inc.php:304
& 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:472
static call($hookName, $args=null)
_returnSearchFromRow($row)
Definition: RTDAO.inc.php:277
resequenceSearches($contextId)
Definition: RTDAO.inc.php:576
deleteVersion($versionId, $journalId)
Definition: RTDAO.inc.php:229
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:440
resequenceContexts($versionId)
Definition: RTDAO.inc.php:414
updateSearch($search)
Definition: RTDAO.inc.php:532
getVersion($versionId, $journalId=null, $useCache=null)
Definition: RTDAO.inc.php:140
Data structures associated with the Reading Tools component.
deleteSearchesByContextId($contextId)
Definition: RTDAO.inc.php:554
deleteContextsByVersionId($versionId)
Definition: RTDAO.inc.php:387
deleteVersionsByJournalId($journalId)
Definition: RTDAO.inc.php:217
getSearches($contextId, $pagingInfo=null)
Definition: RTDAO.inc.php:493
insertVersion($journalId, $version)
Definition: RTDAO.inc.php:165
deleteContext($contextId, $versionId)
Definition: RTDAO.inc.php:402
OJS-specific Reading Tools end-user interface.
updateContext($context)
Definition: RTDAO.inc.php:373
insertContext($context)
Definition: RTDAO.inc.php:340
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:566