PageRenderTime 24ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/source/components/com_pftasks/site/controllers/tasks.php

https://github.com/projectfork/Projectfork
PHP | 195 lines | 89 code | 32 blank | 74 comment | 13 complexity | 09091dcabdfd4db24d1a5ca6eebea7cd MD5 | raw file
  1. <?php
  2. /**
  3. * @package Projectfork
  4. * @subpackage Tasks
  5. *
  6. * @author Tobias Kuhn (eaxs)
  7. * @copyright Copyright (C) 2006-2012 Tobias Kuhn. All rights reserved.
  8. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.txt
  9. */
  10. defined('_JEXEC') or die();
  11. jimport('joomla.application.component.controlleradmin');
  12. /**
  13. * Projectfork Task List Controller
  14. *
  15. */
  16. class PFtasksControllerTasks extends JControllerAdmin
  17. {
  18. /**
  19. * The default list view
  20. *
  21. * @var string
  22. */
  23. protected $view_list = 'tasks';
  24. /**
  25. * The prefix to use with controller messages.
  26. *
  27. * @var string
  28. */
  29. protected $text_prefix = 'COM_PROJECTFORK_TASKS';
  30. /**
  31. * Method to get a model object, loading it if required.
  32. *
  33. * @param string $name The model name. Optional.
  34. * @param string $prefix The class prefix. Optional.
  35. * @param array $config Configuration array for model. Optional.
  36. *
  37. * @return object The model.
  38. */
  39. public function &getModel($name = 'TaskForm', $prefix = 'PFtasksModel', $config = array('ignore_request' => true))
  40. {
  41. $model = parent::getModel($name, $prefix, $config);
  42. return $model;
  43. }
  44. /**
  45. * Method to save the priority of one or more tasks
  46. *
  47. * @return boolean True on success, otherwise false
  48. */
  49. public function savePriority()
  50. {
  51. // Check for request forgeries.
  52. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  53. // Initialise variables.
  54. $ids = JRequest::getVar('cid', null, 'post', 'array');
  55. $pids = JRequest::getVar('priority', null, 'post', 'array');
  56. $model = $this->getModel();
  57. $return = $model->savePriority($ids, $pids);
  58. if ($return === false) {
  59. // Storage failed.
  60. $message = JText::sprintf('COM_PROJECTFORK_ERROR_SAVEPRIORITY_FAILED', $model->getError());
  61. $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false), $message, 'error');
  62. return false;
  63. }
  64. else {
  65. // Storage succeeded.
  66. $message = JText::_('COM_PROJECTFORK_SUCCESS_TASK_SAVEPRIORITY');
  67. $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false), $message);
  68. return true;
  69. }
  70. }
  71. /**
  72. * Method to assign a user to one or more tasks
  73. *
  74. * @return boolean True on success, otherwise false
  75. */
  76. public function addUsers()
  77. {
  78. // Check for request forgeries.
  79. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  80. // Initialise variables.
  81. $ids = JRequest::getVar('cid', null, 'post', 'array');
  82. $uids = JRequest::getVar('assigned', null, 'post', 'array');
  83. $model = $this->getModel();
  84. $return = $model->addUsers($ids, $uids);
  85. if ($return === false) {
  86. // Assigning failed.
  87. $message = JText::sprintf('COM_PROJECTFORK_ERROR_ADDUSER_FAILED', $model->getError());
  88. $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false), $message, 'error');
  89. return false;
  90. }
  91. else {
  92. // Assigning succeeded.
  93. $message = JText::_('COM_PROJECTFORK_SUCCESS_TASK_ADDUSER');
  94. $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false), $message);
  95. return true;
  96. }
  97. }
  98. /**
  99. * Method to remove a user from one or more tasks
  100. *
  101. * @return boolean True on success, otherwise false
  102. */
  103. public function deleteUsers()
  104. {
  105. // Check for request forgeries.
  106. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  107. // Initialise variables.
  108. $ids = JRequest::getVar('cid', null, 'post', 'array');
  109. $uids = JRequest::getVar('assigned', null, 'post', 'array');
  110. $model = $this->getModel();
  111. $return = $model->deleteUsers($ids, $uids);
  112. if ($return === false) {
  113. // Deletion failed.
  114. $message = JText::sprintf('COM_PROJECTFORK_ERROR_ADDUSER_FAILED', $model->getError());
  115. $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false), $message, 'error');
  116. return false;
  117. }
  118. else {
  119. // Deletion succeeded.
  120. $message = JText::_('COM_PROJECTFORK_SUCCESS_TASK_ADDUSER');
  121. $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false), $message);
  122. return true;
  123. }
  124. }
  125. /**
  126. * Gets the URL arguments to append to an item redirect.
  127. *
  128. * @param int $id The primary key id for the item.
  129. * @param string $url_var The name of the URL variable for the id.
  130. *
  131. * @return string The arguments to append to the redirect URL.
  132. */
  133. protected function getRedirectToItemAppend($id = null, $url_var = 'id')
  134. {
  135. // Need to override the parent method completely.
  136. $tmpl = JRequest::getCmd('tmpl');
  137. $layout = JRequest::getCmd('layout');
  138. $item_id = JRequest::getUInt('Itemid');
  139. $return = $this->getReturnPage();
  140. $append = '';
  141. // Setup redirect info.
  142. if ($tmpl) $append .= '&tmpl=' . $tmpl;
  143. if ($layout) $append .= '&layout=' . $layout;
  144. if ($id) $append .= '&' . $url_var . '=' . $id;
  145. if ($item_id) $append .= '&Itemid=' . $item_id;
  146. if ($return) $append .= '&return=' . base64_encode($return);
  147. return $append;
  148. }
  149. /**
  150. * Get the return URL.
  151. * If a "return" variable has been passed in the request
  152. *
  153. * @return string The return URL.
  154. */
  155. protected function getReturnPage()
  156. {
  157. $return = JRequest::getVar('return', null, 'default', 'base64');
  158. if (empty($return) || !JUri::isInternal(base64_decode($return))) {
  159. return JURI::base();
  160. }
  161. return base64_decode($return);
  162. }
  163. }