Exemplo n.º 1
0
 /**
  * Add new task list from template
  *
  * @access public
  * @param void
  * @return null
  */
 function from_template()
 {
     if (!ProjectTaskList::canAdd(logged_user(), active_project())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('task'));
     }
     // if
     $templates = ProjectTaskListTemplates::findAll();
     tpl_assign('templates', $templates);
     if (isset($_POST['name']) && isset($_POST['from_id'])) {
         $template = ProjectTaskListTemplates::findById(sanitize($_POST['from_id']));
         if ($template == null) {
             flash_error(lang('invalid template id'));
             $this->redirectToReferer(get_url('project'));
         }
         $task_list = ProjectTaskListTemplates::fromPickle($template->getData());
         if ($task_list == null) {
             flash_error(lang('invalid template id'));
             $this->redirectToReferer(get_url('project'));
         }
         $task_list->setProjectId(active_project()->getId());
         $task_list->setName(sanitize($_POST['name']));
         try {
             DB::beginWork();
             $task_list->save();
             ApplicationLogs::createLog($task_list, active_project(), ApplicationLogs::ACTION_ADD);
             DB::commit();
             $this->redirectToUrl($task_list->getViewUrl());
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
     }
     // if
 }