123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- use app\models\TasksModel;
- use app\models\entity\ProjectsLocotech;
- /**
- * This is the model class for table "s_regions".
- *
- * The followings are the available columns in table 's_regions':
- * @property integer $rg_id
- * @property string $rg_name
- */
- class ProjectsModel extends MainModel
- {
- public $errors;
- public $createProject;
-
- // работает
-
- public function StartProject($action, $project_id)
- {
- // die();
- $tasksModel = new TasksModel();
- $existing_tasks = $tasksModel->GetTasksForProject($project_id);
-
- if (sizeof($existing_tasks) > 0) {
- $this->message['createProject'] = 'Задачи для этого проекта уже созданы';
- return true; //данная функция:
- }
- $tasktypesarr = $tasksModel->GrabTasktypes("all", intval($action));
- if (count($tasktypesarr) > 0) {
- //$tasksModel->CreateTasks($tasktypesarr, $project_id);
- $tasksModel->CreateTasksExtra($tasktypesarr, $project_id);
- $this->message = $tasksModel->message;
- return true;
- } else {
- $this->message['createProject'] = 'Ошибка: нет подходящих задач под выбранное действие';
- return false;
- }
- }
-
- public function addProject($params,$idSection = null)
- {
- $result = false;
- $projectsLocotech = new ProjectsLocotech();
- $projectsLocotech->action = $params['action'];
- $projectsLocotech->company = $params['company'];
- $projectsLocotech->status = 1;
- $projectsLocotech->loco_type = $params['loco_type'];
- $projectsLocotech->loco_number = $params['loco_number'];
- $projectsLocotech->depo = $params['depo'];
- $projectsLocotech->depo_service = $params['depo_service'];
- $projectsLocotech->kind = $params['kind'];
- // $projectsLocotech->diagnostic_card = $params['diagnosticCard'];
- $projectsLocotech->created = date('Y-m-d H:i:s');
- $projectsLocotech->section_id = $idSection;
- if( $projectsLocotech->save() ) {
- return $projectsLocotech->id;
- }
-
- $this->errors['addProject'] = $projectsLocotech->errors;
- return $result;
- }
-
- // работает
-
- public function StartProjectRequest($action,$activeid) {
-
- //$jsonEncoded = ['activeid' => $activeid, 'action' => $action,'appMykey' => 123465];
- $jsonEncoded = "activeid=".$activeid."&action=".$action."&appMykey=123465";
- $url = $_SERVER['SERVER_NAME'] . "/addproject.php";
-
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_TIMEOUT, 20);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonEncoded);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec($curl);
-
- $info = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- //$result = json_decode($result,true);
- //echo $result;
- curl_close($curl);
- return $result;
- }
-
- public function GetProjectStatus( $projid )
- {
- $tasksModel = new TasksModel();
- $tasks = $tasksModel->GetTasksForProject( $projid );
- $assigned = 0;
- $accepted = 0;
- $hold = 0;
- $done = 0;
- $numcommands = 0;
- $lentasks = 0;
- foreach ( $tasks as $task ) {
- if ( $task->parent_id == '0') {
- $lentasks++;
- $numcommands++;
-
- $status = $tasksModel->GetTaskStatus( $task->id );
- switch ($status) {
- case 2:
- $assigned++;
- break;
- case 3:
- $accepted++;
- break;
- case 4:
- $hold++;
- break;
- case 5:
- $done++;
- break;
- }
- }
- }
- if ( $done == $lentasks && $lentasks > 0 ) {
- return 5;
- } elseif ( $accepted > 0 || $assigned > 0 ) {
- return 2;
- } else {
- return 1;
- }
- }
-
- public function getStatusArray($entity) {
-
- $arrayResult = [];
- foreach ($entity as $item) {
- $arrayResult[ $item->id ] = $this->GetProjectStatus($item->id);
- }
- return $arrayResult;
- }
- /*
- public function StartProject($action, $project_id)
- {
- //$assign_id - id таблицы входных данных
- //$action - действие (например перемещение)
- //данная функция:
- //1. ищет в базе среди tasktype данное действие (глобальное main_task=true)
- //2. создает задачу найденного типа
- $tasksModel = new TasksModel();
- $existing_tasks = $tasksModel->GetTasksForProject($project_id);
- if (sizeof($existing_tasks) > 0) {
- echo "<span style='color: red'>Задачи для этого проекта уже созданы</span><br>";
- return true;
- }
- $tasktypesarr = GrabTasktypes("all", intval($action));
- if (sizeof($tasktypesarr) > 0) {
- CreateTasks($tasktypesarr, $project_id);
- return true;
- }
- else
- {
- echo "<span style='color: red'>Ошибка: нет подходящих задач под выбранное действие</span>";
- return false;
- }
- }
-
- */
- }
|