예제 #1
0
 public static function runRestMethod($executiveUserId, $methodName, $args, $navigation)
 {
     static $arManifest = null;
     static $arMethodsMetaInfo = null;
     if ($arManifest === null) {
         $arManifest = self::getManifest();
         $arMethodsMetaInfo = $arManifest['REST: available methods'];
     }
     // Check and parse params
     CTaskAssert::assert(isset($arMethodsMetaInfo[$methodName]));
     $arMethodMetaInfo = $arMethodsMetaInfo[$methodName];
     $argsParsed = CTaskRestService::_parseRestParams('ctasklogitem', $methodName, $args);
     $returnValue = null;
     if (isset($arMethodMetaInfo['staticMethod']) && $arMethodMetaInfo['staticMethod']) {
         if ($methodName === 'list') {
             $taskId = $argsParsed[0];
             $order = $argsParsed[1];
             $filter = $argsParsed[2];
             $oTaskItem = CTaskItem::getInstance($taskId, $executiveUserId);
             list($items, $rsData) = self::fetchList($oTaskItem, $order, $filter);
             $returnValue = array();
             foreach ($items as $item) {
                 $returnValue[] = $item->getData(false);
             }
         } else {
             $returnValue = call_user_func_array(array('self', $methodName), $argsParsed);
         }
     } else {
         $taskId = array_shift($argsParsed);
         $itemId = array_shift($argsParsed);
         $oTaskItem = CTaskItem::getInstance($taskId, $executiveUserId);
         $item = new self($oTaskItem, $itemId);
         $returnValue = call_user_func_array(array($item, $methodName), $argsParsed);
     }
     return array($returnValue, null);
 }
예제 #2
0
 /**
  * This method is only for rest purposes
  * 
  * @access private
  */
 public static function runRestMethod($executiveUserId, $methodName, $args, $navigation)
 {
     static $arManifest = null;
     static $arMethodsMetaInfo = null;
     $rsData = null;
     if ($arManifest === null) {
         $arManifest = self::getManifest();
         $arMethodsMetaInfo = $arManifest['REST: available methods'];
     }
     // Check and parse params
     CTaskAssert::assert(isset($arMethodsMetaInfo[$methodName]));
     $arMethodMetaInfo = $arMethodsMetaInfo[$methodName];
     $argsParsed = CTaskRestService::_parseRestParams('ctaskitem', $methodName, $args);
     $runAs = $methodName;
     if (isset($arMethodsMetaInfo[$methodName]['runAs']) && (string) $arMethodsMetaInfo[$methodName]['runAs'] != '') {
         $runAs = $arMethodsMetaInfo[$methodName]['runAs'];
     }
     $returnValue = null;
     if (isset($arMethodMetaInfo['staticMethod']) && $arMethodMetaInfo['staticMethod']) {
         if ($methodName === 'add') {
             $argsParsed[] = $executiveUserId;
             /** @var CTaskItem $oTaskItem */
             $oTaskItem = call_user_func_array(array('self', $methodName), $argsParsed);
             $taskId = (int) $oTaskItem->getId();
             $returnValue = $taskId;
             self::cacheInstanceInPool($taskId, $executiveUserId, $oTaskItem);
         } elseif ($methodName === 'getlist' || $methodName === 'list') {
             array_unshift($argsParsed, $executiveUserId);
             // we need to fill default values up to $arParams (4th) argument
             while (!array_key_exists(3, $argsParsed)) {
                 $argsParsed[] = array();
             }
             if ($navigation['iNumPage'] > 1) {
                 $argsParsed[3]['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => (int) $navigation['iNumPage']);
             } else {
                 if (isset($argsParsed[3]['NAV_PARAMS'])) {
                     if (isset($argsParsed[3]['NAV_PARAMS']['nPageTop'])) {
                         $argsParsed[3]['NAV_PARAMS']['nPageTop'] = min(CTaskRestService::TASKS_LIMIT_TOP_COUNT, (int) $argsParsed[3]['NAV_PARAMS']['nPageTop']);
                     }
                     if (isset($argsParsed[3]['NAV_PARAMS']['nPageSize'])) {
                         $argsParsed[3]['NAV_PARAMS']['nPageSize'] = min(CTaskRestService::TASKS_LIMIT_PAGE_SIZE, (int) $argsParsed[3]['NAV_PARAMS']['nPageSize']);
                     }
                     if (!isset($argsParsed[3]['NAV_PARAMS']['nPageTop']) && !isset($argsParsed[3]['NAV_PARAMS']['nPageSize'])) {
                         $argsParsed[3]['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => 1);
                     }
                 } else {
                     $argsParsed[3]['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => 1);
                 }
             }
             /** @var CTaskItem[] $oTaskItems */
             /** @noinspection PhpUnusedLocalVariableInspection */
             list($oTaskItems, $rsData) = call_user_func_array(array('self', 'fetchList'), $argsParsed);
             $returnValue = array();
             foreach ($oTaskItems as $oTaskItem) {
                 $arTaskData = $oTaskItem->getData(false);
                 $arTaskData['ALLOWED_ACTIONS'] = $oTaskItem->getAllowedActionsAsStrings();
                 if (isset($argsParsed[3])) {
                     if (isset($argsParsed[3]['LOAD_TAGS']) && ($argsParsed[3]['LOAD_TAGS'] == 1 || $argsParsed[3]['LOAD_TAGS'] == 'Y')) {
                         $arTaskData['TAGS'] = $oTaskItem->getTags();
                     }
                 }
                 $returnValue[] = $arTaskData;
             }
         } else {
             $returnValue = call_user_func_array(array('self', $runAs), $argsParsed);
         }
     } else {
         $taskId = array_shift($argsParsed);
         $oTask = self::getInstanceFromPool($taskId, $executiveUserId);
         $returnValue = call_user_func_array(array($oTask, $runAs), $argsParsed);
     }
     return array($returnValue, $rsData);
 }
예제 #3
0
 /**
  * @deprecated
  */
 public static function runRestMethod($executiveUserId, $methodName, $args, $navigation)
 {
     static $arManifest = null;
     static $arMethodsMetaInfo = null;
     if ($arManifest === null) {
         $arManifest = self::getManifest();
         $arMethodsMetaInfo = $arManifest['REST: available methods'];
     }
     // Check and parse params
     CTaskAssert::assert(isset($arMethodsMetaInfo[$methodName]));
     $arMethodMetaInfo = $arMethodsMetaInfo[$methodName];
     $argsParsed = CTaskRestService::_parseRestParams('ctaskcomments', $methodName, $args);
     $returnValue = null;
     if (isset($arMethodMetaInfo['staticMethod']) && $arMethodMetaInfo['staticMethod']) {
         if ($methodName === 'add') {
             $occurAsUserId = CTasksTools::getOccurAsUserId();
             if (!$occurAsUserId) {
                 $occurAsUserId = $executiveUserId;
             }
             $taskId = $argsParsed[0];
             $commentText = $argsParsed[1];
             $commentAuthorId = $occurAsUserId;
             $returnValue = self::add($taskId, $commentAuthorId, $commentText);
         }
     } else {
         $taskId = array_shift($argsParsed);
         $oTask = self::getInstanceFromPool($taskId, $executiveUserId);
         $returnValue = call_user_func_array(array($oTask, $methodName), $argsParsed);
     }
     return array($returnValue, null);
 }
예제 #4
0
 public static function runRestMethod($executiveUserId, $methodName, $args, $navigation)
 {
     CTaskAssert::assert($methodName === 'getcurrenttaskslist');
     // Check and parse params
     $argsParsed = CTaskRestService::_parseRestParams('ctaskplannermaintance', $methodName, $args);
     $arTasksIds = call_user_func_array(array('self', 'getcurrenttaskslist'), $argsParsed);
     return array($arTasksIds, null);
 }
예제 #5
0
 public static function runRestMethod($executiveUserId, $methodName, $args, $navigation)
 {
     CTaskAssert::assert($methodName === 'getlist');
     // Force & limit NAV_PARAMS (in 4th argument)
     while (count($args) < 4) {
         $args[] = array();
     }
     // All params in CTasks::GetList() by default are empty arrays
     $arParams =& $args[3];
     if ($navigation['iNumPage'] > 1) {
         $arParams['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => (int) $navigation['iNumPage']);
     } else {
         if (isset($arParams['NAV_PARAMS'])) {
             if (isset($arParams['NAV_PARAMS']['nPageTop'])) {
                 $arParams['NAV_PARAMS']['nPageTop'] = min(CTaskRestService::TASKS_LIMIT_TOP_COUNT, (int) $arParams['NAV_PARAMS']['nPageTop']);
             }
             if (isset($arParams['NAV_PARAMS']['nPageSize'])) {
                 $arParams['NAV_PARAMS']['nPageSize'] = min(CTaskRestService::TASKS_LIMIT_PAGE_SIZE, (int) $arParams['NAV_PARAMS']['nPageSize']);
             }
             if (!isset($arParams['NAV_PARAMS']['nPageTop']) && !isset($arParams['NAV_PARAMS']['nPageSize'])) {
                 $arParams['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => 1);
             }
         } else {
             $arParams['NAV_PARAMS'] = array('nPageSize' => CTaskRestService::TASKS_LIMIT_PAGE_SIZE, 'iNumPage' => 1);
         }
     }
     // Check and parse params
     $argsParsed = CTaskRestService::_parseRestParams('ctasks', $methodName, $args);
     $arParams['USER_ID'] = $executiveUserId;
     // TODO: remove this hack (needs for select tasks with GROUP_ID === NULL or 0)
     if (isset($argsParsed[1])) {
         $arFilter = $argsParsed[1];
         foreach ($arFilter as $key => $value) {
             if ($key === 'GROUP_ID' && $value == 0) {
                 $argsParsed[1]['META:GROUP_ID_IS_NULL_OR_ZERO'] = 1;
                 unset($argsParsed[1][$key]);
                 break;
             }
         }
         if (isset($argsParsed[1]['ID']) && is_array($argsParsed[1]['ID']) && empty($argsParsed[1]['ID'])) {
             $argsParsed[1]['ID'] = -1;
         }
     }
     $rsTasks = call_user_func_array(array('self', 'getlist'), $argsParsed);
     $arTasks = array();
     while ($arTask = $rsTasks->fetch()) {
         $arTasks[] = $arTask;
     }
     return array($arTasks, $rsTasks);
 }
예제 #6
0
 private static function _init()
 {
     self::$arAllowedMethods = array();
     foreach (self::$arAllowedClasses as $className) {
         $arManifest = $className::getManifest();
         self::$arAllowedMethods[$className] = array_map('strtolower', array_keys($arManifest['REST: available methods']));
         self::$arMethodsMetaInfo[$className] = $arManifest['REST: available methods'];
         if (isset($arManifest['REST: shortname alias to class'])) {
             $aliasClassName = $arManifest['REST: shortname alias to class'];
             self::$arClassAliases[$className] = $aliasClassName;
         }
         self::$arManifests[$className] = $arManifest;
         // refactor this translation later when add userfields to other entites
         $classNameCut = $namespace = $className;
         if ($className == 'ctaskitem') {
             $classNameCut = 'item';
             $namespace = 'task';
         }
         $specialClasses = array('\\Bitrix\\Tasks\\Integration\\Rest\\' . ucfirst($namespace) . '\\UserField');
         foreach ($specialClasses as $sClassName) {
             if (class_exists($sClassName)) {
                 self::$allowedSpecialClasses[$sClassName] = array('publicClassName' => $sClassName::getClassName(), 'publicParentClassName' => $classNameCut);
                 foreach ($sClassName::getAvailableMethods() as $method) {
                     self::$arMethodsMetaInfo[$sClassName][$method] = array();
                 }
             }
         }
     }
     self::$inited = true;
 }
예제 #7
0
 private static function _init()
 {
     self::$arAllowedMethods = array();
     foreach (self::$arAllowedClasses as $className) {
         $arManifest = $className::getManifest();
         self::$arAllowedMethods[$className] = array_map('strtolower', array_keys($arManifest['REST: available methods']));
         self::$arMethodsMetaInfo[$className] = $arManifest['REST: available methods'];
         if (isset($arManifest['REST: shortname alias to class'])) {
             $aliasClassName = $arManifest['REST: shortname alias to class'];
             self::$arClassAliases[$className] = $aliasClassName;
         }
         self::$arManifests[$className] = $arManifest;
     }
     self::$inited = true;
 }