GrabTask( $taskid );
$parent = intval($task->parent_id);
if ($parent > 0)
return intval($task->status);
else
{
$tasks = $this->GrabSubTasks( $taskid );
$assigned = 0;
$accepted = 0;
$hold = 0;
$done = 0;
$lentasks = sizeof($tasks);
foreach ($tasks as $task)
{
$status = intval( $task->status );
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)
{
return 2;
}
elseif ($assigned > 0)
return 2;
else
return 1;
}
}
// работает
public function GetTasksForProject($projectid, $status=0, $inactiveproject=0, $subs = 0)
{
global $link;
// $taskstring = $this->GetTasksFromProjectString($projectid);
$projectsLocotechEntity = ProjectsLocotech::findOne($projectid);
$taskstring = $projectsLocotechEntity->tasks;
if ( $inactiveproject != 0 ) {
$countTaskEntity = Tasks::find()->where(['and',['id' => $taskstring],['or','status=2','status=3']])->count();
if ( $countTaskEntity ) {
$count = intval($countTaskEntity);
if ( $count > 0 ) {
echo "Found started tasks!";
return;
}
}
}
if ( $subs > 0 ) {
$tasksarr = explode(",", $taskstring);
foreach ($tasksarr as $task_id)
{
$parent = $this->GrabTask($task_id);
if ( $parent->status == $status ) {
return $this->GrabSubTasks($task_id);
}
}
}
if ($status != 0) {
$tasksEntity = Tasks::find()->where(['and', ['id' =>$taskstring],['status' => $status]])->all();
} else {
if( !empty($taskstring)) {
$tasksEntity = Tasks::find()->where(['in', 'id', $taskstring ])->all();
}
}
$ret = array();
if ( !empty($tasksEntity) ) {
foreach( $tasksEntity as $task){
$tempArray = [];
foreach($task as $item){
$tempArray[] = $item;
}
array_push($ret, $tempArray);
}
}
return $ret;
}
public function GetTasksFromProjectString($projectid)
{
$projectsLocotechEntity = ProjectsLocotech::findOne($projectid);
$ret = array();
if ($projectsLocotechEntity)
{
$ret = $projectsLocotechEntity->tasks;
}
return $ret;
}
public function GrabTask($task_id)
{
$tasksEntity = Tasks::findOne($task_id);
if ( $tasksEntity ) {
//$result = sizeof($tasksEntity);
return $tasksEntity;
}
return null;
}
public function GrabSubTasks($parent_id)
{
$subtasks = array();
$tasksEntity = Tasks::find()->where(['parent_id' => $parent_id])->all();
foreach ( $tasksEntity as $task) {
array_push($subtasks, $task);
}
return $subtasks;
}
// работает
public function GrabTasktypes( $chooseSubtasks = "all" )
{
$companyId = Yii::$app->params['api']['companyId'];
$tasktypesEntity = new Tasktypes();
if ($chooseSubtasks == "subs") {
$result = $tasktypesEntity::find()->where(['and','company' => $companyId,'main_task' => 0])->orderBy(['id' => DESC])->all();
} else if ( $chooseSubtasks == "tasks" ) {
$result = $tasktypesEntity::find()->where(['and','company' => $companyId,'main_task' => 1])->orderBy(['id' => DESC])->all();
} else {
$result = $tasktypesEntity::find()->where(['company' => $companyId])->orderBy(['id' => 'DESC'])->all();
}
if ( 0 == count($result) ) {
return [];
}
return $result;
}
public function CreateTasks($tasktypesarr, $input_id=0)
{
global $link;
// echo "CreateTasks $input_id";
// print_r($tasktypesarr);
// $query = mysqli_query($link, "select * from input_tables where id=".$input_id);
// if ($res = mysqli_fetch_array($query)) {
//
// }
$maintasks = array();
foreach ($tasktypesarr as $tasktype_data)
{
if ($tasktype_data->main_task == '1')
{
$tasktype = $tasktype_data->id;
// $tasktype_data = array_values($tasktypesarr)[0];//!!!! только первый эелмент берется
// echo "subtasks ".$tasktype_data['subtasks']." tasktype ".$tasktype;
$subtaskarr = explode(",", $tasktype_data->subtasks);
// echo $action_data['name'] . "! Входная таблица " . $assign_id;
$result = mysqli_query($link, "INSERT INTO tasks (type, status, priority, created, input_id) VALUES ($tasktype, 1, 0, NOW(), $input_id)"); //создание глобальной задачи
if (mysqli_affected_rows($link) >0 )
{
$parent_id = mysqli_insert_id($link);
array_push($maintasks, $parent_id);
// $query1 = mysqli_query($link, "select MAX(id) from tasks");
// if ($res1 = mysqli_fetch_row($query1)) {
// $parent_id = $res1[0];
//// echo "created parent_id ".$parent_id;
// }
$priority = 1;
foreach ($subtaskarr as $sub) {
$str = "insert into tasks (type, parent_id, priority, status, created, input_id) values ($sub, $parent_id, $priority, 1, NOW(), $input_id)";
//echo "$str
";
$sub_id = mysqli_insert_id($link);
//создаем парентов
$types = \CheckPointTypes\CheckPointType::GetCheckPointTypesByTask($sub);
if (sizeof($types) > 0) {
$q = mysqli_query($link, "select MAX(id) from tasks");
if ($res = mysqli_fetch_row($q))
{
$myid = $res[0];
foreach ($types as $typeID) {
echo "create type " . $typeID['cp_type_id'];
//var_dump($typeID['cp_type_id']);die();
$cpt = \CheckPointTypes\CheckPointType::CreateFromID($typeID['cp_type_id']);
if ($cpt != null)
$cp = \CheckPoints\CheckPoint::CreateFromType($cpt, null, $myid+1);
}
}
}
mysqli_query($link, $str); //создание подзадач
$priority++;
}
}
}
}
if (sizeof($maintasks) > 0) {
echo " Задачи созданы для проекта $input_id!";
$taskstring = implode(",",$maintasks);
AddTasksToProject($taskstring, $input_id);
}
else
echo ' Нет ни одной основной задачи!
';
}
// работает
public function CreateTasksExtra($tasktypesarr, $input_id=0)
{
$checkpointModel = new CheckPointTypeModel();
$tasksEntitySelect = new Tasks();
$maintasks = array();
foreach ( $tasktypesarr as $tasktype_data ) {
if ( $tasktype_data->main_task == '1') {
$tasktype = $tasktype_data->id;
$subtaskarr = explode(",", $tasktype_data->subtasks);
$testksEntity = new Tasks();
$testksEntity->type = $tasktype;
$testksEntity->status = 1;
$testksEntity->priority = 0;
$testksEntity->created = date("Y-m-d H:i:s");
$testksEntity->input_id = $input_id;
if ( $testksEntity->save() ) {
$parent_id = $testksEntity->id;
array_push($maintasks, $parent_id);
$priority = 1;
foreach ( $subtaskarr as $sub ) {
if ( null == $sub ) {
continue;
}
$testksEntitySub = new Tasks();
$testksEntitySub->type = $sub;
$testksEntitySub->parent_id = $parent_id;
$testksEntitySub->priority = $priority;
$testksEntitySub->status = 1;
$testksEntitySub->created = date("Y-m-d H:i:s");
$testksEntitySub->input_id = $input_id;
$testksEntitySub->save();
$sub_id = $testksEntitySub->id;
$types = $checkpointModel::GetCheckPointTypesByTask($sub);
if (count($types) > 0) {
$id = Tasks::find()->max('id');
$tasksEntity = Tasks::findOne($id);
if ( $tasksEntity ) {
$myid = $tasksEntity->id;
foreach ($types as $typeID) {
$this->message['createType'][] = $typeID->cp_type_id;
$cpt = $checkpointModel->CreateFromID($typeID->cp_type_id);
if ($cpt != null){
$cp = CheckPointModel::CreateFromType($cpt, null, $myid+1);
}
}
}
}
$priority++;
}
}
}
}
if (sizeof($maintasks) > 0) {
//echo " Задачи созданы для проекта $input_id!";
$this->createTasks = $input_id;
$taskstring = implode(",",$maintasks);
$this->AddTasksToProject($taskstring, $input_id);
} else {
//echo ' Нет ни одной основной задачи!
';
$this->message['createTasksMessage'] = 'Нет ни одной основной задачи!';
}
}
// работает
public function AddTasksToProject($taskstring, $input_id)
{
$projectsLocotechEntity = ProjectsLocotech::findOne($input_id);
$projectsLocotechEntity->tasks = $taskstring;
$projectsLocotechEntity->update();
}
public function TasksAssign($task_id, $execute, $project_id = 0)
{
//1 ищем акки без тасков
//2 определяем должности акков
//3 определяем доступные задачи по должностям
//2 берем активные (невыданные) задачи
//2 выдаем подходящим аккам их подзадачи
//tofix: удаление подзадач глобалов похоже не происходит на каком-то этапе
//tofix: выдавать подзадачи с глобалами
//tofix: подзадачи согласно проекту, а не все подряд подходящие сотруднику
//global $link, $companyID;
$accountModel = new AccountModel();
$companyID = Yii::$app->params['api']['companyId'];
$freeaccounts = array();
$accountnames = array();
//get free accs (without active tasks)
$accountsEntity = Accounts::find()->where(['active_task_ids' => ''])->all();
//$str = "select * from accounts where active_task_ids = ''";
//$query1 = mysqli_query($link, $str);
$online_counter = 0;
foreach ($accountsEntity as $account) {
$last_seen_mobile = $account->last_seen_mobile;
$online_mobile = $accountModel->OnlineAccountCheck($last_seen_mobile);
if (!$online_mobile)
continue;
else
$online_counter++;
//var_dump($account->id);
$jobtypes = [];
foreach ($account->accountsJobtypes as $value) {
$jobtypes[] = $value->jobtype_id;
}
//$jobtypes = explode(",",$account->jobtypes);
$acc_id = $account->id;
$accountnames[$acc_id] = $account->name;
$freeaccounts[$acc_id] = $jobtypes;
}
if ($online_counter == 0)
{
$this->message['TasksAssign'] = 'Задачи не выданы в работу! Нет подходящих исполнителей онлайн';
//echo "