コード例 #1
0
ファイル: baseobject.php プロジェクト: DarneoStudio/bitrix
 /**
  * Gets fields which Externalizer or Internalizer should modify.
  * @return array
  */
 public function getFieldsForMap()
 {
     return array('TYPE' => array('IN' => function ($externalValue) {
         switch ($externalValue) {
             case 'folder':
                 return ObjectTable::TYPE_FOLDER;
             case 'file':
                 return ObjectTable::TYPE_FILE;
         }
         return null;
     }, 'OUT' => function ($internalValue) {
         switch ($internalValue) {
             case ObjectTable::TYPE_FOLDER:
                 return 'folder';
             case ObjectTable::TYPE_FILE:
                 return 'file';
         }
         return null;
     }), 'CREATE_TIME' => array('IN' => function ($externalValue) {
         return \CRestUtil::unConvertDateTime($externalValue);
     }, 'OUT' => function (DateTime $internalValue = null) {
         return \CRestUtil::convertDateTime($internalValue);
     }), 'UPDATE_TIME' => array('IN' => function ($externalValue) {
         return \CRestUtil::unConvertDateTime($externalValue);
     }, 'OUT' => function (DateTime $internalValue = null) {
         return \CRestUtil::convertDateTime($internalValue);
     }), 'DELETE_TIME' => array('IN' => function ($externalValue) {
         return \CRestUtil::unConvertDateTime($externalValue);
     }, 'OUT' => function (DateTime $internalValue = null) {
         return \CRestUtil::convertDateTime($internalValue);
     }));
 }
コード例 #2
0
ファイル: externallink.php プロジェクト: DarneoStudio/bitrix
 /**
  * Gets fields which Externalizer or Internalizer should modify.
  * @return array
  */
 public function getFieldsForMap()
 {
     return array('CREATE_TIME' => array('IN' => function ($externalValue) {
         return \CRestUtil::unConvertDateTime($externalValue);
     }, 'OUT' => function (DateTime $internalValue = null) {
         return \CRestUtil::convertDateTime($internalValue);
     }));
 }
コード例 #3
0
 /**
  * Gets fields which Externalizer or Internalizer should modify.
  * @return array
  */
 public function getFieldsForMap()
 {
     return array('CREATE_TIME' => array('IN' => function ($externalValue) {
         return \CRestUtil::unConvertDateTime($externalValue);
     }, 'OUT' => function (DateTime $internalValue = null) {
         return \CRestUtil::convertDateTime($internalValue);
     }), 'ENTITY_TYPE' => array('IN' => function ($externalValue) {
         switch ($externalValue) {
             case 'blog_comment':
                 return BlogPostCommentConnector::className();
             case 'blog_post':
                 return BlogPostConnector::className();
             case 'calendar_event':
                 return CalendarEventConnector::className();
             case 'forum_message':
                 return ForumMessageConnector::className();
             case 'tasks_task':
                 return TaskConnector::className();
             case 'sonet_log':
                 return SonetLogConnector::className();
             case 'sonet_comment':
                 return SonetCommentConnector::className();
         }
         return null;
     }, 'OUT' => function ($internalValue) {
         switch ($internalValue) {
             case BlogPostCommentConnector::className():
                 return 'blog_comment';
             case BlogPostConnector::className():
                 return 'blog_post';
             case CalendarEventConnector::className():
                 return 'calendar_event';
             case ForumMessageConnector::className():
                 return 'forum_message';
             case TaskConnector::className():
                 return 'tasks_task';
             case SonetLogConnector::className():
                 return 'sonet_log';
             case SonetCommentConnector::className():
                 return 'sonet_comment';
         }
         return null;
     }));
 }
コード例 #4
0
ファイル: rest.php プロジェクト: ASDAFF/bxApiDocs
	private static function checkGroupFilter($arFilter)
	{

		if(!is_array($arFilter))
		{
			$arFilter = array();
		}
		else
		{
			foreach ($arFilter as $key => $value)
			{
				if(preg_match('/^([^a-zA-Z]*)(.*)/', $key, $matches))
				{
					$operation = $matches[1];
					$field = $matches[2];

					if(!in_array($operation, self::$arAllowedOperations))
					{
						unset($arFilter[$key]);
					}
					else
					{
						switch($field)
						{
							case 'DATE_CREATE':
							case 'DATE_ACTIVITY':
							case 'DATE_UPDATE':
								$arFilter[$key] = CRestUtil::unConvertDateTime($value);
							break;

							case 'CHECK_PERMISSIONS':
								unset($arFilter[$key]);
							break;

							default:
							break;
						}
					}
				}
			}
		}

		return $arFilter;
	}
コード例 #5
0
ファイル: restservice.php プロジェクト: mrdeadmouse/u136006
 protected function internalizeFilterFields(&$filter, &$fieldsInfo)
 {
     if (!is_array($filter)) {
         return;
     }
     foreach ($filter as $k => $v) {
         $operationInfo = CSqlUtil::GetFilterOperation($k);
         $fieldName = $operationInfo['FIELD'];
         $info = isset($fieldsInfo[$fieldName]) ? $fieldsInfo[$fieldName] : null;
         if (!$info) {
             unset($filter[$k]);
             continue;
         }
         $fieldType = isset($info['TYPE']) ? $info['TYPE'] : '';
         if ($fieldType === 'datetime') {
             $filter[$k] = CRestUtil::unConvertDateTime($v);
         }
     }
     CCrmEntityHelper::PrepareMultiFieldFilter($filter);
 }
コード例 #6
0
ファイル: restservice.php プロジェクト: DarneoStudio/bitrix
 /**
  * This function is for internal use only, not a part of public API
  *
  * @access private
  */
 public static function _parseRestParams($className, $methodName, $inArgs)
 {
     CTaskAssert::assert(is_array($inArgs) && isset(self::$arMethodsMetaInfo[$className][$methodName]));
     $arMethodMetaInfo = self::$arMethodsMetaInfo[$className][$methodName];
     $arAllowedParams = $arMethodMetaInfo['params'];
     $mandatoryParamsCount = $arMethodMetaInfo['mandatoryParamsCount'];
     $arDateFields = array();
     if (isset(self::$arManifests[$className]['REST: date fields'])) {
         $arDateFields = self::$arManifests[$className]['REST: date fields'];
     }
     $outArgs = array();
     foreach ($arAllowedParams as $paramIndex => $paramMetaInfo) {
         // No more params given?
         if (!array_key_exists($paramIndex, $inArgs)) {
             // Set default value, if need
             if (array_key_exists('defaultValue', $paramMetaInfo)) {
                 $inArgs[$paramIndex] = $paramMetaInfo['defaultValue'];
             } elseif ($paramIndex < $mandatoryParamsCount) {
                 throw new TasksException('Param #' . $paramIndex . ' (' . $paramMetaInfo['description'] . ')' . ' expected by method ' . $className . '::' . $methodName . '(), but not given.', TasksException::TE_WRONG_ARGUMENTS);
             } else {
                 break;
             }
             // no more params to be processed
         }
         // for "galvanic isolation" of input/output
         $paramValue = $inArgs[$paramIndex];
         // Check param type
         /** @noinspection PhpUnusedLocalVariableInspection */
         $isCorrectValue = false;
         switch ($paramMetaInfo['type']) {
             case 'boolean':
                 if ($paramValue === '0' || $paramValue === 0) {
                     $paramValue = false;
                 } elseif ($paramValue === '1' || $paramValue === 1) {
                     $paramValue = true;
                 }
                 $isCorrectValue = is_bool($paramValue);
                 break;
             case 'array':
                 $isCorrectValue = is_array($paramValue);
                 break;
             case 'string':
                 $isCorrectValue = is_string($paramValue);
                 break;
             case 'integer':
                 $isCorrectValue = CTaskAssert::isLaxIntegers($paramValue);
                 break;
             default:
                 throw new TasksException('Internal error: unknown param type: ' . $paramMetaInfo['type'], TasksException::TE_UNKNOWN_ERROR);
                 break;
         }
         if (!$isCorrectValue) {
             throw new TasksException('Param #' . $paramIndex . ' (' . $paramMetaInfo['description'] . ')' . ' for method ' . $className . '::' . $methodName . '()' . ' expected to be of type "' . $paramMetaInfo['type'] . '",' . ' but given something else.', TasksException::TE_WRONG_ARGUMENTS);
         }
         // add legal aggregated columns in keys & values array
         if (is_array($paramMetaInfo['allowedAggregations'])) {
             // for keys
             if (is_array($paramMetaInfo['allowedKeysInAggregation'])) {
                 $fields = $paramMetaInfo['allowedKeysInAggregation'];
             } else {
                 $fields = $paramMetaInfo['allowedKeys'];
             }
             if (is_array($fields)) {
                 $aggrCombos = static::getAllowedAggregateCombos($paramMetaInfo['allowedAggregations'], $fields);
                 $paramMetaInfo['allowedKeys'] = array_merge($paramMetaInfo['allowedKeys'], $aggrCombos);
             }
             // for values
             if (is_array($paramMetaInfo['allowedValuesInAggregation'])) {
                 $fields = $paramMetaInfo['allowedValuesInAggregation'];
             } else {
                 $fields = $paramMetaInfo['allowedValues'];
             }
             if (is_array($fields)) {
                 $aggrCombos = static::getAllowedAggregateCombos($paramMetaInfo['allowedAggregations'], $fields);
                 $paramMetaInfo['allowedValues'] = array_merge($paramMetaInfo['allowedValues'], $aggrCombos);
             }
         }
         if (isset($paramMetaInfo['allowedKeys'])) {
             CTaskAssert::assert(is_array($paramValue));
             // ensure that $paramValue is array
             /** @var $paramValue array */
             foreach (array_keys($paramValue) as $key) {
                 // a little fix to be able to pass an empty array in order to "skip" argument
                 if ((string) $key == '0' && $paramValue[$key] == '') {
                     unset($paramValue[$key]);
                     continue;
                 }
                 if (isset($paramMetaInfo['allowedKeyPrefixes'])) {
                     $keyWoPrefix = str_replace($paramMetaInfo['allowedKeyPrefixes'], '', $key);
                 } else {
                     $keyWoPrefix = $key;
                 }
                 if (!in_array((string) $keyWoPrefix, $paramMetaInfo['allowedKeys'], true)) {
                     throw new TasksException('Param #' . $paramIndex . ' (' . $paramMetaInfo['description'] . ')' . ' for method ' . $className . '::' . $methodName . '()' . ' must not contain key "' . $key . '".', TasksException::TE_WRONG_ARGUMENTS);
                 }
                 // Additionally convert datetime fields from ISO 8601
                 if (in_array((string) $keyWoPrefix, $arDateFields, true) && !in_array($paramValue[$key], array('asc', 'desc'))) {
                     $paramValue[$key] = (string) CRestUtil::unConvertDateTime($paramValue[$key]);
                 }
             }
         }
         if (isset($paramMetaInfo['allowedValues'])) {
             CTaskAssert::assert(is_array($paramValue));
             foreach ($paramValue as $value) {
                 if ($value !== null && !is_bool($value)) {
                     $value = (string) $value;
                 }
                 if (!in_array($value, $paramMetaInfo['allowedValues'], true)) {
                     throw new TasksException('Param #' . $paramIndex . ' (' . $paramMetaInfo['description'] . ')' . ' for method ' . $className . '::' . $methodName . '()' . ' must not contain value "' . $value . '".', TasksException::TE_WRONG_ARGUMENTS);
                 }
             }
         }
         // "galvanic isolation" of input/output
         $outArgs[] = $paramValue;
     }
     if (count($inArgs) > count($arAllowedParams)) {
         throw new TasksException('Too much params(' . count($inArgs) . ') given for method ' . $className . '::' . $methodName . '()' . ', but expected not more than ' . count($arAllowedParams) . '.', TasksException::TE_WRONG_ARGUMENTS);
     }
     return $outArgs;
 }
コード例 #7
0
ファイル: vi_rest.php プロジェクト: DarneoStudio/bitrix
 public static function statisticGet($arParams, $nav, $server)
 {
     $arParams = array_change_key_case($arParams, CASE_UPPER);
     $sort = $arParams['SORT'];
     $order = $arParams['ORDER'];
     if (isset($arParams['FILTER']) && is_array($arParams['FILTER'])) {
         $arFilter = array_change_key_case($arParams['FILTER'], CASE_UPPER);
         if (isset($arFilter['CALL_START_DATE'])) {
             $arFilter['CALL_START_DATE'] = CRestUtil::unConvertDateTime($arFilter['CALL_START_DATE']);
         }
         if (isset($arFilter['CALL_TYPE'])) {
             $arFilter['INCOMING'] = $arFilter['CALL_TYPE'];
             unset($arFilter['CALL_TYPE']);
         }
     } else {
         $arFilter = array();
     }
     if (!CVoxImplantMain::CheckAccess()) {
         $arFilter['PORTAL_USER_ID'] = $GLOBALS['USER']->GetID();
     }
     $arReturn = array();
     $dbResCnt = \Bitrix\Voximplant\StatisticTable::getList(array('filter' => $arFilter, 'select' => array("CNT" => new Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(1)'))));
     $arResCnt = $dbResCnt->fetch();
     if ($arResCnt && $arResCnt["CNT"] > 0) {
         $arNavParams = self::getNavData($nav, true);
         $arSort = array();
         if ($sort && $order) {
             $arSort[$sort] = $order;
         }
         $dbRes = \Bitrix\Voximplant\StatisticTable::getList(array('order' => $arSort, 'filter' => $arFilter, 'limit' => $arNavParams['limit'], 'offset' => $arNavParams['offset']));
         $result = array();
         while ($arData = $dbRes->fetch()) {
             unset($arData['ACCOUNT_ID']);
             unset($arData['APPLICATION_ID']);
             unset($arData['APPLICATION_NAME']);
             unset($arData['CALL_LOG']);
             unset($arData['CALL_RECORD_ID']);
             unset($arData['CALL_WEBDAV_ID']);
             unset($arData['CALL_STATUS']);
             unset($arData['CALL_DIRECTION']);
             $arData['CALL_TYPE'] = $arData['INCOMING'];
             unset($arData['INCOMING']);
             $arData['CALL_START_DATE'] = CRestUtil::ConvertDateTime($arData['CALL_START_DATE']);
             $result[] = $arData;
         }
         return self::setNavData($result, array("count" => $arResCnt['CNT'], "offset" => $arNavParams['offset']));
     }
     return $arReturn;
 }
コード例 #8
0
 private static function prepareFilter($arFilter)
 {
     if (!is_array($arFilter)) {
         $arFilter = array();
     } else {
         $fieldsInfo = self::getFieldsInfo();
         $arAllowedFilterFields = array();
         foreach ($fieldsInfo as $fieldName => $fieldInfo) {
             if ($fieldInfo['filter'] === true) {
                 $arAllowedFilterFields[] = $fieldName;
             }
         }
         if (count($arFilter) > 0) {
             $arFilter = array_change_key_case($arFilter, CASE_UPPER);
             foreach ($arFilter as $key => $value) {
                 $matches = array();
                 if (preg_match('/^([^a-zA-Z]*)(.*)/', $key, $matches)) {
                     $operation = $matches[1];
                     $field = $matches[2];
                     if (!in_array($field, $arAllowedFilterFields, true) || !in_array($operation, self::$arAllowedFilterOperations, true)) {
                         unset($arFilter[$key]);
                     } else {
                         switch ($fieldsInfo[$field]['type']) {
                             case 'datetime':
                                 $arFilter[$key] = CRestUtil::unConvertDateTime($value);
                                 break;
                             case 'date':
                                 $arFilter[$key] = CRestUtil::unConvertDate($value);
                                 break;
                             default:
                                 break;
                         }
                     }
                 } else {
                     unset($arFilter[$key]);
                 }
             }
         }
     }
     return $arFilter;
 }
コード例 #9
0
ファイル: restservice.php プロジェクト: DarneoStudio/bitrix
 protected function internalizeFilterFields(&$filter, &$fieldsInfo)
 {
     if (!is_array($filter)) {
         return;
     }
     foreach ($filter as $k => $v) {
         $operationInfo = CSqlUtil::GetFilterOperation($k);
         $fieldName = $operationInfo['FIELD'];
         $info = isset($fieldsInfo[$fieldName]) ? $fieldsInfo[$fieldName] : null;
         if (!$info) {
             unset($filter[$k]);
             continue;
         }
         $operation = substr($k, 0, strlen($k) - strlen($fieldName));
         if (isset($info['FORBIDDEN_FILTERS']) && is_array($info['FORBIDDEN_FILTERS']) && in_array($operation, $info['FORBIDDEN_FILTERS'], true)) {
             unset($filter[$k]);
             continue;
         }
         $fieldType = isset($info['TYPE']) ? $info['TYPE'] : '';
         if (($fieldType === 'crm_status' || $fieldType === 'crm_company' || $fieldType === 'crm_contact') && ($operation === '%' || $operation === '%=' || $operation === '=%')) {
             //Prevent filtration by LIKE due to performance considerations
             $filter["={$fieldName}"] = $v;
             unset($filter[$k]);
             continue;
         }
         if ($fieldType === 'datetime') {
             $filter[$k] = CRestUtil::unConvertDateTime($v);
         } elseif ($fieldType === 'date') {
             $filter[$k] = CRestUtil::unConvertDate($v);
         }
     }
     CCrmEntityHelper::PrepareMultiFieldFilter($filter, array(), '=%', true);
 }