PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/ojs/ojs-2.0.2-1/classes/rt/ojs/RTDAO.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite
PHP | 605 lines | 383 code | 70 blank | 152 comment | 12 complexity | 9042c9a8b967575658e976dabcbb5326 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * RTDAO.inc.php
  4. *
  5. * Copyright (c) 2003-2005 The Public Knowledge Project
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @package rt.ojs
  9. *
  10. * DAO operations for the OJS Reading Tools interface.
  11. *
  12. * $Id: RTDAO.inc.php,v 1.20 2005/07/16 03:52:02 alec Exp $
  13. */
  14. import('rt.ojs.JournalRT');
  15. class RTDAO extends DAO {
  16. //
  17. // RT
  18. //
  19. /**
  20. * Retrieve an RT configuration.
  21. * @param $versionId int
  22. * @return RT
  23. */
  24. function &getJournalRTByJournalId($journalId) {
  25. $result = &$this->retrieve(
  26. 'SELECT * FROM rt_settings WHERE journal_id = ?',
  27. $journalId
  28. );
  29. $returner = null;
  30. if ($result->RecordCount() != 0) {
  31. $returner = &$this->_returnJournalRTFromRow($result->GetRowAssoc(false));
  32. }
  33. $result->Close();
  34. return $returner;
  35. }
  36. function updateJournalRT($rt) {
  37. return $this->update(
  38. 'UPDATE rt_settings
  39. SET
  40. version_id = ?,
  41. capture_cite = ?,
  42. view_metadata = ?,
  43. supplementary_files = ?,
  44. printer_friendly = ?,
  45. author_bio = ?,
  46. define_terms = ?,
  47. add_comment = ?,
  48. email_author = ?,
  49. email_others = ?,
  50. bib_format = ?
  51. WHERE journal_id = ?',
  52. array(
  53. $rt->getVersion(),
  54. $rt->getCaptureCite(),
  55. $rt->getViewMetadata(),
  56. $rt->getSupplementaryFiles(),
  57. $rt->getPrinterFriendly(),
  58. $rt->getAuthorBio(),
  59. $rt->getDefineTerms(),
  60. $rt->getAddComment(),
  61. $rt->getEmailAuthor(),
  62. $rt->getEmailOthers(),
  63. $rt->getBibFormat(),
  64. $rt->getJournalId()
  65. )
  66. );
  67. }
  68. function deleteJournalRT($journalId) {
  69. return $this->update(
  70. 'DELETE FROM rt_settings WHERE journal_id = ?',
  71. $journalId
  72. );
  73. }
  74. /**
  75. * Insert a new RT configuration.
  76. * @param $rt object
  77. */
  78. function insertJournalRT(&$rt) {
  79. return $this->update(
  80. 'INSERT INTO rt_settings (
  81. journal_id,
  82. version_id,
  83. capture_cite,
  84. view_metadata,
  85. supplementary_files,
  86. printer_friendly,
  87. author_bio,
  88. define_terms,
  89. add_comment,
  90. email_author,
  91. email_others,
  92. bib_format
  93. ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
  94. array(
  95. $rt->getJournalId(),
  96. $rt->getVersion(),
  97. $rt->getCaptureCite(),
  98. $rt->getViewMetadata(),
  99. $rt->getSupplementaryFiles(),
  100. $rt->getPrinterFriendly(),
  101. $rt->getAuthorBio(),
  102. $rt->getDefineTerms(),
  103. $rt->getAddComment(),
  104. $rt->getEmailAuthor(),
  105. $rt->getEmailOthers(),
  106. $rt->getBibFormat()
  107. )
  108. );
  109. }
  110. //
  111. // RT Versions
  112. //
  113. /**
  114. * Retrieve all RT versions for a journal.
  115. * @param $journalId int
  116. * @param $pagingInfo object DBResultRange (optional)
  117. * @return array RTVersion
  118. */
  119. function &getVersions($journalId, $pagingInfo = null) {
  120. $versions = array();
  121. $result = &$this->retrieveRange(
  122. 'SELECT * FROM rt_versions WHERE journal_id = ? ORDER BY version_key',
  123. $journalId,
  124. $pagingInfo
  125. );
  126. $returner = &new DAOResultFactory($result, $this, '_returnVersionFromRow');
  127. return $returner;
  128. }
  129. /**
  130. * Retrieve a version.
  131. * @param $versionId int
  132. * @param $journalId int
  133. * @return RTVersion
  134. */
  135. function &getVersion($versionId, $journalId) {
  136. $result = &$this->retrieve(
  137. 'SELECT * FROM rt_versions WHERE version_id = ? AND journal_id = ?',
  138. array($versionId, $journalId)
  139. );
  140. $returner = null;
  141. if ($result->RecordCount() != 0) {
  142. $returner = &$this->_returnVersionFromRow($result->GetRowAssoc(false));
  143. }
  144. $result->Close();
  145. return $returner;
  146. }
  147. /**
  148. * Insert a new version.
  149. * @param $journalId int
  150. * @param $version RTVersion
  151. */
  152. function insertVersion($journalId, &$version) {
  153. $this->update(
  154. 'INSERT INTO rt_versions
  155. (journal_id, version_key, locale, title, description)
  156. VALUES
  157. (?, ?, ?, ?, ?)',
  158. array($journalId, $version->key, $version->locale, $version->title, $version->description)
  159. );
  160. $version->versionId = $this->getInsertId('rt_versions', 'version_id');
  161. foreach ($version->contexts as $context) {
  162. $context->versionId = $version->versionId;
  163. $this->insertContext($context);
  164. }
  165. return $version->versionId;
  166. }
  167. /**
  168. * Update an exisiting verison.
  169. * @param $version RTVersion
  170. */
  171. function updateVersion($journalId, &$version) {
  172. // FIXME Update contexts and searches?
  173. return $this->update(
  174. 'UPDATE rt_versions
  175. SET
  176. title = ?,
  177. description = ?,
  178. version_key = ?,
  179. locale = ?
  180. WHERE version_id = ? AND journal_id = ?',
  181. array(
  182. $version->getTitle(),
  183. $version->getDescription(),
  184. $version->getKey(),
  185. $version->getLocale(),
  186. $version->getVersionId(),
  187. $journalId
  188. )
  189. );
  190. }
  191. /**
  192. * Delete all versions by journal ID.
  193. * @param $journalId int
  194. */
  195. function deleteVersionsByJournalId($journalId) {
  196. $versions = &$this->getVersions($journalId);
  197. foreach ($versions->toArray() as $version) {
  198. $this->deleteVersion($version->getVersionId(), $journalId);
  199. }
  200. }
  201. /**
  202. * Delete a version.
  203. * @param $versionId int
  204. * @param $journalId int
  205. */
  206. function deleteVersion($versionId, $journalId) {
  207. $this->deleteContextsByVersionId($versionId);
  208. return $this->update(
  209. 'DELETE FROM rt_versions WHERE version_id = ? AND journal_id = ?',
  210. array($versionId, $journalId)
  211. );
  212. }
  213. /**
  214. * Delete RT versions (and dependent entities) by journal ID.
  215. * @param $journalId int
  216. */
  217. function deleteVersionsByJournal($journalId) {
  218. $versions = &RTDAO::getVersions($journalId);
  219. while (!$versions->eof()) {
  220. $version = &$versions->next();
  221. $this->deleteVersion($version->getVersionId(), $journalId);
  222. }
  223. }
  224. /**
  225. * Return RT object from database row.
  226. * @param $row array
  227. * @return RTVersion
  228. */
  229. function &_returnJournalRTFromRow(&$row) {
  230. $rt = &new JournalRT($row['journal_id']);
  231. $rt->setVersion($row['version_id']);
  232. $rt->setCaptureCite($row['capture_cite']);
  233. $rt->setViewMetadata($row['view_metadata']);
  234. $rt->setSupplementaryFiles($row['supplementary_files']);
  235. $rt->setPrinterFriendly($row['printer_friendly']);
  236. $rt->setAuthorBio($row['author_bio']);
  237. $rt->setDefineTerms($row['define_terms']);
  238. $rt->setAddComment($row['add_comment']);
  239. $rt->setEmailAuthor($row['email_author']);
  240. $rt->setEmailOthers($row['email_others']);
  241. $rt->setBibFormat($row['bib_format']);
  242. return $rt;
  243. }
  244. /**
  245. * Return RTVersion object from database row.
  246. * @param $row array
  247. * @return RTVersion
  248. */
  249. function &_returnVersionFromRow(&$row) {
  250. $version = &new RTVersion();
  251. $version->setVersionId($row['version_id']);
  252. $version->setKey($row['version_key']);
  253. $version->setLocale($row['locale']);
  254. $version->setTitle($row['title']);
  255. $version->setDescription($row['description']);
  256. $contextsIterator = &$this->getContexts($row['version_id']);
  257. $version->setContexts($contextsIterator->toArray());
  258. return $version;
  259. }
  260. /**
  261. * Return RTSearch object from database row.
  262. * @param $row array
  263. * @return RTSearch
  264. */
  265. function &_returnSearchFromRow(&$row) {
  266. $search = &new RTSearch();
  267. $search->setSearchId($row['search_id']);
  268. $search->setContextId($row['context_id']);
  269. $search->setTitle($row['title']);
  270. $search->setDescription($row['description']);
  271. $search->setUrl($row['url']);
  272. $search->setSearchUrl($row['search_url']);
  273. $search->setSearchPost($row['search_post']);
  274. $search->setOrder($row['seq']);
  275. return $search;
  276. }
  277. //
  278. // RT Contexts
  279. //
  280. /**
  281. * Retrieve an RT context.
  282. * @param $contextId int
  283. * @return RT
  284. */
  285. function &getContext($contextId) {
  286. $result = &$this->retrieve(
  287. 'SELECT * FROM rt_contexts WHERE context_id = ?',
  288. array($contextId)
  289. );
  290. $returner = null;
  291. if ($result->RecordCount() != 0) {
  292. $returner = &$this->_returnContextFromRow($result->GetRowAssoc(false));
  293. }
  294. $result->Close();
  295. return $returner;
  296. }
  297. /**
  298. * Retrieve all RT contexts for a version (in order).
  299. * @param $versionId int
  300. * @param $pagingInfo object DBResultRange (optional)
  301. * @return array RTContext
  302. */
  303. function &getContexts($versionId, $pagingInfo = null) {
  304. $contexts = array();
  305. $result = &$this->retrieveRange(
  306. 'SELECT * FROM rt_contexts WHERE version_id = ? ORDER BY seq',
  307. $versionId,
  308. $pagingInfo
  309. );
  310. $returner = &new DAOResultFactory($result, $this, '_returnContextFromRow');
  311. return $returner;
  312. }
  313. /**
  314. * Insert a context.
  315. * @param $versionId int
  316. * @param $context RTContext
  317. */
  318. function insertContext(&$context) {
  319. $this->update(
  320. 'INSERT INTO rt_contexts
  321. (version_id, title, abbrev, description, author_terms, define_terms, seq)
  322. VALUES
  323. (?, ?, ?, ?, ?, ?, ?)',
  324. array($context->versionId, $context->title, $context->abbrev, $context->description, $context->authorTerms, $context->defineTerms, $context->order)
  325. );
  326. $context->contextId = $this->getInsertId('rt_contexts', 'context_id');
  327. foreach ($context->searches as $search) {
  328. $search->contextId = $context->contextId;
  329. $this->insertSearch($search);
  330. }
  331. return $context->contextId;
  332. }
  333. /**
  334. * Update an existing context.
  335. * @param $context RTContext
  336. */
  337. function updateContext(&$context) {
  338. // FIXME Update searches?
  339. return $this->update(
  340. 'UPDATE rt_contexts
  341. SET title = ?, abbrev = ?, description = ?, author_terms = ?, define_terms = ?, seq = ?
  342. WHERE context_id = ? AND version_id = ?',
  343. array($context->title, $context->abbrev, $context->description, $context->authorTerms, $context->defineTerms, $context->order, $context->contextId, $context->versionId)
  344. );
  345. }
  346. /**
  347. * Delete all contexts by version ID.
  348. * @param $versionId int
  349. */
  350. function deleteContextsByVersionId($versionId) {
  351. $contexts = &$this->getContexts($versionId);
  352. foreach ($contexts->toArray() as $context) {
  353. $this->deleteContext(
  354. $context->getContextId(),
  355. $context->getVersionId()
  356. );
  357. }
  358. }
  359. /**
  360. * Delete a context.
  361. * @param $contextId int
  362. * @param $versionId int
  363. */
  364. function deleteContext($contextId, $versionId) {
  365. $result = $this->update(
  366. 'DELETE FROM rt_contexts WHERE context_id = ? AND version_id = ?',
  367. array($contextId, $versionId)
  368. );
  369. if ($result) $this->deleteSearchesByContextId($contextId);
  370. return $result;
  371. }
  372. /**
  373. * Sequentially renumber contexts in their sequence order.
  374. */
  375. function resequenceContexts($versionId) {
  376. $result = &$this->retrieve(
  377. 'SELECT context_id FROM rt_contexts WHERE version_id = ? ORDER BY seq',
  378. $versionId
  379. );
  380. for ($i=1; !$result->EOF; $i++) {
  381. list($contextId) = $result->fields;
  382. $this->update(
  383. 'UPDATE rt_contexts SET seq = ? WHERE context_id = ?',
  384. array(
  385. $i,
  386. $contextId
  387. )
  388. );
  389. $result->moveNext();
  390. }
  391. $result->close();
  392. }
  393. /**
  394. * Return RTContext object from database row.
  395. * @param $row array
  396. * @return RTContext
  397. */
  398. function &_returnContextFromRow(&$row) {
  399. $context = &new RTContext();
  400. $context->setContextId($row['context_id']);
  401. $context->setVersionId($row['version_id']);
  402. $context->setTitle($row['title']);
  403. $context->setAbbrev($row['abbrev']);
  404. $context->setDescription($row['description']);
  405. $context->setAuthorTerms($row['author_terms']);
  406. $context->setDefineTerms($row['define_terms']);
  407. $context->setOrder($row['seq']);
  408. $searchesIterator = &$this->getSearches($row['context_id']);
  409. $context->setSearches($searchesIterator->toArray());
  410. return $context;
  411. }
  412. //
  413. // RT Searches
  414. //
  415. /**
  416. * Retrieve an RT search.
  417. * @param $searchId int
  418. * @return RTSearch
  419. */
  420. function &getSearch($searchId) {
  421. $result = &$this->retrieve(
  422. 'SELECT * FROM rt_searches WHERE search_id = ?',
  423. $searchId
  424. );
  425. $returner = null;
  426. if ($result->RecordCount() != 0) {
  427. $returner = &$this->_returnSearchFromRow($result->GetRowAssoc(false));
  428. }
  429. $result->Close();
  430. return $returner;
  431. }
  432. /**
  433. * Retrieve all RT searches for a context (in order).
  434. * @param $contextId int
  435. * @param $pagingInfo object DBResultRange (optional)
  436. * @return array RTSearch
  437. */
  438. function &getSearches($contextId, $pagingInfo = null) {
  439. $searches = array();
  440. $result = &$this->retrieveRange(
  441. 'SELECT * FROM rt_searches WHERE context_id = ? ORDER BY seq',
  442. $contextId,
  443. $pagingInfo
  444. );
  445. $returner = &new DAOResultFactory($result, $this, '_returnSearchFromRow');
  446. return $returner;
  447. }
  448. /**
  449. * Insert new search.
  450. * @param $search RTSearch
  451. */
  452. function insertSearch(&$search) {
  453. $this->update(
  454. 'INSERT INTO rt_searches
  455. (context_id, title, description, url, search_url, search_post, seq)
  456. VALUES
  457. (?, ?, ?, ?, ?, ?, ?)',
  458. array(
  459. $search->getContextId(),
  460. $search->getTitle(),
  461. $search->getDescription(),
  462. $search->getUrl(),
  463. $search->getSearchUrl(),
  464. $search->getSearchPost(),
  465. $search->getOrder()
  466. )
  467. );
  468. $search->searchId = $this->getInsertId('rt_searches', 'search_id');
  469. return $search->searchId;
  470. }
  471. /**
  472. * Update an existing search.
  473. * @param $search RTSearch
  474. */
  475. function updateSearch(&$search) {
  476. return $this->update(
  477. 'UPDATE rt_searches
  478. SET title = ?, description = ?, url = ?, search_url = ?, search_post = ?, seq = ?
  479. WHERE search_id = ? AND context_id = ?',
  480. array(
  481. $search->getTitle(),
  482. $search->getDescription(),
  483. $search->getUrl(),
  484. $search->getSearchUrl(),
  485. $search->getSearchPost(),
  486. $search->getOrder(),
  487. $search->getSearchId(),
  488. $search->getContextId()
  489. )
  490. );
  491. }
  492. /**
  493. * Delete all searches by context ID.
  494. * @param $contextId int
  495. */
  496. function deleteSearchesByContextId($contextId) {
  497. return $this->update(
  498. 'DELETE FROM rt_searches WHERE context_id = ?',
  499. $contextId
  500. );
  501. }
  502. /**
  503. * Delete a search.
  504. * @param $searchId int
  505. * @param $contextId int
  506. */
  507. function deleteSearch($searchId, $contextId) {
  508. return $this->update(
  509. 'DELETE FROM rt_searches WHERE search_id = ? AND context_id = ?',
  510. array($searchId, $contextId)
  511. );
  512. }
  513. /**
  514. * Sequentially renumber searches in their sequence order.
  515. */
  516. function resequenceSearches($contextId) {
  517. $result = &$this->retrieve(
  518. 'SELECT search_id FROM rt_searches WHERE context_id = ? ORDER BY seq',
  519. $contextId
  520. );
  521. for ($i=1; !$result->EOF; $i++) {
  522. list($searchId) = $result->fields;
  523. $this->update(
  524. 'UPDATE rt_searches SET seq = ? WHERE search_id = ?',
  525. array(
  526. $i,
  527. $searchId
  528. )
  529. );
  530. $result->moveNext();
  531. }
  532. $result->close();
  533. }
  534. }
  535. ?>