Esempio n. 1
0
 /**
  * Method to run batch operations.
  *
  * @param     jmodel     $model    The model of the component being processed.
  *
  * @return    boolean              True if successful, false otherwise and internal error is set.
  */
 public function batch($model)
 {
     // Initialise variables.
     $input = JFactory::getApplication()->input;
     $vars = $input->post->get('batch', array(), 'array');
     $cid = $input->post->get('cid', array(), 'array');
     $data = array();
     $data['success'] = "true";
     $data['messages'] = array();
     $data['data'] = array();
     // Build an array of item contexts to check
     $contexts = array();
     foreach ($cid as $id) {
         // If we're coming from com_categories, we need to use extension vs. option
         if (isset($this->extension)) {
             $option = $this->extension;
         } else {
             $option = $this->option;
         }
         $contexts[$id] = $option . '.' . $this->context . '.' . $id;
     }
     // Attempt to run the batch operation.
     if ($model->batch($vars, $cid, $contexts)) {
         $data['messages'][] = JText::_('JLIB_APPLICATION_SUCCESS_BATCH');
         $this->sendResponse($data);
     } else {
         $data['success'] = "false";
         $data['messages'][] = JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_FAILED', $model->getError());
         $this->sendResponse($data);
     }
 }
 /**
  * Function that allows child controller access to model data after the data has been saved.
  *
  * @param     jmodel    $model        The data model object.
  * @param     array     $validData    The validated data.
  *
  * @return    void
  */
 protected function postSaveHook(&$model, $validData)
 {
     $task = $this->getTask();
     $id = (int) $model->getState('tasklistform.id');
     switch ($task) {
         case 'save2copy':
         case 'save2new':
             // No redirect because its already set
             break;
         case 'save2milestone':
             $link = JRoute::_(PFmilestonesHelperRoute::getMilestonesRoute() . '&task=form.add');
             $this->setRedirect($link);
             break;
         case 'save2task':
             $link = JRoute::_(PFtasksHelperRoute::getTasksRoute() . '&task=taskform.add&list_id=' . $id);
             $this->setRedirect($link);
             break;
         default:
             $this->setRedirect($this->getReturnPage());
             break;
     }
 }