task_id = $taskCreated; self::$_instance->initiator = $initiator; self::$_instance->getTasktypeId(); self::$_instance->createCheckpoints(); return true; } private function cpt_get($tasktypeId) { $checkpointTypesForTasksEntity = CheckpointTypesForTasks::find()->select('cp_type_id')->where(['tasktype_id' => $tasktypeId])->orderBy(['coalesce(priority, 0)' => SORT_ASC, 'cp_type_id' => SORT_ASC])->all(); return $checkpointTypesForTasksEntity; } private function cb_get($cpt) { $checkpointTypeHierarchyEntity = CheckpointTypeHierarchy::find()->select('cp_type')->where(['parent_cp_type' => $cpt])->orderBy(['cp_type' => SORT_ASC])->all(); return $checkpointTypeHierarchyEntity; } // 1 private function getTasktypeId() { $tasksEntity = Tasks::find()->select('type')->where(['id' => self::$_instance->task_id])->one(); self::$_instance->tasktypeId = $tasksEntity->type; } // 2 private function createCheckpoints() { $tasktype = self::$_instance->tasktypeId; foreach(self::$_instance->cpt_get($tasktype) as $tasktypeId) { self::$_instance->txt = CheckpointTypes::findOne($tasktypeId->cp_type_id); self::$_instance->generateUuid(); // 2.1 self::$_instance->addCheckpoints(); // 2.2 self::$_instance->cpid = Checkpoints::find()->where(['text' => self::$_instance->tmpUuid])->one(); $checkpointsEntity = Checkpoints::findOne(self::$_instance->cpid->id); $checkpointsEntity->text = self::$_instance->txt->name; $checkpointsEntity->save(); foreach( self::$_instance->cb_get($tasktypeId->cp_type_id) as $parent ) { self::$_instance->getCheckpointTypesName($parent->cp_type); // 2.3 self::$_instance->insertCheckpointTypes($parent->cp_type); // 2.4 } } } // 2.1 private function generateUuid() { $query = 'select UUID()'; $uuid = Yii::$app->db->createCommand('select UUID() as uuid')->queryOne(); self::$_instance->tmpUuid = $uuid["uuid"]; if ( null == self::$_instance->tmpUuid ){ return false; } return true; } // 2.2 private function addCheckpoints() { $checkpointsEntity = new Checkpoints(); $checkpointsEntity->type = $tasktypeId->cp_type_id; $checkpointsEntity->text = self::$_instance->tmpUuid; $checkpointsEntity->parent_task_id = self::$_instance->task_id; $checkpointsEntity->parent_checkpoint_id = 0; $checkpointsEntity->save(); if ( !$checkpointsEntity->save()){ return false; } return true; } //2.3 private function getCheckpointTypesName($cb) { $checkpointTypesEntity = CheckpointTypes::find()->select('name')->where(['id' => $cb])->one(); self::$_instance->txtParent = $checkpointTypesEntity->name; if ( null == self::$_instance->txtParent ){ return false; } return true; } // 2.4 private function insertCheckpointTypes($cb) { $checkpointsEntity = new Checkpoints(); $checkpointsEntity->type = $cb; $checkpointsEntity->text = self::$_instance->txtParent; $checkpointsEntity->parent_task_id = self::$_instance->task_id; $checkpointsEntity->parent_checkpoint_id = self::$_instance->cpid->id; $checkpointsEntity->save(); if ( null == self::$_instance->tmpUuid ){ return false; } return true; } } /* 197366 cpt_add: BEGIN declare tasktypeId integer; declare cpt integer; declare txt varchar(255); declare tmpUuid varchar(255); declare cb integer; declare cpid integer; declare done integer; declare cpt_get cursor for select cp_type_id from checkpoint_types_for_tasks where tasktype_id = tasktypeId order by coalesce(priority, 0), cp_type_id; declare cb_get cursor for select cp_type from checkpoint_type_hierarchy where parent_cp_type = cpt order by cp_type; declare continue handler for not found set done = 1; 1 select type into tasktypeId from tasks where id = task_id; 2 open cpt_get; cptget: loop set done = 0; fetch cpt_get into cpt; if done = 1 then leave cptget; end if; select name into txt from checkpoint_types where id = cpt; set tmpUuid = uuid(); insert into checkpoints (type, text, parent_task_id, parent_checkpoint_id) values (cpt, tmpUuid, task_id, 0); select id into cpid from checkpoints where text = tmpUuid; update checkpoints set text = txt where id = cpid; open cb_get; cbget: loop set done = 0; fetch cb_get into cb; if done = 1 then leave cbget; end if; select name into txt from checkpoint_types where id = cb; insert into checkpoints (type, text, parent_task_id, parent_checkpoint_id) values (cb, txt, task_id, cpid); end loop; close cb_get; end loop; close cpt_get; END */