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 "Задачи для этого проекта уже созданы
";
return true;
}
$tasktypesarr = GrabTasktypes("all", intval($action));
if (sizeof($tasktypesarr) > 0) {
CreateTasks($tasktypesarr, $project_id);
return true;
}
else
{
echo "Ошибка: нет подходящих задач под выбранное действие";
return false;
}
}
*/
}