initiator = $initiator; $this->projecttype = $projecttype; $this->locoserie = $locoserie; $this->loconumber = $loconumber; $this->projectcomment = $projectcomment; //1 Получаем ид компании инициатора //1.1 если null то умираем if(!$this->GetCompanyId()) { return false; } // 2. Проверяем на существование тип проекта // 2.1 Если null то умираем if(!$this->IsissetProjecttype()) { return false; } // 3 генерируем uuid $this->generateUuid(); //4 создаем проект //4.1 проверяем прошла ли запись //$this->buildProject(); // 5 чистим все таски у созданного проекта //$this->CleanProjectTasks(); // 6. получаем список тасков на тип проекта // 6.1 закидываем нужные таски в проект $listTasks = $this->GetListTasks(); if ($this->addTaskInProject($listTasks)) { return $this->projId; } return false; //echo "
";
        //var_dump($this->GetListTasks());
        //echo "
"; //exit; } private function GetCompanyId() { $accountsEntity = Accounts::findOne($this->initiator); $this->companyId = $accountsEntity->company; if ( null == $this->companyId){ return false; } return true; } private function IsissetProjecttype() { $projecttypesEntity = Projecttypes::find()->where(['id' => $this->projecttype ,'company' => $this->companyId])->one(); $this->tasktype = $projecttypesEntity->id; if ( null == $this->tasktype){ return false; } return true; } private function generateUuid() { $query = 'select UUID()'; $uuid = Yii::$app->db->createCommand('select UUID() as uuid')->queryOne(); $this->projectGuid = $uuid["uuid"]; if ( null == $this->projectGuid){ return false; } return true; } private function buildProject() { $projectsLocotechEntity = new ProjectsLocotech(); $projectsLocotechEntity->action = $this->projecttype; $projectsLocotechEntity->tasks = $this->projectGuid; $projectsLocotechEntity->company = $this->companyId; $projectsLocotechEntity->status = 1; $projectsLocotechEntity->loco_type = $this->locoserie; $projectsLocotechEntity->loco_number = $this->loconumber; $projectsLocotechEntity->urgent = 0; $projectsLocotechEntity->created = date('Y-m-d H:i:S'); $projectsLocotechEntity->uuid = $this->projectcomment; if ($projectsLocotechEntity->save()) { $projectsLocotechOne = ProjectsLocotech::findOne(['tasks' => $this->projectGuid]); $this->projId = $projectsLocotechOne->id; if ( null == $this->projId ){ return false; } return true; } return false; } private function CleanProjectTasks() { $projectsLocotechEntity = ProjectsLocotech::findOne($this->projId); $projectsLocotechEntity->tasks = ''; if ( !$projectsLocotechEntity->save()) { return false; } } private function GetListTasks() { $projecttypesTasktypesEntity = ProjecttypesTasktypes::find() ->select(['tasktype_id']) ->where(['projecttype_id' => $this->projecttype]) ->orderBy(['priority' => SORT_ASC]) ->all(); return $projecttypesTasktypesEntity; } private function addTaskInProject($listTasks) { if (is_array($listTasks)) { foreach ( $listTasks as $task) { //var_dump($this->initiator, $this->projId, $task->tasktype_id); echo "\n"; $addTaskIntoProjectModel = new AddTaskIntoProjectModel(); $addTaskIntoProjectModel->execute($this->initiator, $this->projId, $task->tasktype_id); } } return true; } }