Esempio n. 1
0
 public function addDependOn($parentId, $linkType = DependenceTable::LINK_TYPE_FINISH_START)
 {
     $exceptionInfo = array('AUX' => array('MESSAGE' => array('FROM_TASK_ID' => $parentId, 'TASK_ID' => $this->getId(), 'LINK_TYPE' => $linkType)));
     if (!\Bitrix\Tasks\Util\Restriction::checkCanCreateDependence()) {
         $exceptionInfo['ERROR'] = array(array('CODE' => 'TRIAL_EXPIRED', 'MESSAGE' => Loc::getMessage('TASKS_TRIAL_PERIOD_EXPIRED')));
         throw new ActionRestrictedException(Loc::getMessage('TASK_CANT_ADD_LINK'), $exceptionInfo);
     }
     if ($this->isActionAllowed(self::ACTION_CHANGE_DEADLINE)) {
         $parentTask = CTaskItem::getInstanceFromPool($parentId, $this->executiveUserId);
         if ($parentTask->isActionAllowed(self::ACTION_CHANGE_DEADLINE)) {
             // DependenceTable does not care about PARENT_ID relations and other restrictions except
             // those which may compromise dependence mechanism logic
             // so PARENT_ID check and DATE assignment are placed outside
             $errors = array();
             if ($this->checkIsSubtaskOf($parentId) || $parentTask->checkIsSubtaskOf($this->getId())) {
                 $errors['TASKS_HAS_PARENT_RELATION'] = Loc::getMessage('TASKS_HAS_PARENT_RELATION');
             } else {
                 // assign dates
                 $calendar = new Calendar();
                 $taskScheduler = new Scheduler($this->executiveUserId, $this, array(), $calendar);
                 $taskScheduler->defineDates();
                 $taskScheduler->sync();
                 $parentTaskScheduler = new Scheduler($this->executiveUserId, $parentTask, array(), $calendar);
                 $parentTaskScheduler->defineDates();
                 $parentTaskScheduler->sync();
                 $result = DependenceTable::createLink($this->getId(), $parentId, $linkType, array('TASK_DATA' => $this->getData(false), 'PARENT_TASK_DATA' => $parentTask->getData(false)));
                 if (!$result->isSuccess()) {
                     $errors = array_merge($errors, $result->getErrorMessages());
                 }
             }
             if (!empty($errors)) {
                 $exceptionInfo['ERROR'] = $errors;
                 throw new ActionFailedException(Loc::getMessage('TASK_CANT_ADD_LINK'), $exceptionInfo);
             }
             return;
         }
     }
     throw new ActionNotAllowedException(Loc::getMessage('TASK_CANT_ADD_LINK'), $exceptionInfo);
 }