本文整理汇总了PHP中ActiveRecordModel::getSchemaInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecordModel::getSchemaInstance方法的具体用法?PHP ActiveRecordModel::getSchemaInstance怎么用?PHP ActiveRecordModel::getSchemaInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecordModel
的用法示例。
在下文中一共展示了ActiveRecordModel::getSchemaInstance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadRequest
public function loadRequest($loadData = true)
{
$request = $this->getApplication()->getRequest();
$cn = $request->get(ApiReader::API_PARSER_CLASS_NAME);
if ($cn == null || class_exists($cn) == false) {
throw new Exception('Parser ' . $cn . ' not found');
}
$modelFields = $modelFieldNames = array();
if ($this->className) {
$modelFields = ActiveRecordModel::getSchemaInstance($this->className)->getFieldList();
// $modelFieldNames - $ignoreFieldNames
$modelFieldNames = array_diff(array_keys($modelFields), is_array($this->ignoreFieldNames) ? $this->ignoreFieldNames : array($this->ignoreFieldNames));
}
$this->setParserClassName($cn);
$this->setParser(new $cn($request->get(ApiReader::API_PARSER_DATA), $modelFieldNames));
// read and put data from api request format (that could be wahatever custom parser can read) in Requst object as key=>value pairs.
if ($loadData) {
$this->getParser()->loadDataInRequest($this->getApplication()->getRequest());
}
}
示例2: loadRequestData
/**
* Note that the form may not always contain all the fields of the model, so we must always
* make sure that the data for the particular field has actually been submitted to avoid
* setting empty values for fields that weren't included in the form
*/
public function loadRequestData(Request $request, $prefix = '')
{
$enabledFields = is_array($prefix) ? array_flip($prefix) : null;
$schema = ActiveRecordModel::getSchemaInstance(get_class($this));
foreach ($schema->getFieldList() as $field) {
if (!($field instanceof ARForeignKey || $field instanceof ARPrimaryKey)) {
$name = $field->getName();
$reqName = $prefix . $name;
if (is_array($enabledFields) && !isset($enabledFields[$name])) {
continue;
}
if ($request->isValueSet($reqName) || $request->isValueSet('checkbox_' . $reqName) && 'ARBool' == get_class($field->getDataType())) {
switch (get_class($field->getDataType())) {
case 'ARArray':
$this->setValueArrayByLang(array($name), self::getApplication()->getDefaultLanguageCode(), self::getApplication()->getLanguageArray(LiveCart::INCLUDE_DEFAULT), $request);
break;
case 'ARBool':
$this->setFieldValue($name, in_array(strtolower($request->get($reqName)), array('on', 1, 'yes', 'true')));
break;
case 'ARInteger':
case 'ARFloat':
if (is_numeric($request->get($reqName))) {
$this->setFieldValue($name, $request->get($reqName));
}
break;
default:
$this->setFieldValue($name, $request->get($reqName));
break;
}
}
}
}
if ($this instanceof EavAble) {
$hasSpecification = $this->isSpecificationLoaded();
$this->getSpecification()->loadRequestData($request, $prefix);
if (!$hasSpecification && !$this->getSpecification()->hasValues()) {
$this->removeSpecification();
}
}
}
示例3: testLoadAllReferencesIncludingAutoLoad
public function testLoadAllReferencesIncludingAutoLoad()
{
$child = ActiveRecordModel::getNewInstance('LoadReferenceChild');
$child->name->set('child');
$child->setID(4);
$child->save();
$parent = ActiveRecordModel::getNewInstance('LoadReferenceParent');
$parent->setID(4);
$parent->name->set('parent');
$parent->reference->set($child);
$parent->save();
$super = ActiveRecordModel::getNewInstance('LoadReferenceSuper');
$super->setID(1);
$super->name->set('super');
$super->reference->set($parent);
$super->save();
$schema = ActiveRecordModel::getSchemaInstance('LoadReferenceParent');
$schema->registerAutoReference('referenceID');
ActiveRecordModel::clearPool();
$newSuper = ActiveRecordModel::getInstanceByID('LoadReferenceSuper', 1, ActiveRecordModel::LOAD_DATA, true);
$this->assertNotSame($child, $newSuper->reference->get()->reference->get());
$this->assertNotSame($newSuper->reference->get(), $newSuper->reference->get()->reference->get());
$this->assertEqual('child', $newSuper->reference->get()->reference->get()->name->get());
}
示例4: getSchemaInstance
private function getSchemaInstance($fieldName)
{
list($schemaName, $fieldName) = explode('.', $fieldName);
if ($this->getEavTableAlias() == $schemaName) {
$eavField = call_user_func_array(array($this->getEavFieldClass(), 'getInstanceByID'), array($fieldName, true));
if (!$eavField->isMultiValue->get()) {
$schemaName = $eavField->getValueTableName();
} else {
// intentionally return wrong schema for multi-select values as they cannot be sorted or searched
$schemaName = $this->getEavFieldClass();
}
}
$possibleSchemas = ActiveRecordModel::getSchemaInstance($this->modelClass)->getDirectlyReferencedSchemas();
if (isset($possibleSchemas[$schemaName])) {
$schema = $possibleSchemas[$schemaName];
} else {
foreach ((array) $possibleSchemas as $name => $schemaArray) {
$parts = explode('_', $name, 2);
if (isset($parts[1]) && $parts[1] == $schemaName) {
$schema = $schemaArray[0];
break;
}
}
}
if (!isset($schema) || !is_object($schema)) {
$schema = ActiveRecordModel::getSchemaInstance($schemaName);
}
if ('EavItem' == $schema->getName()) {
$schema = ActiveRecordModel::getSchemaInstance('EavValue');
} elseif ('SpecificationItem' == $schema->getName()) {
$schema = ActiveRecordModel::getSchemaInstance('SpecFieldValue');
}
return $schema;
}
示例5: saveAddresses
private function saveAddresses(User $user = null)
{
$user->loadAddresses();
foreach (array('defaultBillingAddress' => 'billingAddress', 'defaultShippingAddress' => 'shippingAddress') as $field => $prefix) {
$address = $user->{$field}->get() ? $user->{$field}->get()->userAddress->get() : UserAddress::getNewInstance();
$address->loadRequestData($this->request, $prefix . '_');
// get address state
if ($stateID = $this->request->get($prefix . '_stateID')) {
$address->state->set(ActiveRecordModel::getInstanceByID('State', $stateID, ActiveRecordModel::LOAD_DATA));
$address->stateName->setNull();
} else {
$address->stateName->set($this->request->get($prefix . '_stateName'));
$address->state->setNull();
}
$modified = false;
foreach (ActiveRecordModel::getSchemaInstance('UserAddress')->getFieldList() as $f) {
if ($address->getFieldValue($f->getName())) {
$modified = true;
}
}
if ($modified) {
$address->save();
if (!$user->{$field}->get()) {
$addressType = call_user_func_array(array($prefix, 'getNewInstance'), array($user, $address));
$addressType->save();
}
}
}
if ($this->request->get('sameAddresses') && $user->defaultBillingAddress->get()) {
$shippingAddress = ShippingAddress::getNewInstance($user, clone $user->defaultBillingAddress->get()->userAddress->get());
$shippingAddress->save();
}
}
示例6: loadSpecificationForRecordSetArray
/**
* Load product specification data for a whole array of products at once
*/
public static function loadSpecificationForRecordSetArray($class, &$productArray, $fullSpecification = false)
{
$ids = array();
foreach ($productArray as $key => $product) {
$ids[$product['ID']] = $key;
}
$fieldClass = call_user_func(array($class, 'getFieldClass'));
$groupClass = $fieldClass . 'Group';
$groupColumn = call_user_func_array(array($fieldClass, 'getGroupIDColumnName'), array($fieldClass));
$stringClass = call_user_func(array($fieldClass, 'getStringValueClass'));
$fieldColumn = call_user_func(array($fieldClass, 'getFieldIDColumnName'));
$objectColumn = call_user_func(array($fieldClass, 'getObjectIDColumnName'));
$valueItemClass = call_user_func(array($fieldClass, 'getSelectValueClass'));
$valueColumn = call_user_func(array($valueItemClass, 'getValueIDColumnName'));
$specificationArray = self::fetchSpecificationData($class, array_flip($ids), $fullSpecification);
$specFieldSchema = ActiveRecordModel::getSchemaInstance($fieldClass);
$specStringSchema = ActiveRecordModel::getSchemaInstance($stringClass);
$specFieldColumns = array_keys($specFieldSchema->getFieldList());
foreach ($specificationArray as &$spec) {
if ($spec['isMultiValue']) {
$value['value'] = $spec['value'];
$value = MultiLingualObject::transformArray($value, $specStringSchema);
if (isset($productArray[$ids[$spec[$objectColumn]]]['attributes'][$spec[$fieldColumn]])) {
$sp =& $productArray[$ids[$spec[$objectColumn]]]['attributes'][$spec[$fieldColumn]];
$sp['valueIDs'][] = $spec['valueID'];
$sp['values'][] = $value;
continue;
}
}
foreach ($specFieldColumns as $key) {
$spec[$fieldClass][$key] = $spec[$key];
unset($spec[$key]);
}
// transform for presentation
$spec[$fieldClass] = MultiLingualObject::transformArray($spec[$fieldClass], $specFieldSchema);
if ($spec[$fieldClass]['isMultiValue']) {
$spec['valueIDs'] = array($spec['valueID']);
$spec['values'] = array($value);
} else {
$spec = MultiLingualObject::transformArray($spec, $specStringSchema);
}
// groups
if ($spec[$fieldClass][$groupColumn]) {
$spec[$fieldClass][$groupClass] = array('ID' => $spec[$fieldClass][$groupColumn], 'name' => $spec['SpecFieldGroupName'], 'position' => $spec['SpecFieldGroupPosition']);
if (!isset($groupSchema)) {
$groupSchema = ActiveRecordModel::getSchemaInstance($groupClass);
}
$spec[$fieldClass][$groupClass] = MultiLingualObject::transformArray($spec[$fieldClass][$groupClass], $groupSchema);
}
if (!empty($spec['value']) || !empty($spec['values']) || !empty($spec['value_lang'])) {
// append to product array
$productArray[$ids[$spec[$objectColumn]]]['attributes'][$spec[$fieldColumn]] = $spec;
self::sortAttributesByHandle($class, $productArray[$ids[$spec[$objectColumn]]]);
}
}
}
示例7: getSchemaColumns
public static function getSchemaColumns($schemaName, LiveCart $application, $customColumns = array())
{
$productSchema = ActiveRecordModel::getSchemaInstance($schemaName);
$availableColumns = array();
foreach ($productSchema->getFieldList() as $field) {
$type = ActiveGrid::getFieldType($field);
if (!$type && 'ID' != $field->getName()) {
continue;
}
$availableColumns[$schemaName . '.' . $field->getName()] = $type;
}
$availableColumns = array_merge($availableColumns, $customColumns);
foreach ($availableColumns as $column => $type) {
$availableColumns[$column] = array('name' => $application->translate($column), 'type' => $type);
}
// specField columns
if (self::isEav($schemaName)) {
$fields = EavFieldManager::getClassFieldSet($schemaName);
foreach ($fields as $field) {
$fieldArray = $field->toArray();
if ($field->isDate()) {
$type = 'date';
} else {
$type = $field->isSimpleNumbers() ? 'numeric' : 'text';
}
$availableColumns['eavField.' . $field->getID()] = array('name' => $fieldArray['name_lang'], 'type' => $type);
}
}
return $availableColumns;
}