Exemplo n.º 1
0
 /**
  * @param CTaskItemInterface $oTaskItem (of class CTaskItem,checklist item will be added to this task)
  * @param array $arFields with mandatory element TITLE (string).
  * 
  * @throws TasksException with code TasksException::TE_WRONG_ARGUMENTS
  * 
  * @return CTaskCheckListItem
  */
 public static function add(CTaskItemInterface $oTaskItem, $arFields)
 {
     global $DB;
     if (!self::checkFieldsForAdd($arFields)) {
         throw new TasksException('Bad arguments for ' . __CLASS__ . '::add()', TasksException::TE_WRONG_ARGUMENTS);
     }
     $arFields = self::normalizeFieldsDataForAdd($arFields);
     CTaskAssert::assert(isset($arFields['TITLE']) && is_string($arFields['TITLE']) && $arFields['TITLE'] !== '' && $oTaskItem instanceof CTaskItemInterface);
     if (!$oTaskItem->isActionAllowed(CTaskItem::ACTION_CHECKLIST_ADD_ITEMS)) {
         throw new TasksException(__CLASS__ . '::add() is not allowed to call', TasksException::TE_ACTION_NOT_ALLOWED);
     }
     $taskId = (int) $oTaskItem->getId();
     $executiveUserId = (int) $oTaskItem->getExecutiveUserId();
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $curDatetime = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time() + CTimeZone::GetOffset());
     $arFieldsToDb = array('TITLE' => $arFields['TITLE'], 'TASK_ID' => $taskId, 'CREATED_BY' => $executiveUserId, 'IS_COMPLETE' => 'N');
     if (isset($arFields['SORT_INDEX'])) {
         $arFieldsToDb['SORT_INDEX'] = (int) $arFields['SORT_INDEX'];
     } else {
         $rc = $DB->Query("SELECT MAX(SORT_INDEX) AS MAX_SORT_INDEX\n\t\t\t\tFROM b_tasks_checklist_items \n\t\t\t\tWHERE TASK_ID = " . (int) $taskId, $bIgnoreErrors = true);
         if (!$rc) {
             throw new TasksException('SQL error', TasksException::TE_SQL_ERROR);
         }
         if (($arSortIndex = $rc->fetch()) && isset($arSortIndex['MAX_SORT_INDEX'])) {
             $arFieldsToDb['SORT_INDEX'] = (int) $arSortIndex['MAX_SORT_INDEX'] + 1;
         } else {
             $arFieldsToDb['SORT_INDEX'] = 0;
         }
     }
     if (isset($arFields['IS_COMPLETE'])) {
         $arFieldsToDb['IS_COMPLETE'] = $arFields['IS_COMPLETE'];
     }
     $id = $DB->add('b_tasks_checklist_items', $arFieldsToDb, $arCLOBFields = array(), 'tasks', $ignore_errors = true);
     $occurAsUserId = CTasksTools::getOccurAsUserId();
     if (!$occurAsUserId) {
         $occurAsUserId = $executiveUserId;
     }
     // changes log
     $arLogFields = array('TASK_ID' => $taskId, 'USER_ID' => $occurAsUserId, 'CREATED_DATE' => $curDatetime, 'FIELD' => 'CHECKLIST_ITEM_CREATE', 'FROM_VALUE' => '', 'TO_VALUE' => $arFields['TITLE']);
     if (!($id > 0)) {
         CTaskAssert::logError('[0xbb7986ff] ');
         throw new TasksException('Action failed', TasksException::TE_ACTION_FAILED_TO_BE_PROCESSED);
     }
     $log = new CTaskLog();
     $log->Add($arLogFields);
     if ($arFieldsToDb['IS_COMPLETE'] === 'Y') {
         // changes log
         $arLogFields = array('TASK_ID' => (int) $taskId, 'USER_ID' => $occurAsUserId, 'CREATED_DATE' => $curDatetime, 'FIELD' => 'CHECKLIST_ITEM_CHECK', 'FROM_VALUE' => $arFields['TITLE'], 'TO_VALUE' => $arFields['TITLE']);
         $log->Add($arLogFields);
     }
     return new self($oTaskItem, (int) $id);
 }
Exemplo n.º 2
0
 /**
  * @param CTaskItemInterface $oTaskItem
  * @param array $arFields with mandatory elements POST_MESSAGE
  * @throws TasksException
  * @return CTaskElapsedItem
  */
 public static function add(CTaskItemInterface $oTaskItem, $arFields)
 {
     CTaskAssert::assert(is_array($arFields) && !empty($arFields));
     // if you reached this point (e.g. created an instance of a task class, you have an access to the task and therefore can comment it)
     //if ( ! $this->isActionAllowed(CTaskItem::ACTION_COMMENT_ADD) )
     //	throw new TasksException('', TasksException::TE_ACTION_NOT_ALLOWED);
     $obComment = new CTaskComments();
     $messageId = $obComment->add($oTaskItem->getId(), $oTaskItem->getExecutiveUserId(), $arFields['POST_MESSAGE']);
     if ($messageId === false) {
         throw new TasksException('', TasksException::TE_ACTION_FAILED_TO_BE_PROCESSED);
     }
     return new self($oTaskItem, (int) $messageId);
 }
Exemplo n.º 3
0
 /**
  * @param CTaskItemInterface $oTaskItem
  * @throws TasksException
  * @return array $arReturn with elements
  * 		<ul>
  * 		<li>$arReturn[0] - array of items
  * 		<li>$arReturn[1] - CDBResult
  * 		</ul>
  */
 public static function fetchList(CTaskItemInterface $oTaskItem, $arOrder = array(), $arFilter = array())
 {
     $arItems = array();
     CTaskAssert::assert($oTaskItem instanceof CTaskItemInterface);
     $taskId = (int) $oTaskItem->getId();
     // Ensure that we have read access for task
     $taskData = $oTaskItem->getData();
     try {
         list($arItemsData, $rsData) = static::fetchListFromDb($taskData, $arOrder, $arFilter);
     } catch (Exception $e) {
         throw new TasksException('Action failed', TasksException::TE_ACTION_FAILED_TO_BE_PROCESSED);
     }
     foreach ($arItemsData as $arItemData) {
         $arItems[] = self::constructWithPreloadedData($oTaskItem, $arItemData['ID'], $arItemData);
     }
     return array($arItems, $rsData);
 }
Exemplo n.º 4
0
 /**
  * @param CTaskItemInterface $oTaskItem
  * @param array $arFields with mandatory elements MINUTES, COMMENT_TEXT
  * @throws TasksException
  * @return CTaskElapsedItem
  */
 public static function add(CTaskItemInterface $oTaskItem, $arFields)
 {
     CTaskAssert::assert(is_array($arFields) && count($arFields) == 2 && isset($arFields['COMMENT_TEXT']) && (isset($arFields['MINUTES']) && CTaskAssert::isLaxIntegers($arFields['MINUTES']) || isset($arFields['SECONDS']) && CTaskAssert::isLaxIntegers($arFields['SECONDS'])) && is_string($arFields['COMMENT_TEXT']));
     if (!$oTaskItem->isActionAllowed(CTaskItem::ACTION_ELAPSED_TIME_ADD)) {
         throw new TasksException('', TasksException::TE_ACTION_NOT_ALLOWED);
     }
     $arFields['USER_ID'] = $oTaskItem->getExecutiveUserId();
     $arFields['TASK_ID'] = $oTaskItem->getId();
     /** @noinspection PhpDeprecationInspection */
     $obElapsed = new CTaskElapsedTime();
     $logId = $obElapsed->Add($arFields);
     // Reset tagged system cache by tag 'tasks_user_' . $userId for each task member
     self::__resetSystemWideTasksCacheByTag($oTaskItem->getData(false));
     if ($logId === false) {
         throw new TasksException('', TasksException::TE_ACTION_FAILED_TO_BE_PROCESSED);
     }
     return new self($oTaskItem, (int) $logId);
 }