Exemplo n.º 1
0
 /**
  * Save task list as a template
  *
  * @access public
  * @param void
  * @return null
  */
 function save_as_template()
 {
     $this->setTemplate('save_as_template');
     $task_list = ProjectTaskLists::findById(get_id());
     if (!$task_list instanceof ProjectTaskList) {
         flash_error(lang('task list dnx'));
         $this->redirectTo('task');
     }
     // if
     if (!$task_list->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectTo('task');
     }
     // if
     tpl_assign('task_list', $task_list);
     if (isset($_POST['new']) && isset($_POST['name'])) {
         $name = sanitize($_POST['name']);
         if (strlen($name) == 0) {
             flash_error(lang('task list template name required'));
             $this->redirectTo('task');
         }
         if (ProjectTaskListTemplates::nameExists($name)) {
             flash_error(lang('task list template unique'));
             return;
         }
         $temp = new ProjectTaskListTemplate();
         $data = $task_list->pickle();
         $temp->setData($data);
         $temp->setName($name);
         try {
             DB::beginWork();
             $temp->save();
             ApplicationLogs::createLog($temp, active_project(), ApplicationLogs::ACTION_ADD);
             DB::commit();
             flash_success(lang('success save as template task list', $temp->getName()));
             $this->redirectToUrl($task_list->getViewUrl());
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }