Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
AuthorHandler.inc.php
1 <?php
2 
16 import('classes.submission.author.AuthorAction');
17 import('classes.handler.Handler');
18 
19 class AuthorHandler extends Handler {
21  var $submission;
22 
26  function AuthorHandler() {
27  parent::Handler();
28 
29  $this->addCheck(new HandlerValidatorJournal($this));
30  }
31 
37  function index($args, $request) {
38  $this->validate($request);
39  $this->setupTemplate($request);
40 
41  $journal =& $request->getJournal();
42 
43  $user =& $request->getUser();
44  $rangeInfo =& $this->getRangeInfo('submissions');
45  $authorSubmissionDao =& DAORegistry::getDAO('AuthorSubmissionDAO');
46 
47  $page = array_shift($args);
48  switch($page) {
49  case 'completed':
50  $active = false;
51  break;
52  default:
53  $page = 'active';
54  $active = true;
55  }
56 
57  $sort = $request->getUserVar('sort');
58  $sort = isset($sort) ? $sort : 'title';
59  $sortDirection = $request->getUserVar('sortDirection');
60  $sortDirection = (isset($sortDirection) && ($sortDirection == SORT_DIRECTION_ASC || $sortDirection == SORT_DIRECTION_DESC)) ? $sortDirection : SORT_DIRECTION_ASC;
61 
62  if ($sort == 'status') {
63  // FIXME Does not pass $rangeInfo else we only get partial results
64  $unsortedSubmissions = $authorSubmissionDao->getAuthorSubmissions($user->getId(), $journal->getId(), $active, null, $sort, $sortDirection);
65 
66  // Sort all submissions by status, which is too complex to do in the DB
67  $submissionsArray = $unsortedSubmissions->toArray();
68  $compare = create_function('$s1, $s2', 'return strcmp($s1->getSubmissionStatus(), $s2->getSubmissionStatus());');
69  usort ($submissionsArray, $compare);
70  if($sortDirection == SORT_DIRECTION_DESC) {
71  $submissionsArray = array_reverse($submissionsArray);
72  }
73  // Convert submission array back to an ItemIterator class
74  import('lib.pkp.classes.core.ArrayItemIterator');
75  $submissions =& ArrayItemIterator::fromRangeInfo($submissionsArray, $rangeInfo);
76  } else {
77  $submissions = $authorSubmissionDao->getAuthorSubmissions($user->getId(), $journal->getId(), $active, $rangeInfo, $sort, $sortDirection);
78  }
79 
80  $templateMgr =& TemplateManager::getManager();
81  $templateMgr->assign('pageToDisplay', $page);
82  if (!$active) {
83  // Make view counts available if enabled.
84  $templateMgr->assign('statViews', $journal->getSetting('statViews'));
85  }
86  $templateMgr->assign_by_ref('submissions', $submissions);
87 
88  // assign payment
89  import('classes.payment.ojs.OJSPaymentManager');
90  $paymentManager = new OJSPaymentManager($request);
91 
92  if ( $paymentManager->isConfigured() ) {
93  $templateMgr->assign('submissionEnabled', $paymentManager->submissionEnabled());
94  $templateMgr->assign('fastTrackEnabled', $paymentManager->fastTrackEnabled());
95  $templateMgr->assign('publicationEnabled', $paymentManager->publicationEnabled());
96 
97  $completedPaymentDAO =& DAORegistry::getDAO('OJSCompletedPaymentDAO');
98  $templateMgr->assign_by_ref('completedPaymentDAO', $completedPaymentDAO);
99  }
100 
101  import('classes.issue.IssueAction');
102  $issueAction = new IssueAction();
103  $templateMgr->register_function('print_issue_id', array($issueAction, 'smartyPrintIssueId'));
104  $templateMgr->assign('helpTopicId', 'editorial.authorsRole.submissions');
105  $templateMgr->assign('sort', $sort);
106  $templateMgr->assign('sortDirection', $sortDirection);
107  $templateMgr->display('author/index.tpl');
108  }
109 
118  function validate(&$request, $articleId = null, $reason = null) {
119  $this->addCheck(new HandlerValidatorRoles($this, true, $reason, null, array(ROLE_ID_AUTHOR)));
120 
121  if ($articleId !== null) {
122  $authorSubmissionDao =& DAORegistry::getDAO('AuthorSubmissionDAO');
123  $roleDao =& DAORegistry::getDAO('RoleDAO');
124  $journal =& $request->getJournal();
125  $user =& $request->getUser();
126 
127  $isValid = true;
128 
129  $authorSubmission =& $authorSubmissionDao->getAuthorSubmission($articleId);
130 
131  if ($authorSubmission == null) {
132  $isValid = false;
133  } else if ($authorSubmission->getJournalId() != $journal->getId()) {
134  $isValid = false;
135  } else {
136  if (!$user || ($authorSubmission->getUserId() != $user->getId())) {
137  $isValid = false;
138  }
139  }
140 
141  if (!$isValid) {
142  $request->redirect(null, $request->getRequestedPage());
143  }
144 
145  $this->submission =& $authorSubmission;
146  }
147 
148  return parent::validate();
149  }
150 
155  function setupTemplate($request, $subclass = false, $articleId = 0, $parentPage = null) {
156  parent::setupTemplate();
157  AppLocale::requireComponents(LOCALE_COMPONENT_OJS_AUTHOR, LOCALE_COMPONENT_PKP_SUBMISSION);
158  $templateMgr =& TemplateManager::getManager();
159 
160  $pageHierarchy = $subclass ? array(array($request->url(null, 'user'), 'navigation.user'), array($request->url(null, 'author'), 'user.role.author'), array($request->url(null, 'author'), 'article.submissions'))
161  : array(array($request->url(null, 'user'), 'navigation.user'), array($request->url(null, 'author'), 'user.role.author'));
162 
163  import('classes.submission.sectionEditor.SectionEditorAction');
164  $submissionCrumb = SectionEditorAction::submissionBreadcrumb($articleId, $parentPage, 'author');
165  if (isset($submissionCrumb)) {
166  $pageHierarchy = array_merge($pageHierarchy, $submissionCrumb);
167  }
168  $templateMgr->assign('pageHierarchy', $pageHierarchy);
169  }
170 
176  function instructions($args, &$request) {
177  import('classes.submission.proofreader.ProofreaderAction');
178  if (!isset($args[0]) || !ProofreaderAction::instructions($args[0], array('copy', 'proof'))) {
179  $request->redirect(null, null, 'index');
180  }
181  }
182 }
183 
184 ?>
submissionBreadcrumb($articleId, $parentPage, $section)
& getRangeInfo($rangeName, $contextData=null)
setupTemplate($request, $subclass=false, $articleId=0, $parentPage=null)
IssueAction class.
validate(&$request, $articleId=null, $reason=null)
Base request handler application class.
Definition: Handler.inc.php:21
addCheck(&$handlerValidator)
Handle requests for journal author functions.
& getDAO($name, $dbconn=null)
& fromRangeInfo(&$theArray, &$theRange)
instructions($type, $allowed=array('copy', 'layout', 'proof', 'referenceLinking'))
Definition: Action.inc.php:202
instructions($args, &$request)
index($args, $request)
Class to validate if a Journal is present.
Provides payment management functions.