90 public static function getById($id)
93 $compatibility =
new static();
94 return static::setGetListParameters($compatibility);
108 $compatibility =
new static();
156 if (!empty($callback))
161 return $compatibility->execute();
179 $aliasFields = static::getAliasFields();
180 foreach(
$filter as $fieldName => $fieldValue)
182 $fieldName = mb_strtoupper($fieldName);
183 $filterMatch = $this->query->explodeFilterKey($fieldName);
184 $fieldClearName = $filterMatch[
'alias'];
188 if (isset($aliasFields[$fieldClearName]))
190 $this->
addQueryAlias($fieldClearName, $aliasFields[$fieldClearName]);
194 if ($propKey = $this->
parseField($fieldClearName))
196 $this->
addFilter($filterMatch[
'modifier'].$filterMatch[
'operator'].$propKey, $fieldValue);
205 $aliasFieldsValue = $aliasFields[$fieldClearName] ??
null;
206 if (!is_array($aliasFieldsValue))
208 $this->
addFilter($fieldName, $fieldValue);
224 $aliasFields = static::getAliasFields();
227 $select = static::getSelectFields();
232 if ($fieldName ==
"*")
244 $fieldName = mb_strtoupper($fieldName);
247 if (isset($aliasFields[$fieldName]))
259 $aliasFieldsValue = $aliasFields[$fieldName] ??
null;
260 if (!is_array($aliasFieldsValue))
296 foreach(
$group as $fieldName => $fieldValue)
300 $this->group[$propKey] = $fieldValue;
304 $this->group[$fieldName] = $fieldValue;
316 foreach(
$sort as $fieldName => $fieldValue)
318 $fieldName = mb_strtoupper($fieldName);
321 $this->sort[$propKey] = $fieldValue;
325 $this->sort[$fieldName] = $fieldValue;
343 if (($sql = call_user_func_array($callback,
array())) && strval(trim($sql)) !=
'')
345 $this->query->registerRuntimeField(
349 '(CASE WHEN ('.$sql.
') THEN 1 ELSE 0 END)'
352 $this->query->addFilter(
'=__CALLBACK', 1);
363 if (isset($this->filter[
$name]))
366 $this->filter[
$name] = $value;
379 $match = $this->query->explodeFilterKey(
$name);
380 $rule = ($match[
'modifier']? $match[
'modifier']:
"").($match[
'operator']? $match[
'operator']:
"");
383 foreach ($aliasList as $fieldName => $fieldValue)
385 $filterName = $rule.$fieldName;
386 $logic[] =
array($filterName => $value);
391 $logic[
'LOGIC'] =
'OR';
392 $this->query->addFilter(
null, $logic);
418 foreach ($aliasList as $fieldName => $fieldValue)
441 if (!empty($value) && is_array($value))
447 $list[
$name] = $value;
450 foreach ($list as $fieldName => $fieldValue)
452 if (in_array($fieldName, $this->queryAliasList))
457 $this->queryAliasList[] = $fieldName;
458 $this->query->addAlias($fieldName, $fieldValue);
470 if ($this->queryAliasList ===
null)
472 $this->queryAliasList = array_keys($this->query->getAliases());
481 public function execute()
485 $this->query->prepare($this->sort, $this->filter, $this->group, $this->
select);
486 if ($this->query->counted())
488 return $this->query->exec()->getSelectedRowsCount();
491 return $this->query->compatibleExec(
$result, $this->nav);
501 return $this->fields->get(
$name);
510 $this->fields->set(
$name, $value);
518 return $this->fields->getValues();
526 $this->fields->resetValues($values);
539 if (empty($availableFields))
540 $availableFields = static::getAvailableFields();
542 foreach (
$fields as $fieldName => $fieldValue)
544 if (!in_array($fieldName, $availableFields))
564 $resultList =
array();
567 $resultList[
$k] = static::convertDateField(
$k, $value, $dateFields);
584 if (mb_substr(
$key, 0, 1) ==
'=')
589 if (!array_key_exists(
$key, $dateFields))
594 $nowDate = Application::getConnection()->getSqlHelper()->getCurrentDateTimeFunction();
597 && !($value instanceof
Date))
602 if (strval($value) ==
'')
608 if (mb_strtolower($value) != mb_strtolower($nowDate))
613 if (mb_strtoupper($dateFields[
$key]) ==
"DATE")
615 $value =
new Date($setValue);
617 elseif (mb_strtoupper($dateFields[
$key]) ==
"DATETIME")
634 $resultList =
array();
637 $valueString = static::convertDateFieldToOldFormat($value);
638 $resultList[
$k] = $valueString;
655 || ($value instanceof
Date))
657 $setValue = $value->toString();
676 || ($value instanceof
Date))
678 $phpFormat = $value->convertFormatToPhp($format);
679 $setValue = $value->format($phpFormat);
680 $setValue = str_replace(
" 00:00:00",
"", $setValue);
702 if (array_key_exists(
$name, $replace))
704 $replacedFields[$replace[
$name]] = $replacedFields[
$name];
705 unset($replacedFields[
$name]);
709 return $replacedFields;
730 return ($entityName == static::ENTITY_ORDER
731 || $entityName == static::ENTITY_PAYMENT
745 if (!static::checkEntityName($entityName))
750 if (empty($availableFields))
751 $availableFields = static::getAvailableFields();
755 $firstLetter = mb_substr(
$name, 0, 1);
756 if ($firstLetter ==
"~" || $firstLetter ==
"=")
758 $fieldName = ltrim(
$name,
'=');
759 $fieldName = ltrim($fieldName,
'~');
761 if (!in_array($fieldName, $availableFields))
764 $this->rawFields[$entityName][$firstLetter.$fieldName] = $value;
782 public function saveRawFields(
$entity, $entityName)
786 if (!static::checkEntityName($entityName))
791 if (empty($this->rawFields[$entityName]) || !is_array($this->rawFields[$entityName]))
795 if ($entityName == static::ENTITY_ORDER)
803 $tableName = static::ENTITY_ORDER_TABLE;
805 elseif ($entityName == static::ENTITY_PAYMENT)
810 throw new ObjectNotFoundException(
'Entity "Payment" not found');
812 $tableName = static::ENTITY_PAYMENT_TABLE;
817 throw new ArgumentNullException(
'id');
820 if (strval(trim($tableName)) ==
'')
822 throw new ArgumentNullException(
'tableName');
827 $queryValue =
$DB->PrepareUpdate($tableName, $this->rawFields[$entityName]);
829 foreach ($this->rawFields[$entityName] as
$key => $value)
831 if (mb_substr(
$key, 0, 1) !=
"=")
834 if (strval($queryValue) !=
'')
837 $queryValue .= mb_substr(
$key, 1).
"=".
$value.
" ";
841 "UPDATE ".$tableName.
" SET ".
842 " ".$queryValue.
" WHERE ID = ".
$entity->getId().
" ";
844 if (!(
$DB->Query($sql,
true)))
846 $result->addError(
new Sale\ResultError(Loc::getMessage(
'SALE_COMPATIBLE_'.$entityName.
'_RAW_FIELD_UPDATE_ERROR'),
'SALE_'.$entityName.
'_COMPATIBLE_RAW_FIELD_UPDATE_ERROR'));
863 if (!static::checkEntityName($entityName))
873 $fields[$separator.$name] = $value;
896 if (in_array($fieldName,
$fields))
899 if (mb_strpos($fieldName,
'UF_') === 0)
static convertDateField($name, $value, array $dateFields=array())
static backRawField($entityName, array $fields, $separator='=')
setSelect(array $select=array())
checkWhiteListFields($fieldName)
addSelectForAlias(array $aliasList)
setNav(array $nav=array())
const ENTITY_PAYMENT_TABLE
static setGetListParameters(EntityCompatibility $compatibility, $sort=array(), $filter=array(), $group=null, $nav=array(), $select=array(), $callback=false)
setCallback(array $callback)
setFilter(array $filter=array())
static convertDateFieldsToOldFormat(array $fields)
static clearFields(array $fields, array $availableFields=array())
addQueryAlias($name, $value=null)
static replaceFields(array $fields, array $replace=array())
static convertDateFields(array $fields, array $dateFields=array())
static getAvailableFields()
__construct(array $fields=array())
addFilterForAlias(array $aliasList, $name, $value)
parseRawFields($entityName, array $fields, array $availableFields=array())
static getList($sort=array(), $filter=array(), $group=null, $nav=array(), $select=array(), $callback=false)
static checkEntityName($entityName)
static add(array $fields)
static convertDateFieldToOldFormat($value)
setSort(array $sort=array())
static convertDateFieldToFormat($value, $format)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key