Example #1
0
 public function postInsertupdate()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     $businesslogic = NULL;
     if (Input::get("bl_id")) {
         $businesslogic = Businesslogic::find(Input::get("bl_id"));
     }
     $fields = ["name" => Input::get("name")];
     $rules = ["name" => "required"];
     $customMessages = ["name.required" => "Поле \"Заголовок\" обязательно для заполнения"];
     if (!$businesslogic && !Input::get("id")) {
         $fields["contractor"] = Input::get("contractor");
         $rules["contractor"] = "required|numeric|exists:users,id";
         $customMessages["contractor.required"] = "Вы не выбрали исполнителя";
     }
     $validator = Validator::make($fields, $rules, $customMessages);
     if ($validator->fails()) {
         $error = "";
         foreach (array_keys($fields) as $k) {
             $message = $validator->messages()->first($k);
             if ($message) {
                 $error .= "<div>" . $message . "</div>";
             }
         }
         return Response::json(["error" => $error]);
     }
     $item = NULL;
     $method = "update";
     if (Input::get("id")) {
         $item = Task::find(Input::get("id"));
     }
     if (!$item) {
         $method = "insert";
         $item = new Task();
     }
     if ($method == "insert") {
         $item->bl_id = Input::get("bl_id", NULL) ? Input::get("bl_id") : NULL;
     }
     $item->subtask_id = Input::get("parent", NULL) ? Input::get("parent") : NULL;
     $item->author_id = $this->userdata->id;
     $item->category_id = Input::get("type", NULL) ? Input::get("type") : NULL;
     $item->name = Input::get("name");
     $item->text = Input::get("comment");
     $item->deadline_at = $this->makeDeadlineDate();
     $item->save();
     if (Input::get("contractor", NULL) && $method == "insert") {
         $assign = new Taskassign();
         $assign->task_id = $item->id;
         $assign->user_from_id = $this->userdata->id;
         $assign->user_to_id = Input::get("contractor");
         $assign->save();
         Taskemails::taskAssigned($assign);
     }
     if (!Input::get("contractor", NULL) && $businesslogic && $method == "insert") {
         $assign = new Taskassign();
         $assign->task_id = $item->id;
         $assign->logicstep_id = $item->defineFirstLogicStep();
         $assign->user_from_id = $this->userdata->id;
         $assign->user_to_id = $this->userdata->id;
         $assign->save();
         Taskemails::taskAssigned($assign);
     }
     $fileStr = Input::get("files");
     if ($fileStr) {
         $ids = explode(",", $fileStr);
         foreach ($ids as $fileid) {
             $file = Taskfile::find($fileid);
             if (!$file) {
                 continue;
             }
             $file->task_id = $item->id;
             $file->save();
         }
     }
     $message = $item->parentTask ? 'Подзадача успешно опубликована.' : 'Задача опубликована.';
     Session::flash("message", $message);
     $redirect = $item->parentTask ? '/tasks/my/view/' . $item->parentTask->id : '/tasks/my/view/' . $item->id;
     return Response::json(["error" => "", "redirect" => $redirect]);
 }
Example #2
0
 public function postStepadd($id = false)
 {
     if (!$id) {
         return App::abort(404);
     }
     $blogic = Businesslogic::find($id);
     if (!$blogic) {
         return App::abort(404);
     }
     $fields = ["name" => Input::get("name"), "position" => Input::get("position")];
     $rules = ["name" => "required|max:255", "position" => "required|numeric|exists:positions,id"];
     $customMessages = ["name.required" => "Поле \"Заголовок\" обязательно для заполнения", "position.required" => "Выберите должность"];
     $validator = Validator::make($fields, $rules, $customMessages);
     if ($validator->fails()) {
         $error = "";
         foreach (array_keys($fields) as $k) {
             $message = $validator->messages()->first($k);
             if ($message) {
                 $error .= "<div>" . $message . "</div>";
             }
         }
         return Redirect::to($_SERVER["HTTP_REFERER"])->with("error", $error);
     }
     $item = new Businesslogicstep();
     $item->bl_id = $id;
     $item->position_id = Input::get("position");
     $item->name = Input::get("name");
     $item->comment = Input::get("comment");
     $item->sort = Businesslogicstep::count();
     $item->save();
     return Redirect::to("/tasks/logics/steps/" . $id)->with("message", "Этап успешно опубликован");
 }