예제 #1
0
 public static function checkCanCreateDependence()
 {
     if (Bitrix24\Task::checkFeatureEnabled('gant')) {
         return true;
         // yes, you are using box, or you are in trial mode
     }
     // generally no, but you can make 5 dependences
     return DependenceTable::getLinkCount() < 5;
 }
예제 #2
0
 public function deleteDependOn($parentId)
 {
     $exceptionInfo = array('AUX' => array('MESSAGE' => array('FROM_TASK_ID' => $parentId, 'TASK_ID' => $this->getId(), 'LINK_TYPE' => $linkType)));
     if ($this->isActionAllowed(self::ACTION_CHANGE_DEADLINE)) {
         $parentTask = CTaskItem::getInstanceFromPool($parentId, $this->executiveUserId);
         if ($parentTask->isActionAllowed(self::ACTION_CHANGE_DEADLINE)) {
             $result = DependenceTable::deleteLink($this->getId(), $parentId);
             if (!$result->isSuccess()) {
                 $exceptionInfo['ERROR'] = $result->getErrorMessages();
                 throw new ActionFailedException(Loc::getMessage('TASK_CANT_DELETE_LINK'), $exceptionInfo);
             }
             return;
         }
     }
     throw new ActionNotAllowedException(Loc::getMessage('TASK_CANT_DELETE_LINK'), $exceptionInfo);
 }
예제 #3
0
 /**
  * Inject info about links with parent tasks (in terms of project dependence).
  * This data is used when gantt is shown. To get dependent tasks, use the other function.
  * 
  * Unsure about this function, so access private currently
  * 
  * @access private
  */
 private static function injectIngoingDependenceFields(array $parameters, array &$data, array &$can)
 {
     // task join here?
     $res = DependenceTable::getListByLegacyTaskFilter($parameters['LIST_PARAMETERS']['FILTER'], array('select' => array('DEPENDS_ON_ID', 'TYPE', 'TASK_ID')));
     while ($item = $res->fetch()) {
         if (isset($data[$item['TASK_ID']])) {
             $taskId = $item['TASK_ID'];
             unset($item['TASK_ID']);
             $dependsOnId = $item['DEPENDS_ON_ID'];
             unset($item['DEPENDS_ON_ID']);
             $data[$taskId]['INGOING_DEPENDECE_ID'][$dependsOnId] = $item;
         }
     }
 }
예제 #4
0
 protected function getTaskRelationHash()
 {
     $id = $this->taskId;
     $result = array();
     if ($id) {
         global $DB;
         $sql = DependenceTable::getSubTreeSql($id);
         $res = $DB->query($sql);
         $items = array();
         // all items
         $taskData = array($id => true);
         // actual task list in bundle
         while ($item = $res->fetch()) {
             // make datetime objects
             if ($item['CREATED_DATE']) {
                 $item['CREATED_DATE'] = DateTime::createFromUserTimeGmt($item['CREATED_DATE']);
             }
             if ($item['START_DATE_PLAN']) {
                 $item['START_DATE_PLAN'] = DateTime::createFromUserTimeGmt($item['START_DATE_PLAN']);
             }
             if ($item['END_DATE_PLAN']) {
                 $item['END_DATE_PLAN'] = DateTime::createFromUserTimeGmt($item['END_DATE_PLAN']);
             }
             $items[] = $item;
             $taskId = $item['TASK_ID'];
             unset($item['TASK_ID']);
             unset($item['TYPE']);
             unset($item['FROM_TASK_ID']);
             $taskData[$taskId] = $item;
         }
         $relations = array();
         foreach ($items as $item) {
             if (isset($taskData[$item['FROM_TASK_ID']])) {
                 $pid = $item['FROM_TASK_ID'];
                 $relations[$pid][$item['TASK_ID']] = array('TASK_ID' => $item['TASK_ID'], 'TYPE' => $item['TYPE'], 'FROM_TASK_ID' => $item['FROM_TASK_ID']);
             }
             // else skip this relation
         }
         $this->makeRelationTree($this->taskId, $relations, $taskData);
         $filteredRelations = array();
     }
 }
예제 #5
0
 function CheckFields(&$arFields, $ID = false, $effectiveUserId = null)
 {
     global $APPLICATION, $USER;
     if ($effectiveUserId === null) {
         $effectiveUserId = is_object($USER) ? intval($USER->GetID()) : 1;
     }
     if ((is_set($arFields, "TITLE") || $ID === false) && strlen($arFields["TITLE"]) <= 0) {
         $this->_errors[] = array("text" => GetMessage("TASKS_BAD_TITLE"), "id" => "ERROR_BAD_TASKS_TITLE");
     }
     // you are not allowed to clear up END_DATE_PLAN while the task is linked
     if ($ID && (isset($arFields['END_DATE_PLAN']) && (string) $arFields['END_DATE_PLAN'] == '')) {
         if (DependenceTable::checkItemLinked($ID)) {
             $this->_errors[] = array("text" => GetMessage("TASKS_IS_LINKED_END_DATE_PLAN_REMOVE"), "id" => "ERROR_TASKS_IS_LINKED");
         }
     }
     if ($ID && (isset($arFields['PARENT_ID']) && intval($arFields['PARENT_ID']) > 0)) {
         if (DependenceTable::checkLinkExists($ID, $arFields['PARENT_ID'], array('BIDIRECTIONAL' => true))) {
             $this->_errors[] = array("text" => GetMessage("TASKS_IS_LINKED_SET_PARENT"), "id" => "ERROR_TASKS_IS_LINKED");
         }
     }
     // If plan dates were set
     if (isset($arFields['START_DATE_PLAN']) && isset($arFields['END_DATE_PLAN']) && $arFields['START_DATE_PLAN'] != '' && $arFields['END_DATE_PLAN'] != '') {
         $startDate = MakeTimeStamp($arFields['START_DATE_PLAN']);
         $endDate = MakeTimeStamp($arFields['END_DATE_PLAN']);
         // and they were really set
         if ($startDate > 0 && $endDate > 0) {
             // and end date is before start date => then emit error
             if ($endDate < $startDate) {
                 $this->_errors[] = array('text' => GetMessage('TASKS_BAD_PLAN_DATES'), 'id' => 'ERROR_BAD_TASKS_PLAN_DATES');
             }
         }
     }
     if ($ID === false && !is_set($arFields, "RESPONSIBLE_ID")) {
         $this->_errors[] = array("text" => GetMessage("TASKS_BAD_RESPONSIBLE_ID"), "id" => "ERROR_TASKS_BAD_RESPONSIBLE_ID");
     }
     if ($ID === false && !is_set($arFields, "CREATED_BY")) {
         $this->_errors[] = array("text" => GetMessage("TASKS_BAD_CREATED_BY"), "id" => "ERROR_TASKS_BAD_CREATED_BY");
     }
     if (is_set($arFields, "CREATED_BY")) {
         if (!($arFields['CREATED_BY'] >= 1)) {
             $this->_errors[] = array("text" => GetMessage("TASKS_BAD_CREATED_BY"), "id" => "ERROR_TASKS_BAD_CREATED_BY");
         }
     }
     if (is_set($arFields, "RESPONSIBLE_ID")) {
         $r = CUser::GetByID($arFields["RESPONSIBLE_ID"]);
         if ($arUser = $r->Fetch()) {
             if ($ID) {
                 $rsTask = CTasks::GetList(array(), array("ID" => $ID), array("RESPONSIBLE_ID"), array('USER_ID' => $effectiveUserId));
                 if ($arTask = $rsTask->Fetch()) {
                     $currentResponsible = $arTask["RESPONSIBLE_ID"];
                 }
             }
             if (!$ID || isset($currentResponsible) && $currentResponsible != $arFields["RESPONSIBLE_ID"]) {
                 $createdBy = $arFields["CREATED_BY"];
                 $arSubDeps = CTasks::GetSubordinateDeps($createdBy);
                 if (!is_array($arUser["UF_DEPARTMENT"])) {
                     $bSubordinate = sizeof(array_intersect($arSubDeps, array($arUser["UF_DEPARTMENT"]))) > 0;
                 } else {
                     $bSubordinate = sizeof(array_intersect($arSubDeps, $arUser["UF_DEPARTMENT"])) > 0;
                 }
                 if (!$arFields["STATUS"]) {
                     $arFields["STATUS"] = self::STATE_PENDING;
                 }
                 if (!$bSubordinate) {
                     $arFields["ADD_IN_REPORT"] = "N";
                 }
                 $arFields["DECLINE_REASON"] = false;
             }
         } else {
             $this->_errors[] = array("text" => GetMessage("TASKS_BAD_RESPONSIBLE_ID_EX"), "id" => "ERROR_TASKS_BAD_RESPONSIBLE_ID_EX");
         }
     }
     if (is_set($arFields, "PARENT_ID") && intval($arFields["PARENT_ID"]) > 0) {
         $r = CTasks::GetByID($arFields["PARENT_ID"], true, array('USER_ID' => $effectiveUserId));
         if (!$r->Fetch()) {
             $this->_errors[] = array("text" => GetMessage("TASKS_BAD_PARENT_ID"), "id" => "ERROR_TASKS_BAD_PARENT_ID");
         }
     }
     if ($ID !== false && $ID == $arFields["PARENT_ID"]) {
         $this->_errors[] = array("text" => GetMessage("TASKS_PARENT_SELF"), "id" => "ERROR_TASKS_PARENT_SELF");
     }
     if ($ID !== false && is_array($arFields["DEPENDS_ON"]) && in_array($ID, $arFields["DEPENDS_ON"])) {
         $this->_errors[] = array("text" => GetMessage("TASKS_DEPENDS_ON_SELF"), "id" => "ERROR_TASKS_DEPENDS_ON_SELF");
     }
     /*
     if(!$ID)
     {
     	// since this time we dont allow to create tasks with a non-bbcode description
     	if($arFields['DESCRIPTION_IN_BBCODE'] == 'N')
     	{
     		$this->_errors[] = array("text" => GetMessage("TASKS_DESCRIPTION_IN_BBCODE_NO_NOT_ALLOWED"), "id" => "ERROR_TASKS_DESCRIPTION_IN_BBCODE_NO_NOT_ALLOWED");
     	}
     	else
     	{
     		$arFields['DESCRIPTION_IN_BBCODE'] = 'Y';
     	}
     }
     */
     if (!empty($this->_errors)) {
         $e = new CAdminException($this->_errors);
         $APPLICATION->ThrowException($e);
         return false;
     }
     //Defaults
     if (is_set($arFields, 'PRIORITY')) {
         if (!in_array((string) $arFields['PRIORITY'], array((string) self::PRIORITY_LOW, (string) self::PRIORITY_AVERAGE, (string) self::PRIORITY_HIGH), true)) {
             $arFields['PRIORITY'] = self::PRIORITY_AVERAGE;
         }
         $arFields['PRIORITY'] = (int) $arFields['PRIORITY'];
     }
     // flags
     self::checkBooleanParameter($arFields, 'ALLOW_CHANGE_DEADLINE');
     self::checkBooleanParameter($arFields, 'TASK_CONTROL');
     self::checkBooleanParameter($arFields, 'ADD_IN_REPORT');
     self::checkBooleanParameter($arFields, 'MATCH_WORK_TIME');
     self::checkBooleanParameter($arFields, 'REPLICATE');
     return true;
 }