Esempio n. 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);
 }
Esempio n. 2
0
 /**
  * Removes a task from favorites for a particular (or current) user. This function DOES NOT check permissions.
  * 
  * @param mixed[] Primary key for \Bitrix\Tasks\Task\FavoriteTable entity
  * @param mixed[] Behaviour flags
  * 
  *  <li> AFFECT_CHILDREN boolean if true, all child tasks also will be added to favorite. (default false)
  * 
  * @return \Bitrix\Main\Entity\DeleteResult
  */
 public static function delete($primary, $behaviour = array('AFFECT_CHILDREN' => false))
 {
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     if (!isset($behaviour['AFFECT_CHILDREN'])) {
         $behaviour['AFFECT_CHILDREN'] = false;
     }
     $primary = static::processPrimary($primary);
     $result = parent::delete($primary);
     if ($result->isSuccess() && $behaviour['AFFECT_CHILDREN']) {
         // add also all children...
         $res = TaskTable::getChildrenTasksData($primary['TASK_ID'], array('runtime' => TaskTable::getRuntimeFieldMixins(array('IN_FAVORITE'), array('USER_ID' => $primary['USER_ID'])), 'select' => array('IN_FAVORITE')));
         while ($item = $res->fetch()) {
             if ($item['IN_FAVORITE']) {
                 // our client
                 static::delete(array('TASK_ID' => $item['ID']), array('AFFECT_CHILDREN' => false));
             }
         }
     }
     return $result;
 }