Exemple #1
0
 /**
  * Prepares "parameters" argument for self::getList() according to the purposes of a REST interface
  * 
  * @param mixed[] Initial parameters
  * @param mixed[] Behaviour flags
  * 
  * 	<li> USER_ID integer Current user id, mandatory.
  * 	<li> ROW_LIMIT integer Row limit on each rest query, optional
  * 
  * @return mixed[]
  */
 public static function getList(array $parameters = array(), $behaviour = array())
 {
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     $behaviour['USER_ID'] = Assert::expectIntegerPositive($behaviour['USER_ID'], '$behaviour[USER_ID]');
     if (!isset($behaviour['ROW_LIMIT'])) {
         $behaviour['ROW_LIMIT'] = false;
     }
     $runtime = array();
     if (is_array($parameters['order']) && !empty($parameters['order'])) {
         static::parseOutSimpleAggregations(array_keys($parameters['order']), $runtime);
     }
     $parameters['filter']['=TASK.ZOMBIE'] = 'N';
     if (is_array($parameters['select']) && !empty($parameters['select'])) {
         static::parseOutSimpleAggregations($parameters['select'], $runtime);
     }
     $rights = TaskTable::getRuntimeFieldMixins(array('CHECK_RIGHTS'), array('USER_ID' => $behaviour['USER_ID'], 'REF_FIELD' => 'TASK_ID'));
     if (!empty($rights)) {
         $runtime['CHECK_RIGHTS'] = $rights['CHECK_RIGHTS'];
     }
     if (!empty($runtime)) {
         $parameters['runtime'] = $runtime;
     }
     $behaviour['ROW_LIMIT'] = intval($behaviour['ROW_LIMIT']);
     if ($behaviour['ROW_LIMIT'] && (!isset($parameters['limit']) || (int) $parameters['limit'] > $behaviour['ROW_LIMIT'])) {
         $parameters['limit'] = $behaviour['ROW_LIMIT'];
     }
     return parent::getList($parameters);
 }
Exemple #2
0
 public static function delete($ownerId, $id, array $parameters = array())
 {
     global $USER_FIELD_MANAGER;
     $ownerId = Assert::expectStringNotNull($ownerId, '$ownerId');
     $id = Assert::expectIntegerPositive($id, '$id');
     $parameters['USER_ID'] = Assert::expectIntegerPositive($parameters['USER_ID'], '$parameters[USER_ID]');
     $parameters['ENTITY_ID'] = Assert::expectStringNotNull($parameters['ENTITY_ID'], '$parameters[ENTITY_ID]');
     $parameters['FIELD_NAME'] = Assert::expectStringNotNull($parameters['FIELD_NAME'], '$parameters[FIELD_NAME]');
     static::checkFieldExistsThrowException($parameters['ENTITY_ID'], $parameters['FIELD_NAME']);
     $currentValue = static::getValue($ownerId, $parameters['ENTITY_ID'], $parameters['FIELD_NAME']);
     $currentValue = array_diff($currentValue, array($id));
     $USER_FIELD_MANAGER->Update($parameters['ENTITY_ID'], $ownerId, array($parameters['FIELD_NAME'] => $currentValue), $parameters['USER_ID']);
     return true;
 }
Exemple #3
0
 public function __construct($userId, $task, array $taskData = array(), Calendar $calendar = null)
 {
     if ($calendar === null) {
         $this->calendar = new Calendar();
     } else {
         $this->calendar = $calendar;
     }
     $this->userId = Assert::expectIntegerPositive($userId, '$userId', 'Incorrect userId passed');
     if (is_object($task) && $task instanceof \CTaskItem) {
         $this->taskId = $task->getId();
         $this->initializeTaskFromObject($task);
     } else {
         $this->taskId = intval($task);
         if (!$this->taskId && empty($taskData)) {
             throw new ArgumentException('Neither correct task id nor task data specified');
         }
         $this->initializeTaskFromData($taskData);
     }
 }
 /**
  * Removes all checklist's items for given template.
  * This function is low-level, i.e. it disrespects any events\callbacks
  * 
  * @param integer $templateId
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function deleteByTemplateId($templateId)
 {
     $templateId = Assert::expectIntegerPositive($templateId, '$templateId');
     \Bitrix\Main\HttpApplication::getConnection()->query("DELETE FROM " . static::getTableName() . " WHERE TEMPLATE_ID = '" . $templateId . "'");
 }
Exemple #5
0
 /**
  * Removes a task from favorites for all users. This function DOES NOT check permissions.
  * 
  * @param integer Task id
  * @param mixed[] Behaviour
  * 
  * 		<li> LOW_LEVEL boolean If set to true, function will ignore all events and do a low-level db query
  * 
  * @return \Bitrix\Main\Entity\DeleteResult
  */
 public static function deleteByTaskId($taskId, $behaviour = array('LOW_LEVEL' => false))
 {
     $taskId = Assert::expectIntegerPositive($taskId, '$taskId');
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     if (!isset($behaviour['LOW_LEVEL'])) {
         $behaviour['LOW_LEVEL'] = false;
     }
     if ($behaviour['LOW_LEVEL']) {
         HttpApplication::getConnection()->query("delete from " . static::getTableName() . " where TASK_ID = '" . intval($taskId) . "'");
         $result = true;
     } else {
         $result = array();
         $res = static::getList(array('filter' => array('=TASK_ID' => $taskId)));
         while ($item = $res->fetch()) {
             $result[] = static::delete(array('TASK_ID' => $item['TASK_ID'], 'USER_ID' => $item['USER_ID']));
         }
     }
     return $result;
 }
Exemple #6
0
 public static function getSubTreeSql($id)
 {
     $id = Assert::expectIntegerPositive($id, '$id');
     $parentColName = static::getPARENTIDColumnName();
     $idColName = static::getIDColumnName();
     return "select " . $idColName . " from " . static::getTableName() . " where " . $parentColName . " = '" . intval($id) . "'";
 }
Exemple #7
0
 /**
  * For better perfomance purposes
  */
 public static function getSubTreeSql($id)
 {
     $id = Assert::expectIntegerPositive($id, '$id');
     global $DB;
     $tableName = static::getTableName();
     $parentColName = static::getPARENTIDColumnName();
     $idColName = static::getIDColumnName();
     $directColName = static::getDIRECTColumnName();
     // select STATUS as REAL_STATUS, according to the CTasks::GetList() behaviour
     // (in \Bitrix\Tasks\TaskTable there is different alias naming)
     /*
     --DEP_T.DURATION_PLAN as DURATION_PLAN,
     */
     // enough data to say if and how we can change dates
     // look also at \Bitrix\Tasks\Util\Scheduler::initializeTargetTask()
     // CDatabase::DateToCharFunction() converts database format like "2015-10-15 00:00:00"
     // to a site format: "22.06.2015 11:39:50", and optionally adds the timezone offset
     return "\n\t\t\tselect \n\t\t\t\tDEP." . $idColName . " as " . $idColName . ",\n\t\t\t\tDEP_P.TYPE as TYPE,\n\t\t\t\tDEP_P." . $parentColName . " as FROM_TASK_ID,\n\n\t\t\t\tDEP_T.ID as ID,\n\t\t\t\tDEP_T.MATCH_WORK_TIME as MATCH_WORK_TIME,\n\t\t\t\tDEP_T.ALLOW_CHANGE_DEADLINE as ALLOW_CHANGE_DEADLINE,\n\t\t\t\tDEP_T.DURATION_TYPE as DURATION_TYPE,\n\n\t\t\t\tDEP_T.RESPONSIBLE_ID as RESPONSIBLE_ID,\n\t\t\t\tDEP_T.CREATED_BY as CREATED_BY,\n\t\t\t\tDEP_T.GROUP_ID as GROUP_ID,\n\t\t\t\tDEP_T.STATUS as REAL_STATUS,\n\n\t\t\t\t" . $DB->DateToCharFunction("DEP_T.CREATED_DATE", "FULL") . " as CREATED_DATE,\n\t\t\t\t" . $DB->DateToCharFunction("DEP_T.START_DATE_PLAN", "FULL") . " as START_DATE_PLAN,\n\t\t\t\t" . $DB->DateToCharFunction("DEP_T.END_DATE_PLAN", "FULL") . " as END_DATE_PLAN\n\t\t\tfrom \n\t\t\t\t" . $tableName . " DEP\n\n\t\t\tinner join \n\t\t\t\tb_tasks DEP_T\n\t\t\t\t\ton \n\t\t\t\t\t\tDEP." . $idColName . " = DEP_T.ID\n\t\t\tinner join \n\t\t\t\t" . $tableName . " DEP_P \n\t\t\t\t\ton \n\t\t\t\t\t\tDEP_P." . $directColName . " = '1'and DEP." . $idColName . " = DEP_P." . $idColName . "\n\n\t\t\twhere DEP." . $parentColName . " = '" . intval($id) . "'\n\t\t";
 }
Exemple #8
0
 protected static function getRuntimeFieldMixinsCheckRights($parameters)
 {
     $result = false;
     $parameters['USER_ID'] = Assert::expectIntegerPositive($parameters['USER_ID'], '$parameters[USER_ID]');
     $rf = $parameters['REF_FIELD'];
     if (!\CTasksTools::IsAdmin($userId) && !\CTasksTools::IsPortalB24Admin($userId)) {
         list($conditions, $expression) = \CTasks::getPermissionFilterConditions($parameters, array('USE_PLACEHOLDERS' => true));
         $conditions = "(case when (" . implode(' OR ', $conditions) . ") then '1' else '0' end)";
         array_unshift($expression, $conditions);
         $query = new \Bitrix\Main\Entity\Query('Bitrix\\Tasks\\Task');
         $query->registerRuntimeField('F', array('data_type' => 'string', 'expression' => $expression));
         $query->setFilter(array('=F' => '1'));
         $query->setSelect(array('TASK_ID' => 'ID'));
         $result = new Entity\ReferenceField($parameters['NAME'], \Bitrix\Main\Entity\Base::getInstanceByQuery($query), array('=this.' . ((string) $rf != '' ? $rf : 'ID') => 'ref.TASK_ID'), array('join_type' => 'inner'));
     }
     return $result;
 }
Exemple #9
0
 protected static function applyCreateRestrictions(&$id, &$parentId)
 {
     $id = Assert::expectIntegerPositive($id, '$id');
     $parentId = Assert::expectIntegerNonNegative($parentId, '$parentId');
     // parent id might be equal to 0
     if (static::checkLinkExists($id, $parentId)) {
         throw new Tree\LinkExistsException(false, array('NODES' => array($id, $parentId)));
     }
 }