123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- use app\models\entity\ProjectsLocotech;
- use app\models\entity\CheckpointTypesForTasks;
- use app\models\entity\CheckpointTypeHierarchy;
- use app\models\entity\Tasks;
- use app\models\entity\Tasktypes;
- use app\models\entity\CheckpointTypes;
- class CheckPointTypeModel extends Model
- {
-
- public $id;
- public $priority;
- public $name;
- public $parentTaskTypeId;
- public $parentCheckpointTypeId;
- public $childrenCheckpointTypes;
- public $class;
-
- // работает
-
- public function getCheckPointTypesByTask($task_type = null)
- {
- $checkpointTypes = array(); //массив значений чекпойнтов
-
- if ($task_type != null){
- $resultTasks = CheckpointTypesForTasks::find()->where(['tasktype_id' => $task_type ])->all();
-
- } else {
- $resultTasks = CheckpointTypesForTasks::find()->all();
- }
- return $resultTasks;
- }
-
-
- // работает
-
- public function createFromID($id)
- {
- $checkpointTypesEntity = CheckpointTypes::findOne($id);
- if ( $checkpointTypesEntity ) {
- $cpType = self::CreateFromArray($checkpointTypesEntity);
- return $cpType;
- }
- return null;
- }
-
- // работает
-
- public static function CreateFromArray($checkpointArr)
- {
-
- $checkpointType = new CheckPointTypeModel();
- $checkpointType->id = $checkpointArr->id;
- $checkpointType->name = $checkpointArr->name;
- $checkpointType->class = $checkpointArr->class;
- $checkpointType->childrenCheckpointTypes = array();
- $checkpointType->FillChildren();
- return $checkpointType;
- }
-
- // работает
-
- function FillChildren()
- {
- $checkpointTypeHierarchy = CheckpointTypeHierarchy::find()->where(['parent_cp_type' => $this->id] );
- foreach ($checkpointTypeHierarchy as $hierarchy) {
- $checkpointTypes = CheckPointTypes::find()->where(['id' => $child->cp_type])->all();
- foreach ($checkpointTypes as $type) {
- $child = self::CreateFromArray($checkarr);
- array_push($this->childrenCheckpointTypes, $child);
- }
- }
- }
-
-
- }
|