Open Journal Systems  3.3.0
QueryNoteForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
18 class QueryNoteForm extends Form {
20  var $_actionArgs;
21 
23  var $_query;
24 
26  var $_noteId;
27 
29  var $_isNew;
30 
38  function __construct($actionArgs, $query, $user, $noteId = null) {
39  parent::__construct('controllers/grid/queries/form/queryNoteForm.tpl');
40  $this->_actionArgs = $actionArgs;
41  $this->setQuery($query);
42 
43  if ($noteId === null) {
44  // Create a new (placeholder) note.
45  $noteDao = DAORegistry::getDAO('NoteDAO'); /* @var $noteDao NoteDAO */
46  $note = $noteDao->newDataObject();
47  $note->setAssocType(ASSOC_TYPE_QUERY);
48  $note->setAssocId($query->getId());
49  $note->setUserId($user->getId());
50  $note->setDateCreated(Core::getCurrentDate());
51  $this->_noteId = $noteDao->insertObject($note);
52  $this->_isNew = true;
53  } else {
54  $this->_noteId = $noteId;
55  $this->_isNew = false;
56  }
57 
58  // Validation checks for this form
59  $this->addCheck(new FormValidator($this, 'comment', 'required', 'submission.queries.messageRequired'));
60  $this->addCheck(new FormValidatorPost($this));
61  $this->addCheck(new FormValidatorCSRF($this));
62  }
63 
64  //
65  // Getters and Setters
66  //
71  function getQuery() {
72  return $this->_query;
73  }
74 
79  function setQuery($query) {
80  $this->_query = $query;
81  }
82 
87  function readInputData() {
88  $this->readUserVars(array(
89  'comment',
90  ));
91  }
92 
96  function fetch($request, $template = null, $display = false) {
97  $templateMgr = TemplateManager::getManager($request);
98  $templateMgr->assign(array(
99  'actionArgs' => $this->_actionArgs,
100  'noteId' => $this->_noteId,
101  'csrfToken' => $request->getSession()->getCSRFToken(),
102  ));
103  return parent::fetch($request, $template, $display);
104  }
105 
110  function execute(...$functionArgs) {
111  $request = Application::get()->getRequest();
112  $user = $request->getUser();
113 
114  // Create a new note.
115  $noteDao = DAORegistry::getDAO('NoteDAO'); /* @var $noteDao NoteDAO */
116  $note = $noteDao->getById($this->_noteId);
117  $note->setUserId($request->getUser()->getId());
118  $note->setContents($this->getData('comment'));
119  $noteDao->updateObject($note);
120 
121  // Check whether the query needs re-opening
122  $query = $this->getQuery();
123  if ($query->getIsClosed()) {
124  $headNote = $query->getHeadNote();
125  if ($user->getId() != $headNote->getUserId()) {
126  // Re-open the query.
127  $query->setIsClosed(false);
128  $queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
129  $queryDao->updateObject($query);
130  }
131  }
132 
133  $notificationDao = DAORegistry::getDAO('NotificationDAO'); /* @var $notificationDao NotificationDAO */
134  $queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
135 
136  // Always include current user to query participants
137  if (!in_array($user->getId(), $queryDao->getParticipantIds($query->getId()))) {
138  $queryDao->insertParticipant($query->getId(), $user->getId());
139  }
140 
141  $notificationManager = new NotificationManager();
142  foreach ($queryDao->getParticipantIds($query->getId()) as $userId) {
143  // Delete any prior notifications of the same type (e.g. prior "new" comments)
144  $notificationDao->deleteByAssoc(
145  ASSOC_TYPE_QUERY, $query->getId(),
146  $userId, NOTIFICATION_TYPE_QUERY_ACTIVITY,
147  $request->getContext()->getId()
148  );
149 
150  // No need to additionally notify the posting user.
151  if ($userId == $user->getId()) continue;
152 
153  // Notify the user of a new query.
154  $notificationManager->createNotification(
155  $request,
156  $userId,
157  NOTIFICATION_TYPE_QUERY_ACTIVITY,
158  $request->getContext()->getId(),
159  ASSOC_TYPE_QUERY,
160  $query->getId(),
161  NOTIFICATION_LEVEL_TASK
162  );
163  }
164 
165  parent::execute(...$functionArgs);
166 
167  return $note;
168  }
169 }
170 
171 
QueryNoteForm\execute
execute(... $functionArgs)
Definition: QueryNoteForm.inc.php:122
QueryNoteForm\$_query
$_query
Definition: QueryNoteForm.inc.php:29
QueryNoteForm\setQuery
setQuery($query)
Definition: QueryNoteForm.inc.php:91
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
Form\readUserVars
readUserVars($vars)
Definition: Form.inc.php:378
QueryNoteForm\getQuery
getQuery()
Definition: QueryNoteForm.inc.php:83
Form\getData
getData($key)
Definition: Form.inc.php:220
FormValidatorPost
Form validation check to make sure the form is POSTed.
Definition: FormValidatorPost.inc.php:18
QueryNoteForm\fetch
fetch($request, $template=null, $display=false)
Definition: QueryNoteForm.inc.php:108
QueryNoteForm\$_noteId
$_noteId
Definition: QueryNoteForm.inc.php:35
QueryNoteForm\$_actionArgs
$_actionArgs
Definition: QueryNoteForm.inc.php:23
QueryNoteForm\readInputData
readInputData()
Definition: QueryNoteForm.inc.php:99
QueryNoteForm\$_isNew
$_isNew
Definition: QueryNoteForm.inc.php:41
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
FormValidator
Class to represent a form validation check.
Definition: FormValidator.inc.php:23
QueryNoteForm
Form for adding/editing a new query note.
Definition: QueryNoteForm.inc.php:18
Core\getCurrentDate
static getCurrentDate($ts=null)
Definition: Core.inc.php:63
QueryNoteForm\__construct
__construct($actionArgs, $query, $user, $noteId=null)
Definition: QueryNoteForm.inc.php:50
Form\addCheck
addCheck($formValidator)
Definition: Form.inc.php:395
NotificationManager
Definition: NotificationManager.inc.php:19
FormValidatorCSRF
Form validation check to make sure the CSRF token is correct.
Definition: FormValidatorCSRF.inc.php:18
Form
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235