PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/classes/article/Article.inc.php

https://github.com/jksrecko/ojs
PHP | 600 lines | 277 code | 75 blank | 248 comment | 41 complexity | 85e66e9e779d259ccce8d78904e5e412 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @defgroup article
  4. */
  5. /**
  6. * @file classes/article/Article.inc.php
  7. *
  8. * Copyright (c) 2003-2011 John Willinsky
  9. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  10. *
  11. * @class Article
  12. * @ingroup article
  13. * @see ArticleDAO
  14. *
  15. * @brief Article class.
  16. */
  17. // Submission status constants
  18. define('STATUS_ARCHIVED', 0);
  19. define('STATUS_QUEUED', 1);
  20. // define('STATUS_SCHEDULED', 2); // #2187: Scheduling queue removed.
  21. define('STATUS_PUBLISHED', 3);
  22. define('STATUS_DECLINED', 4);
  23. // AuthorSubmission::getSubmissionStatus will return one of these in place of QUEUED:
  24. define ('STATUS_QUEUED_UNASSIGNED', 5);
  25. define ('STATUS_QUEUED_REVIEW', 6);
  26. define ('STATUS_QUEUED_EDITING', 7);
  27. define ('STATUS_INCOMPLETE', 8);
  28. // Author display in ToC
  29. define ('AUTHOR_TOC_DEFAULT', 0);
  30. define ('AUTHOR_TOC_HIDE', 1);
  31. define ('AUTHOR_TOC_SHOW', 2);
  32. // Article RT comments
  33. define ('COMMENTS_SECTION_DEFAULT', 0);
  34. define ('COMMENTS_DISABLE', 1);
  35. define ('COMMENTS_ENABLE', 2);
  36. import('lib.pkp.classes.submission.Submission');
  37. class Article extends Submission {
  38. /**
  39. * Constructor.
  40. */
  41. function Article() {
  42. // Switch on meta-data adapter support.
  43. $this->setHasLoadableAdapters(true);
  44. parent::Submission();
  45. }
  46. /**
  47. * @see Submission::getAssocType()
  48. */
  49. function getAssocType() {
  50. return ASSOC_TYPE_ARTICLE;
  51. }
  52. /**
  53. * Add an author.
  54. * @param $author Author
  55. */
  56. function addAuthor($author) {
  57. if ($author->getSubmissionId() == null) {
  58. $author->setSubmissionId($this->getId());
  59. }
  60. parent::addAuthor($author);
  61. }
  62. /**
  63. * Get "localized" article title (if applicable). DEPRECATED
  64. * in favour of getLocalizedTitle.
  65. * @return string
  66. */
  67. function getArticleTitle() {
  68. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  69. return $this->getLocalizedTitle();
  70. }
  71. /**
  72. * Get "localized" article abstract (if applicable). DEPRECATED
  73. * in favour of getLocalizedAbstract.
  74. * @return string
  75. */
  76. function getArticleAbstract() {
  77. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  78. return $this->getLocalizedAbstract();
  79. }
  80. //
  81. // Get/set methods
  82. //
  83. /**
  84. * Get ID of article.
  85. * @return int
  86. */
  87. function getArticleId() {
  88. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  89. return $this->getId();
  90. }
  91. /**
  92. * Set ID of article.
  93. * @param $articleId int
  94. */
  95. function setArticleId($articleId) {
  96. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  97. return $this->setId($articleId);
  98. }
  99. /**
  100. * Get ID of journal.
  101. * @return int
  102. */
  103. function getJournalId() {
  104. return $this->getData('journalId');
  105. }
  106. /**
  107. * Set ID of journal.
  108. * @param $journalId int
  109. */
  110. function setJournalId($journalId) {
  111. return $this->setData('journalId', $journalId);
  112. }
  113. /**
  114. * Get ID of article's section.
  115. * @return int
  116. */
  117. function getSectionId() {
  118. return $this->getData('sectionId');
  119. }
  120. /**
  121. * Set ID of article's section.
  122. * @param $sectionId int
  123. */
  124. function setSectionId($sectionId) {
  125. return $this->setData('sectionId', $sectionId);
  126. }
  127. /**
  128. * Get stored DOI of the submission.
  129. * @return int
  130. */
  131. function getStoredDOI() {
  132. return $this->getData('doi');
  133. }
  134. /**
  135. * Set the stored DOI of the submission.
  136. * @param $doi string
  137. */
  138. function setStoredDOI($doi) {
  139. return $this->setData('doi', $doi);
  140. }
  141. /**
  142. * Get title of article's section.
  143. * @return string
  144. */
  145. function getSectionTitle() {
  146. return $this->getData('sectionTitle');
  147. }
  148. /**
  149. * Set title of article's section.
  150. * @param $sectionTitle string
  151. */
  152. function setSectionTitle($sectionTitle) {
  153. return $this->setData('sectionTitle', $sectionTitle);
  154. }
  155. /**
  156. * Get section abbreviation.
  157. * @return string
  158. */
  159. function getSectionAbbrev() {
  160. return $this->getData('sectionAbbrev');
  161. }
  162. /**
  163. * Set section abbreviation.
  164. * @param $sectionAbbrev string
  165. */
  166. function setSectionAbbrev($sectionAbbrev) {
  167. return $this->setData('sectionAbbrev', $sectionAbbrev);
  168. }
  169. /**
  170. * Return the localized discipline. DEPRECATED in favour of
  171. * getLocalizedDiscipline.
  172. * @return string
  173. */
  174. function getArticleDiscipline() {
  175. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  176. return $this->getLocalizedDiscipline();
  177. }
  178. /**
  179. * Return the localized subject classification. DEPRECATED
  180. * in favour of getLocalizedSubjectClass.
  181. * @return string
  182. */
  183. function getArticleSubjectClass() {
  184. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  185. return $this->getLocalizedSubjectClass();
  186. }
  187. /**
  188. * Return the localized subject. DEPRECATED in favour of
  189. * getLocalizedSubject.
  190. * @return string
  191. */
  192. function getArticleSubject() {
  193. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  194. return $this->getLocalizedSubject();
  195. }
  196. /**
  197. * Return the localized geographical coverage. DEPRECATED
  198. * in favour of getLocalizedCoverageGeo.
  199. * @return string
  200. */
  201. function getArticleCoverageGeo() {
  202. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  203. return $this->getLocalizedCoverageGeo();
  204. }
  205. /**
  206. * Return the localized chronological coverage. DEPRECATED
  207. * in favour of getLocalizedCoverageChron.
  208. * @return string
  209. */
  210. function getArticleCoverageChron() {
  211. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  212. return $this->getLocalizedCoverageChron();
  213. }
  214. /**
  215. * Return the localized sample coverage. DEPRECATED in favour
  216. * of getLocalizedCoverageSample.
  217. * @return string
  218. */
  219. function getArticleCoverageSample() {
  220. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  221. return $this->getLocalizedCoverageSample();
  222. }
  223. /**
  224. * Return the localized type (method/approach). DEPRECATED
  225. * in favour of getLocalizedType.
  226. * @return string
  227. */
  228. function getArticleType() {
  229. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  230. return $this->getLocalizedType();
  231. }
  232. /**
  233. * Return the localized sponsor. DEPRECATED in favour
  234. * of getLocalizedSponsor.
  235. * @return string
  236. */
  237. function getArticleSponsor() {
  238. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  239. return $this->getLocalizedSponsor();
  240. }
  241. /**
  242. * Get the localized article cover filename. DEPRECATED
  243. * in favour of getLocalizedFileName.
  244. * @return string
  245. */
  246. function getArticleFileName() {
  247. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  248. return $this->getLocalizedFileName('fileName');
  249. }
  250. /**
  251. * Get the localized article cover width. DEPRECATED
  252. * in favour of getLocalizedWidth.
  253. * @return string
  254. */
  255. function getArticleWidth() {
  256. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  257. return $this->getLocalizedWidth();
  258. }
  259. /**
  260. * Get the localized article cover height. DEPRECATED
  261. * in favour of getLocalizedHeight.
  262. * @return string
  263. */
  264. function getArticleHeight() {
  265. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  266. return $this->getLocalizedHeight();
  267. }
  268. /**
  269. * Get the localized article cover filename on the uploader's computer.
  270. * DEPRECATED in favour of getLocalizedOriginalFileName.
  271. * @return string
  272. */
  273. function getArticleOriginalFileName() {
  274. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  275. return $this->getLocalizedData('originalFileName');
  276. }
  277. /**
  278. * Get the localized article cover alternate text. DEPRECATED
  279. * in favour of getLocalizedCoverPageAltText.
  280. * @return string
  281. */
  282. function getArticleCoverPageAltText() {
  283. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  284. return $this->getLocalizedCoverPageAltText();
  285. }
  286. /**
  287. * Get the flag indicating whether or not to show
  288. * an article cover page. DEPRECATED in favour of
  289. * getLocalizedShowCoverPage.
  290. * @return string
  291. */
  292. function getArticleShowCoverPage() {
  293. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  294. return $this->getLocalizedShowCoverPage();
  295. }
  296. /**
  297. * Get comments to editor.
  298. * @return string
  299. */
  300. function getCommentsToEditor() {
  301. return $this->getData('commentsToEditor');
  302. }
  303. /**
  304. * Set comments to editor.
  305. * @param $commentsToEditor string
  306. */
  307. function setCommentsToEditor($commentsToEditor) {
  308. return $this->setData('commentsToEditor', $commentsToEditor);
  309. }
  310. /**
  311. * Get current review round.
  312. * @return int
  313. */
  314. function getCurrentRound() {
  315. return $this->getData('currentRound');
  316. }
  317. /**
  318. * Set current review round.
  319. * @param $currentRound int
  320. */
  321. function setCurrentRound($currentRound) {
  322. return $this->setData('currentRound', $currentRound);
  323. }
  324. /**
  325. * Get editor file id.
  326. * @return int
  327. */
  328. function getEditorFileId() {
  329. return $this->getData('editorFileId');
  330. }
  331. /**
  332. * Set editor file id.
  333. * @param $editorFileId int
  334. */
  335. function setEditorFileId($editorFileId) {
  336. return $this->setData('editorFileId', $editorFileId);
  337. }
  338. /**
  339. * get expedited
  340. * @return boolean
  341. */
  342. function getFastTracked() {
  343. return $this->getData('fastTracked');
  344. }
  345. /**
  346. * set fastTracked
  347. * @param $fastTracked boolean
  348. */
  349. function setFastTracked($fastTracked) {
  350. return $this->setData('fastTracked',$fastTracked);
  351. }
  352. /**
  353. * Return boolean indicating if author should be hidden in issue ToC.
  354. * @return boolean
  355. */
  356. function getHideAuthor() {
  357. return $this->getData('hideAuthor');
  358. }
  359. /**
  360. * Set if author should be hidden in issue ToC.
  361. * @param $hideAuthor boolean
  362. */
  363. function setHideAuthor($hideAuthor) {
  364. return $this->setData('hideAuthor', $hideAuthor);
  365. }
  366. /**
  367. * Return locale string corresponding to RT comments status.
  368. * @return string
  369. */
  370. function getCommentsStatusString() {
  371. switch ($this->getCommentsStatus()) {
  372. case COMMENTS_DISABLE:
  373. return 'article.comments.disable';
  374. case COMMENTS_ENABLE:
  375. return 'article.comments.enable';
  376. default:
  377. return 'article.comments.sectionDefault';
  378. }
  379. }
  380. /**
  381. * Return boolean indicating if article RT comments should be enabled.
  382. * Checks both the section and article comments status. Article status
  383. * overrides section status.
  384. * @return int
  385. */
  386. function getEnableComments() {
  387. switch ($this->getCommentsStatus()) {
  388. case COMMENTS_DISABLE:
  389. return false;
  390. case COMMENTS_ENABLE:
  391. return true;
  392. case COMMENTS_SECTION_DEFAULT:
  393. $sectionDao =& DAORegistry::getDAO('SectionDAO');
  394. $section =& $sectionDao->getSection($this->getSectionId(), $this->getJournalId(), true);
  395. if ($section->getDisableComments()) {
  396. return false;
  397. } else {
  398. return true;
  399. }
  400. }
  401. }
  402. /**
  403. * Get an associative array matching RT comments status codes with locale strings.
  404. * @return array comments status => localeString
  405. */
  406. function &getCommentsStatusOptions() {
  407. static $commentsStatusOptions = array(
  408. COMMENTS_SECTION_DEFAULT => 'article.comments.sectionDefault',
  409. COMMENTS_DISABLE => 'article.comments.disable',
  410. COMMENTS_ENABLE => 'article.comments.enable'
  411. );
  412. return $commentsStatusOptions;
  413. }
  414. /**
  415. * Get an array of user IDs associated with this article
  416. * @param $authors boolean
  417. * @param $reviewers boolean
  418. * @param $editors boolean
  419. * @param $proofreader boolean
  420. * @param $copyeditor boolean
  421. * @param $layoutEditor boolean
  422. * @return array User IDs
  423. */
  424. function getAssociatedUserIds($authors = true, $reviewers = true, $editors = true, $proofreader = true, $copyeditor = true, $layoutEditor = true) {
  425. $articleId = $this->getId();
  426. $signoffDao =& DAORegistry::getDAO('SignoffDAO');
  427. $userIds = array();
  428. if($authors) {
  429. $userId = $this->getUserId();
  430. if ($userId) $userIds[] = array('id' => $userId, 'role' => 'author');
  431. }
  432. if($editors) {
  433. $editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
  434. $editAssignments =& $editAssignmentDao->getEditorAssignmentsByArticleId($articleId);
  435. while ($editAssignment =& $editAssignments->next()) {
  436. $userId = $editAssignment->getEditorId();
  437. if ($userId) $userIds[] = array('id' => $userId, 'role' => 'editor');
  438. unset($editAssignment);
  439. }
  440. }
  441. if($copyeditor) {
  442. $copyedSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_INITIAL', ASSOC_TYPE_ARTICLE, $articleId);
  443. $userId = $copyedSignoff->getUserId();
  444. if ($userId) $userIds[] = array('id' => $userId, 'role' => 'copyeditor');
  445. }
  446. if($layoutEditor) {
  447. $layoutSignoff = $signoffDao->build('SIGNOFF_LAYOUT', ASSOC_TYPE_ARTICLE, $articleId);
  448. $userId = $layoutSignoff->getUserId();
  449. if ($userId) $userIds[] = array('id' => $userId, 'role' => 'layoutEditor');
  450. }
  451. if($proofreader) {
  452. $proofSignoff = $signoffDao->build('SIGNOFF_PROOFREADING_PROOFREADER', ASSOC_TYPE_ARTICLE, $articleId);
  453. $userId = $proofSignoff->getUserId();
  454. if ($userId) $userIds[] = array('id' => $userId, 'role' => 'proofreader');
  455. }
  456. if($reviewers) {
  457. $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
  458. $reviewAssignments =& $reviewAssignmentDao->getBySubmissionId($articleId);
  459. foreach ($reviewAssignments as $reviewAssignment) {
  460. $userId = $reviewAssignment->getReviewerId();
  461. if ($userId) $userIds[] = array('id' => $userId, 'role' => 'reviewer');
  462. unset($reviewAssignment);
  463. }
  464. }
  465. return $userIds;
  466. }
  467. /**
  468. * Get the signoff for this article
  469. * @param $signoffType string
  470. * @return Signoff
  471. */
  472. function getSignoff($signoffType) {
  473. $signoffDao =& DAORegistry::getDAO('SignoffDAO');
  474. return $signoffDao->build($signoffType, ASSOC_TYPE_ARTICLE, $this->getId());
  475. }
  476. /**
  477. * Get the file for this article at a given signoff stage
  478. * @param $signoffType string
  479. * @param $idOnly boolean Return only file ID
  480. * @return ArticleFile
  481. */
  482. function &getFileBySignoffType($signoffType, $idOnly = false) {
  483. $articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
  484. $signoffDao =& DAORegistry::getDAO('SignoffDAO');
  485. $signoff = $signoffDao->build($signoffType, ASSOC_TYPE_ARTICLE, $this->getId());
  486. if (!$signoff) {
  487. $returner = false;
  488. return $returner;
  489. }
  490. if ($idOnly) {
  491. $returner = $signoff->getFileId();
  492. return $returner;
  493. }
  494. $articleFile =& $articleFileDao->getArticleFile($signoff->getFileId(), $signoff->getFileRevision());
  495. return $articleFile;
  496. }
  497. /**
  498. * Get the user associated with a given signoff and this article
  499. * @param $signoffType string
  500. * @return User
  501. */
  502. function &getUserBySignoffType($signoffType) {
  503. $signoffDao =& DAORegistry::getDAO('SignoffDAO');
  504. $userDao =& DAORegistry::getDAO('UserDAO');
  505. $signoff = $signoffDao->build($signoffType, ASSOC_TYPE_ARTICLE, $this->getId());
  506. if (!$signoff) {
  507. $returner = false;
  508. return $returner;
  509. }
  510. $user =& $userDao->getUser($signoff->getUserId());
  511. return $user;
  512. }
  513. /**
  514. * Get the user id associated with a given signoff and this article
  515. * @param $signoffType string
  516. * @return int
  517. */
  518. function getUserIdBySignoffType($signoffType) {
  519. $signoffDao =& DAORegistry::getDAO('SignoffDAO');
  520. $signoff = $signoffDao->build($signoffType, ASSOC_TYPE_ARTICLE, $this->getId());
  521. if (!$signoff) return false;
  522. return $signoff->getUserId();
  523. }
  524. }
  525. ?>