Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
PreparedEmailsGridHandler.inc.php
1 <?php
2 
16 // Import grid base classes
17 import('lib.pkp.classes.controllers.grid.settings.preparedEmails.PKPPreparedEmailsGridHandler');
18 
19 class PreparedEmailsGridHandler extends PKPPreparedEmailsGridHandler {
24  parent::PKPPreparedEmailsGridHandler();
25  }
26 
31  function getRowInstance() {
32  return new PreparedEmailsGridRow();
33  }
34 
35 
36  //
37  // Public handler methods
38  //
46  function editPreparedEmail($args, $request) {
47  $journal = $request->getJournal();
48  $emailKey = $request->getUserVar('emailKey');
49 
50  import('lib.pkp.controllers.grid.settings.preparedEmails.form.PreparedEmailForm');
51  $preparedEmailForm = new PreparedEmailForm($emailKey, $journal);
52  $preparedEmailForm->initData($request);
53 
54  $json = new JSONMessage(true, $preparedEmailForm->fetch($request));
55  return $json->getString();
56  }
57 
64  function updatePreparedEmail($args, $request) {
65  $journal = $request->getJournal();
66  $emailKey = $request->getUserVar('emailKey');
67 
68  import('lib.pkp.controllers.grid.settings.preparedEmails.form.PreparedEmailForm');
69  $preparedEmailForm = new PreparedEmailForm($emailKey, $journal);
70  $preparedEmailForm->readInputData();
71 
72  if ($preparedEmailForm->validate()) {
73  $preparedEmailForm->execute();
74 
75  // Create notification.
76  $notificationMgr = new NotificationManager();
77  $user = $request->getUser();
78  $notificationMgr->createTrivialNotification($user->getId());
79 
80  // Let the calling grid reload itself
81  return DAO::getDataChangedEvent($emailKey);
82  } else {
83  $json = new JSONMessage(false);
84  return $json->getString();
85  }
86  }
87 
94  function resetEmail($args, $request) {
95  $emailKey = $request->getUserVar('emailKey');
96  assert(is_string($emailKey));
97 
98  $journal = $request->getJournal();
99 
100  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */
101  if ($emailTemplateDao->templateExistsByKey($emailKey, $journal->getId())) {
102  $emailTemplateDao->deleteEmailTemplateByKey($emailKey, $journal->getId());
103  return DAO::getDataChangedEvent($emailKey);
104  } else {
105  $json = new JSONMessage(false);
106  return $json->getString();
107  }
108  }
109 
115  function resetAllEmails($args, $request) {
116  $journal = $request->getJournal();
117  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */
118  $emailTemplateDao->deleteEmailTemplatesByJournal($journal->getId());
119  return DAO::getDataChangedEvent();
120  }
121 
127  function disableEmail($args, $request) {
128  $emailKey = $request->getUserVar('emailKey');
129  assert(is_string($emailKey));
130 
131  $journal = $request->getJournal();
132 
133  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */
134  $emailTemplate = $emailTemplateDao->getBaseEmailTemplate($emailKey, $journal->getId());
135 
136  if (isset($emailTemplate)) {
137  if ($emailTemplate->getCanDisable()) {
138  $emailTemplate->setEnabled(0);
139 
140  if ($emailTemplate->getAssocId() == null) {
141  $emailTemplate->setAssocId($journal->getId());
142  $emailTemplate->setAssocType(ASSOC_TYPE_JOURNAL);
143  }
144 
145  if ($emailTemplate->getEmailId() != null) {
146  $emailTemplateDao->updateBaseEmailTemplate($emailTemplate);
147  } else {
148  $emailTemplateDao->insertBaseEmailTemplate($emailTemplate);
149  }
150 
151  return DAO::getDataChangedEvent($emailKey);
152  }
153  } else {
154  $json = new JSONMessage(false);
155  return $json->getString();
156  }
157  }
158 
159 
165  function enableEmail($args, $request) {
166  $emailKey = $request->getUserVar('emailKey');
167  assert(is_string($emailKey));
168 
169  $journal = $request->getJournal();
170 
171  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */
172  $emailTemplate = $emailTemplateDao->getBaseEmailTemplate($emailKey, $journal->getId());
173 
174  if (isset($emailTemplate)) {
175  if ($emailTemplate->getCanDisable()) {
176  $emailTemplate->setEnabled(1);
177 
178  if ($emailTemplate->getEmailId() != null) {
179  $emailTemplateDao->updateBaseEmailTemplate($emailTemplate);
180  } else {
181  $emailTemplateDao->insertBaseEmailTemplate($emailTemplate);
182  }
183 
184  return DAO::getDataChangedEvent($emailKey);
185  }
186  } else {
187  $json = new JSONMessage(false);
188  return $json->getString();
189  }
190  }
191 
197  function deleteCustomEmail($args, $request) {
198  $emailKey = $request->getUserVar('emailKey');
199  $journal = $request->getJournal();
200 
201  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */
202  if ($emailTemplateDao->customTemplateExistsByKey($emailKey, $journal->getId())) {
203  $emailTemplateDao->deleteEmailTemplateByKey($emailKey, $journal->getId());
204  return DAO::getDataChangedEvent($emailKey);
205  } else {
206  $json = new JSONMessage(false);
207  return $json->getString();
208  }
209  }
210 
211 }
212 
213 ?>
static & getDAO($name, $dbconn=null)
Form for creating and modifying prepared emails.
Class to represent a JSON (Javascript Object Notation) message.
static getDataChangedEvent($elementId=null, $parentElementId=null)
Definition: DAO.inc.php:606
Handle PreparedEmails grid row requests.
Handle preparedEmails grid requests.