本文整理汇总了PHP中ActiveRecordModel::getInstanceArray方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecordModel::getInstanceArray方法的具体用法?PHP ActiveRecordModel::getInstanceArray怎么用?PHP ActiveRecordModel::getInstanceArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecordModel
的用法示例。
在下文中一共展示了ActiveRecordModel::getInstanceArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unserialize
public function unserialize($serialized)
{
parent::unserialize($serialized);
// load products
$productIds = array();
foreach ($this->orderedItems as $item) {
$productIds[] = $item->getProduct()->getID();
}
$products = ActiveRecordModel::getInstanceArray('Product', $productIds, Product::LOAD_REFERENCES);
// load product prices
$set = new ARSet();
foreach ($products as $product) {
$set->add($product);
}
ProductPrice::loadPricesForRecordSet($set);
}
示例2: loadSpecificationData
protected function loadSpecificationData($specificationDataArray)
{
if (!is_array($specificationDataArray)) {
$specificationDataArray = array();
}
// get value class and field names
$fieldClass = $this->getFieldClass();
$fieldColumn = call_user_func(array($fieldClass, 'getFieldIDColumnName'));
$valueItemClass = call_user_func(array($fieldClass, 'getSelectValueClass'));
$valueClass = call_user_func(array($valueItemClass, 'getValueClass'));
$multiValueItemClass = call_user_func(array($fieldClass, 'getMultiSelectValueClass'));
// preload all specFields from database
$specFieldIds = array();
$selectors = array();
$simpleValues = array();
foreach ($specificationDataArray as $value) {
$specFieldIds[$value[$fieldColumn]] = $value[$fieldColumn];
if ($value['valueID']) {
$selectors[$value[$fieldColumn]][$value['valueID']] = $value;
} else {
$simpleValues[$value[$fieldColumn]] = $value;
}
}
$specFields = ActiveRecordModel::getInstanceArray($fieldClass, $specFieldIds);
// simple values
foreach ($simpleValues as $value) {
$specField = $specFields[$value[$fieldColumn]];
$class = $specField->getValueTableName();
// temporarly fix for Eav selectors parse as string values
//TODO: fix Eav selectors
if ($class == "EavItem") {
switch ($specField->type->get()) {
case EavFieldCommon::TYPE_NUMBERS_SELECTOR:
// $class == "EavNumericValue";
// $class == "EavNumericValue";
case EavFieldCommon::TYPE_TEXT_SELECTOR:
$class = "EavStringValue";
}
}
$specification = call_user_func_array(array($class, 'restoreInstance'), array($this->owner, $specField, $value['value']));
$this->attributes[$specField->getID()] = $specification;
}
// selectors
foreach ($selectors as $specFieldId => $value) {
if (!isset($specFields[$specFieldId])) {
continue;
}
$specField = $specFields[$specFieldId];
if ($specField->isMultiValue->get()) {
$values = array();
foreach ($value as $val) {
$values[$val['valueID']] = $val['value'];
}
$specification = call_user_func_array(array($multiValueItemClass, 'restoreInstance'), array($this->owner, $specField, $values));
} else {
$value = array_pop($value);
$specFieldValue = call_user_func_array(array($valueClass, 'restoreInstance'), array($specField, $value['valueID'], $value['value']));
$specification = call_user_func_array(array($valueItemClass, 'restoreInstance'), array($this->owner, $specField, $specFieldValue));
}
$this->attributes[$specField->getID()] = $specification;
}
}
示例3: loadSpecificationData
protected function loadSpecificationData($specificationDataArray)
{
if (!is_array($specificationDataArray)) {
$specificationDataArray = array();
}
// get value class and field names
$fieldClass = $this->getFieldClass();
$fieldColumn = call_user_func(array($fieldClass, 'getFieldIDColumnName'));
$valueItemClass = call_user_func(array($fieldClass, 'getSelectValueClass'));
$valueClass = call_user_func(array($valueItemClass, 'getValueClass'));
$multiValueItemClass = call_user_func(array($fieldClass, 'getMultiSelectValueClass'));
// preload all specFields from database
$specFieldIds = array();
$selectors = array();
$simpleValues = array();
foreach ($specificationDataArray as $value) {
$specFieldIds[$value[$fieldColumn]] = $value[$fieldColumn];
if ($value['valueID']) {
$selectors[$value[$fieldColumn]][$value['valueID']] = $value;
} else {
$simpleValues[$value[$fieldColumn]] = $value;
}
}
$specFields = ActiveRecordModel::getInstanceArray($fieldClass, $specFieldIds);
// simple values
foreach ($simpleValues as $value) {
$specField = $specFields[$value[$fieldColumn]];
$class = $specField->getValueTableName();
$specification = call_user_func_array(array($class, 'restoreInstance'), array($this->owner, $specField, $value['value']));
$this->attributes[$specField->getID()] = $specification;
}
// selectors
foreach ($selectors as $specFieldId => $value) {
if (!isset($specFields[$specFieldId])) {
continue;
}
$specField = $specFields[$specFieldId];
if ($specField->isMultiValue->get()) {
$values = array();
foreach ($value as $val) {
$values[$val['valueID']] = $val['value'];
}
$specification = call_user_func_array(array($multiValueItemClass, 'restoreInstance'), array($this->owner, $specField, $values));
} else {
$value = array_pop($value);
$specFieldValue = call_user_func_array(array($valueClass, 'restoreInstance'), array($specField, $value['valueID'], $value['value']));
$specification = call_user_func_array(array($valueItemClass, 'restoreInstance'), array($this->owner, $specField, $specFieldValue));
}
$this->attributes[$specField->getID()] = $specification;
}
}