save() public method

public save ( $task_data )
 public function create($action, $uid, $taskdata, $pre_task = 0)
 {
     if (!isset(\Tasks::$types[$action])) {
         return $this->err('任务类型错误');
     }
     if (in_array($action, array('checkout', 'update', 'delete'))) {
         if (!isset($taskdata['project_id'])) {
             return $this->err('需要project_id');
         }
     }
     if (in_array($action, array('rsync'))) {
         if (!isset($taskdata['server_id'])) {
             return $this->err('需要server_id');
         }
     }
     $record = new \Tasks();
     $record->type = $action;
     $record->command = json_encode($taskdata);
     $record->pre_task = $pre_task;
     $record->status = 'created';
     $record->create_time = date('Y-m-d H:i:s');
     $record->execute_time = '0000-00-00 00:00:00';
     $record->output = '';
     $record->uid = $uid;
     $record->save();
     return $record->id;
 }
Example #2
0
 public function post_add_new()
 {
     $data = Input::all();
     $UserValidation = Validator::make(Input::all(), array('new' => 'required|max:100'));
     if (!$UserValidation->fails()) {
         $user_id = Auth::id();
         $task = new Tasks();
         $task->task_name = $data['new'];
         $task->user_id = $user_id;
         $task->created_at = new DateTime();
         $task->save();
         $tasks = Auth::user()->tasks;
         $response = $tasks;
         return $response;
     }
 }
Example #3
0
 public function actionCreate_task($track = null)
 {
     if (!Yii::app()->my->access("edit")) {
         return false;
     }
     $task = new Tasks();
     $task->track = $track;
     // если значения переданы –выводим их
     if (isset($_REQUEST['Tasks'])) {
         foreach ($_REQUEST['Tasks'] as $key => $value) {
             $task->{$key} = $value;
         }
         if ($task->save()) {
             Yii::app()->notify->add("Новое задание успешно создано", "success");
             $this->redirect(array('/task/' . $task->id . '/edit'));
         } else {
             Yii::app()->notify->addErrors($task->getErrors());
             Yii::app()->notify->add("Не удалось создать задание", "danger");
         }
     }
     $this->render("task", array("task" => $task));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     if (Yii::app()->user->checkAccess('createTasks')) {
         $model = new Tasks();
         $Milestones = Milestones::model()->with('Projects.Company.Cusers')->together()->findAll(array('condition' => 'Cusers.user_id = :user_id AND t.project_id = :project_id AND Projects.project_endDate > CURDATE()', 'params' => array(':user_id' => Yii::app()->user->id, ':project_id' => Yii::app()->user->getState('project_selected'))));
         $Cases = Cases::model()->with('Projects.Company.Cusers')->together()->findAll(array('condition' => 'Cusers.user_id = :user_id AND t.project_id = :project_id', 'params' => array(':user_id' => Yii::app()->user->id, ':project_id' => Yii::app()->user->getState('project_selected'))));
         if (isset($_POST['Tasks'])) {
             $model->attributes = $_POST['Tasks'];
             $model->user_id = Yii::app()->user->id;
             $model->status_id = Status::STATUS_PENDING;
             $model->project_id = Yii::app()->user->getState('project_selected');
             $model->task_startDate = date("Y-m-d");
             //new CDbExpression('NOW()');
             if ($model->save()) {
                 // Guardar log
                 $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'TaskCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => 'created', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id, 'project_id' => $model->project_id);
                 Logs::model()->saveLog($attributes);
                 // avisar a los participantes del proyecto que una nueva tarea se ha agregado
                 $Users = Projects::model()->findAllUsersByProject($model->project_id);
                 $recipientsList = array();
                 foreach ($Users as $user) {
                     $recipientsList[] = array('name' => $user->CompleteName, 'email' => $user->user_email);
                 }
                 $subject = Yii::t('email', 'TaskStatusChanged') . " - " . $model->task_name;
                 $str = $this->renderPartial('//templates/tasks/statusChanged', array('task' => $model, 'username' => Yii::app()->user->CompleteName, 'task_url' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->createUrl('tasks/view', array('id' => $model->task_id)), 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true);
                 Yii::import('application.extensions.phpMailer.yiiPhpMailer');
                 $mailer = new yiiPhpMailer();
                 $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL);
                 $this->redirect(array('view', 'id' => $model->task_id));
             }
         }
         $this->render('create', array('model' => $model, 'status' => Status::model()->findAll(), 'types' => TaskTypes::model()->findAll(), 'stages' => TaskStages::model()->findAll(), 'milestones' => $Milestones, 'cases' => $Cases, 'allowEdit' => true));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
Example #5
0
 public function executeXlsTasksImport(sfWebRequest $request)
 {
     app::setPageTitle('Import Spreadsheet', $this->getResponse());
     if ($request->isMethod(sfRequest::PUT)) {
         if ($request->hasParameter('import_file')) {
             if (is_file($import_spreadsheet_file = sfConfig::get('sf_upload_dir') . '/' . $request->getParameter('import_file'))) {
                 $import_fields = $this->getUser()->getAttribute('import_fields');
                 $data = new Spreadsheet_Excel_Reader($import_spreadsheet_file);
                 $projects_id = $request->getParameter('projects_id');
                 if ($request->getParameter('import_first_row') == 1) {
                     $first_row = 1;
                 } elseif ($data->rowcount() > 2) {
                     $first_row = 2;
                 } else {
                     $first_row = 1;
                 }
                 for ($i = $first_row; $i <= $data->rowcount(); $i++) {
                     $t = new Tasks();
                     $t->setCreatedBy($this->getUser()->getAttribute('id'))->setCreatedAt(date('Y-m-d H:i:s'))->setProjectsId($request->getParameter('projects_id'));
                     $extra_fields = array();
                     for ($j = 1; $j <= $data->colcount(); $j++) {
                         if (isset($import_fields[$j])) {
                             $v = $data->val($i, $j);
                             if (strlen(trim($v)) == 0) {
                                 continue;
                             }
                             switch ($import_fields[$j]) {
                                 case 'TasksGroups':
                                     if ($id = app::getProjectCfgItemIdByName($v, 'TasksGroups', $projects_id)) {
                                         $t->setTasksGroupsId($id);
                                     } else {
                                         $cfg = new TasksGroups();
                                         $cfg->setName($v);
                                         $cfg->setProjectsId($projects_id);
                                         $cfg->save();
                                         $t->setTasksGroupsId($cfg->getId());
                                     }
                                     break;
                                 case 'Versions':
                                     if ($id = app::getProjectCfgItemIdByName($v, 'Versions', $projects_id)) {
                                         $t->setVersionsId($id);
                                     } else {
                                         $cfg = new Versions();
                                         $cfg->setName($v);
                                         $cfg->setProjectsId($projects_id);
                                         $cfg->save();
                                         $t->setVersionsId($cfg->getId());
                                     }
                                     break;
                                 case 'ProjectsPhases':
                                     if ($id = app::getProjectCfgItemIdByName($v, 'ProjectsPhases', $projects_id)) {
                                         $t->setProjectsPhasesId($id);
                                     } else {
                                         $cfg = new ProjectsPhases();
                                         $cfg->setName($v);
                                         $cfg->setProjectsId($projects_id);
                                         $cfg->save();
                                         $t->setProjectsPhasesId($cfg->getId());
                                     }
                                     break;
                                 case 'TasksPriority':
                                     if ($id = app::getCfgItemIdByName($v, 'TasksPriority')) {
                                         $t->setTasksPriorityId($id);
                                     } else {
                                         $cfg = new TasksPriority();
                                         $cfg->setName($v);
                                         $cfg->save();
                                         $t->setTasksPriorityId($cfg->getId());
                                     }
                                     break;
                                 case 'TasksLabels':
                                     if ($id = app::getCfgItemIdByName($v, 'TasksLabels')) {
                                         $t->setTasksLabelId($id);
                                     } else {
                                         $cfg = new TasksLabels();
                                         $cfg->setName($v);
                                         $cfg->save();
                                         $t->setTasksLabelId($cfg->getId());
                                     }
                                     break;
                                 case 'name':
                                     $t->setName($v);
                                     break;
                                 case 'TasksStatus':
                                     if ($id = app::getCfgItemIdByName($v, 'TasksStatus')) {
                                         $t->setTasksStatusId($id);
                                     } else {
                                         $cfg = new TasksStatus();
                                         $cfg->setName($v);
                                         $cfg->save();
                                         $t->setTasksStatusId($cfg->getId());
                                     }
                                     break;
                                 case 'TasksTypes':
                                     if ($id = app::getCfgItemIdByName($v, 'TasksTypes')) {
                                         $t->setTasksTypeId($id);
                                     } else {
                                         $cfg = new TasksTypes();
                                         $cfg->setName($v);
                                         $cfg->save();
                                         $t->setTasksTypeId($cfg->getId());
                                     }
                                     break;
                                     break;
                                 case 'assigned_to':
                                     $assigned_to = array();
                                     foreach (explode(',', $v) as $n) {
                                         if ($user = Doctrine_Core::getTable('Users')->createQuery()->addWhere('name=?', trim($n))->fetchOne()) {
                                             $assigned_to[] = $user->getId();
                                         }
                                     }
                                     $t->setAssignedTo(implode(',', $assigned_to));
                                     break;
                                 case 'estimated_time':
                                     $t->setEstimatedTime($v);
                                     break;
                                 case 'start_date':
                                     $t->setStartDate(date('Y-m-d', strtotime($v)));
                                     break;
                                 case 'due_date':
                                     $t->setDueDate(date('Y-m-d', strtotime($v)));
                                     break;
                                 case 'progress':
                                     $t->setProgress($v);
                                     break;
                             }
                             if (strstr($import_fields[$j], 'extra_field_')) {
                                 $extra_fields[str_replace('extra_field_', '', $import_fields[$j])] = $v;
                             }
                         }
                     }
                     $t->save();
                     foreach ($extra_fields as $id => $v) {
                         $f = new ExtraFieldsList();
                         $f->setBindId($t->getId());
                         $f->setExtraFieldsId($id);
                         $f->setValue($v);
                         $f->save();
                     }
                 }
                 $this->getUser()->setFlash('userNotices', t::__('Spreadsheet imported'));
                 $this->redirect('tasks/index?projects_id=' . $request->getParameter('projects_id'));
             }
         } elseif (($projects_id = $request->getParameter('projects_id')) > 0) {
             $f = $request->getFiles();
             if ($f['import_file']) {
                 $this->getUser()->setAttribute('import_fields', array());
                 move_uploaded_file($f['import_file']['tmp_name'], sfConfig::get('sf_upload_dir') . '/' . $f['import_file']['name']);
                 $this->import_file = $f['import_file']['name'];
                 if (is_file($import_spreadsheet_file = sfConfig::get('sf_upload_dir') . '/' . $this->import_file)) {
                     $this->data = new Spreadsheet_Excel_Reader($import_spreadsheet_file);
                     $this->setTemplate('xlsTasksImportBind');
                 } else {
                     $this->getUser()->setFlash('userNotices', array('type' => 'error', 'text' => t::__('There is an error with uploading file. Please try again with less file size.')));
                     $this->redirect('tools/xlsTasksImport');
                 }
             }
         }
     }
 }