public function updateValue(Attribute &$attr) { if ($attr instanceof Classes) { $this->addClass($attr->getClassList()); } else { } }
/** * 新商品 */ public function save() { $item = new Attribute(); $item->cat_id = Input::get('cat_id'); $item->name = Input::get('name'); $item->save(); return redirect()->route('admin.attribute.index'); }
public function setAttribute(Attribute $attribute) { if ($attribute->get('name') == 'class' && $attribute->get('name') == 'style') { return $this; } $this->attributes[$attribute->get('name')] = $attribute; return $this; }
/** * @param Attribute $attribute */ public function setAttribute(Attribute $attribute) { $this->attribute->removeValue($this); // Remove value from current attribute $attribute->addValue($this); // Add value to new attribute $this->attribute = $attribute; }
public function testGroupsToArray() { $array = array('BMI' => array('groups' => array('group1', 'group2'))); $attr = new Attribute(); $attr->setName('BMI'); $attr->addGroup('group1'); $attr->addGroup('group2'); $this->assertEquals($array, $attr->toArray()); }
public function actionAdmin() { $model = new Attribute('search'); $model->unsetAttributes(); if (isset($_GET['Attribute'])) { $model->setAttributes($_GET['Attribute']); } $this->render('admin', array('model' => $model)); }
public function __construct(Product $product, Attribute $attribute, AttributeValue $attributeValue) { $this->setId(); $this->setCreated(); $this->product = $product; $this->attribute = $attribute; $this->attributeValue = $attributeValue; $product->addProductAttribute($this); $attribute->addProductAttribute($this); $attributeValue->addProductAttribute($this); }
public function delete() { if (parent::delete()) { $ret = true; $attributes = $this->getAttributes(); foreach ($attributes as $attribute) { $attr = new Attribute((int) $attribute['id_attribute']); $ret &= $attr->delete(); } return $ret; } }
public function listAction() { $limit = 10; //查询数据 $attribute = new \Attribute(); $list = $attribute->getList(); //数据 $page_html = $this->pageHtml($list); //分页html //加载js $this->assets->addJs('backend/mt/attribute-list.js'); $this->view->setVars(['list' => $list, 'page_html' => $page_html]); }
/** * @param bool $isObjectNew * @param bool $isSearchable * @param int $invalidateCounter * @return void * @dataProvider aroundDeleteDataProvider */ public function testAroundDelete($isObjectNew, $isSearchable, $invalidateCounter) { $attributeMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Eav\\Attribute', ['getIsSearchable', 'isObjectNew', '__wakeup'], [], '', false); $attributeMock->expects($this->any())->method('getIsSearchable')->will($this->returnValue($isSearchable)); $attributeMock->expects($this->once())->method('isObjectNew')->will($this->returnValue($isObjectNew)); $closureMock = function (\Magento\Catalog\Model\Resource\Eav\Attribute $object) use($attributeMock) { $this->assertEquals($object, $attributeMock); return $this->subjectMock; }; $this->indexerMock->expects($this->exactly($invalidateCounter))->method('invalidate'); $this->prepareIndexer($invalidateCounter); $this->assertEquals($this->subjectMock, $this->model->aroundDelete($this->subjectMock, $closureMock, $attributeMock)); }
private function _attributeExists($v) { $v = explode(":", $v); $result = Db::getInstance()->getRow('SELECT `id_attribute` FROM ' . DB_PREFIX . 'attribute WHERE `name`="' . pSQL($v[1]) . '"'); if (isset($result['id_attribute'])) { return $result['id_attribute']; } else { $attribute = new Attribute(); $attribute->id_attribute_group = $v[0]; $attribute->name = $v[1]; $attribute->add(); return $attribute->id; } }
public function run() { $this->trancate(); $faker = Faker\Factory::create(); $languages = Language::all(); $products = Product::all(); $attributes = Attribute::all(); $attributes_options = array(); foreach ($languages as $language) { $options = DB::table('attributes_options')->whereLanguageId($language->id)->get(); $options = new Illuminate\Database\Eloquent\Collection($options); $options = $options->lists("options", 'attribute_id'); $attributes_options[$language->id] = $options; } $attributes_key = $attributes->modelKeys(); $products->each(function ($product) use($attributes_key, $languages, $faker, $attributes_options) { $count_to_insert = rand(0, rand(0, count($attributes_key) - 1)); for ($i = 1; $i <= $count_to_insert; $i++) { foreach ($languages as $language) { $attribute_id = $attributes_key[rand(0, count($attributes_key) - 1)]; $options = $attributes_options[$language->id][$attribute_id]; $tokens = explode("|", $options); try { DB::table('products_to_attributes')->insert(array('product_id' => $product->id, 'language_id' => $language->id, 'attribute_id' => $attribute_id, 'value' => $tokens[rand(0, count($tokens) - 1)])); } catch (Exception $x) { var_dump($x); } } } }); }
/** * Задает значение атрибута * @param mixed $value */ public function setValue($value) { $toSet = null; if ($value !== null && $value !== '') { $list = $this->getListItems(); //перебираем все id foreach ($list as $item) { if ($item['ID'] == $value) { $toSet = $item['ID']; break; } } //перебираем все xml_id if ($toSet === null) { foreach ($list as $item) { if ($item['XML_ID'] == $value) { $toSet = $item['ID']; break; } } } //перебираем все значения if ($toSet === null) { foreach ($list as $item) { if ($item['VALUE'] == $value) { $toSet = $item['ID']; break; } } } } parent::setValue($toSet); }
/** * Exports the object as an array. * * You can specify the key type of the array by passing one of the class * type constants. * * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. * Defaults to TableMap::TYPE_PHPNAME. * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. * * @return array an associative array containing the field names (as keys) and field values */ public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { if (isset($alreadyDumpedObjects['LegacyCartItemAttributeCombination'][serialize($this->getPrimaryKey())])) { return '*RECURSION*'; } $alreadyDumpedObjects['LegacyCartItemAttributeCombination'][serialize($this->getPrimaryKey())] = true; $keys = LegacyCartItemAttributeCombinationTableMap::getFieldNames($keyType); $result = array($keys[0] => $this->getCartItemId(), $keys[1] => $this->getAttributeId(), $keys[2] => $this->getAttributeAvId()); $virtualColumns = $this->virtualColumns; foreach ($virtualColumns as $key => $virtualColumn) { $result[$key] = $virtualColumn; } if ($includeForeignObjects) { if (null !== $this->aCartItem) { $result['CartItem'] = $this->aCartItem->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } if (null !== $this->aAttribute) { $result['Attribute'] = $this->aAttribute->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } if (null !== $this->aAttributeAv) { $result['AttributeAv'] = $this->aAttributeAv->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); } } return $result; }
/** * Задает значение атрибута * @param mixed $value */ public function setValue($value) { parent::setValue($value); $val = $this->getValue(); $val = (double) str_replace(array(' ', ','), array('', '.'), $val); parent::setValue($val); }
public function safeUp() { $this->createTable('{{store_product_attribute_value}}', ['id' => 'pk', 'product_id' => 'INTEGER NOT NULL', 'attribute_id' => 'INTEGER NOT NULL', 'number_value' => 'REAL', 'string_value' => 'VARCHAR(250)', 'text_value' => 'TEXT', 'option_value' => 'INTEGER', 'create_time' => 'DATETIME'], $this->getOptions()); //fk $this->addForeignKey('{{fk_product_attribute_product}}', '{{store_product_attribute_value}}', 'product_id', '{{store_product}}', 'id', 'CASCADE'); $this->addForeignKey('{{fk_product_attribute_attribute}}', '{{store_product_attribute_value}}', 'attribute_id', '{{store_attribute}}', 'id', 'CASCADE'); $this->addForeignKey('{{fk_product_attribute_option}}', '{{store_product_attribute_value}}', 'option_value', '{{store_attribute_option}}', 'id', 'CASCADE'); //ix $this->createIndex('{{ix_product_attribute_number_value}}', '{{store_product_attribute_value}}', 'number_value'); $this->createIndex('{{ix_product_attribute_string_value}}', '{{store_product_attribute_value}}', 'string_value'); //перенести аттрибуты $attributes = Yii::app()->getDb()->createCommand('SELECT * FROM {{store_product_attribute_eav}}')->queryAll(); $modelsAttr = []; foreach ($attributes as $attribute) { $product = Product::model()->findByPk($attribute['product_id']); if (null === $product) { continue; } if (!isset($modelsAttr[$attribute['attribute']])) { $model = Attribute::model()->find('name = :name', [':name' => $attribute['attribute']]); if (null === $model) { continue; } $modelsAttr[$attribute['attribute']] = $model; } $value = new AttributeValue(); $value->store($modelsAttr[$attribute['attribute']]->id, $attribute['value'], $product); } $this->dropTable('{{store_product_attribute_eav}}'); }
/** * @throws Exception */ public function run() { if ('*' === $this->attributes) { $this->attributes = Attribute::model()->with(['options.parent'])->cache($this->cacheTime)->findAll(['condition' => 't.is_filter = 1', 'order' => 't.sort DESC']); } foreach ($this->attributes as $attribute) { $model = is_string($attribute) ? Attribute::model()->findByAttributes(['name' => $attribute]) : $attribute; if ($model) { switch ($model->type) { case Attribute::TYPE_DROPDOWN: $this->widget('application.modules.store.widgets.filters.DropdownFilterWidget', ['attribute' => $model]); break; case Attribute::TYPE_CHECKBOX_LIST: $this->widget('application.modules.store.widgets.filters.DropdownFilterWidget', ['attribute' => $model]); break; case Attribute::TYPE_CHECKBOX: $this->widget('application.modules.store.widgets.filters.CheckboxFilterWidget', ['attribute' => $model]); break; case Attribute::TYPE_NUMBER: $this->widget('application.modules.store.widgets.filters.NumberFilterWidget', ['attribute' => $model]); break; case Attribute::TYPE_SHORT_TEXT: $this->widget('application.modules.store.widgets.filters.TextFilterWidget', ['attribute' => $model]); break; } } } }
public function renderForm() { if (!$this->object->id) { $this->object->price = -1; } $shops = Shop::getShops(); if (count($this->context->employee->getAssociatedShops()) > 1) { $shops = array_merge(array(0 => array('id_shop' => 0, 'name' => $this->l('All shops'))), $shops); } $this->fields_form = array('legend' => array('title' => $this->l('Specific price rules')), 'input' => array(array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 33, 'maxlength' => 32, 'required' => true, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}'), array('type' => 'select', 'label' => $this->l('Shop:'), 'name' => 'id_shop', 'options' => array('query' => $shops, 'id' => 'id_shop', 'name' => 'name'), 'condition' => Shop::isFeatureActive(), 'default_value' => Shop::getContextShopID()), array('type' => 'select', 'label' => $this->l('Currency:'), 'name' => 'id_currency', 'options' => array('query' => array_merge(array(0 => array('id_currency' => 0, 'name' => $this->l('All currencies'))), Currency::getCurrencies()), 'id' => 'id_currency', 'name' => 'name')), array('type' => 'select', 'label' => $this->l('Country:'), 'name' => 'id_country', 'options' => array('query' => array_merge(array(0 => array('id_country' => 0, 'name' => $this->l('All countries'))), Country::getCountries((int) $this->context->language->id)), 'id' => 'id_country', 'name' => 'name')), array('type' => 'select', 'label' => $this->l('Group:'), 'name' => 'id_group', 'options' => array('query' => array_merge(array(0 => array('id_group' => 0, 'name' => $this->l('All groups'))), Group::getGroups((int) $this->context->language->id)), 'id' => 'id_group', 'name' => 'name')), array('type' => 'text', 'label' => $this->l('From quantity:'), 'name' => 'from_quantity', 'size' => 6, 'maxlength' => 10, 'required' => true), array('type' => 'text', 'label' => $this->l('Price (tax excl.):'), 'name' => 'price', 'size' => 6, 'disabled' => $this->object->price == -1 ? 1 : 0, 'maxlength' => 10, 'suffix' => $this->context->currency->getSign('right')), array('type' => 'checkbox', 'name' => 'leave_bprice', 'values' => array('query' => array(array('id' => 'on', 'name' => $this->l('Leave base price'), 'val' => '1', 'checked' => '1')), 'id' => 'id', 'name' => 'name')), array('type' => 'date', 'label' => $this->l('From:'), 'name' => 'from', 'size' => 12), array('type' => 'date', 'label' => $this->l('To:'), 'name' => 'to', 'size' => 12), array('type' => 'select', 'label' => $this->l('Reduction type:'), 'name' => 'reduction_type', 'options' => array('query' => array(array('reduction_type' => 'amount', 'name' => $this->l('Amount')), array('reduction_type' => 'percentage', 'name' => $this->l('Percentage'))), 'id' => 'reduction_type', 'name' => 'name')), array('type' => 'text', 'label' => $this->l('Reduction:'), 'name' => 'reduction', 'required' => true)), 'submit' => array('title' => $this->l('Save'), 'class' => 'button')); if (($value = $this->getFieldValue($this->object, 'price')) != -1) { $price = number_format($value, 2); } else { $price = ''; } $this->fields_value = array('price' => $price, 'from_quantity' => ($value = $this->getFieldValue($this->object, 'from_quantity')) ? $value : 1, 'reduction' => number_format(($value = $this->getFieldValue($this->object, 'reduction')) ? $value : 0, 2), 'leave_bprice_on' => $price ? 0 : 1); $attribute_groups = array(); $attributes = Attribute::getAttributes((int) $this->context->language->id); foreach ($attributes as $attribute) { if (!isset($attribute_groups[$attribute['id_attribute_group']])) { $attribute_groups[$attribute['id_attribute_group']] = array('id_attribute_group' => $attribute['id_attribute_group'], 'name' => $attribute['attribute_group']); } $attribute_groups[$attribute['id_attribute_group']]['attributes'][] = array('id_attribute' => $attribute['id_attribute'], 'name' => $attribute['name']); } $features = Feature::getFeatures((int) $this->context->language->id); foreach ($features as &$feature) { $feature['values'] = FeatureValue::getFeatureValuesWithLang((int) $this->context->language->id, $feature['id_feature'], true); } $this->tpl_form_vars = array('manufacturers' => Manufacturer::getManufacturers(), 'suppliers' => Supplier::getSuppliers(), 'attributes_group' => $attribute_groups, 'features' => $features, 'categories' => Category::getSimpleCategories((int) $this->context->language->id), 'conditions' => $this->object->getConditions(), 'is_multishop' => Shop::isFeatureActive()); return parent::renderForm(); }
public function loadModel($id) { if (($model = Attribute::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
public function __construct($tag = null, $attributes = null) { if ($this->isEmpty($tag)) { throw new HTML5Error(HTML5Error::EMPTY_NODE_TAG); } $this->_parent = null; $this->_tag = $tag; $this->_attributes = array(); if (isset(Specification::$TAGS[$tag])) { $this->_validAttrs = array_merge( Specification::$TAGS[$tag], Specification::$ATTRIBUTES ); } else { $this->_validAttrs = array(); } if ($attributes !== null) { if (is_string($attributes)) { $attributes = Attribute::shorthand($attributes); } if (is_array($attributes)) { $this->setAttributes($attributes); } } }
private static function forTypeAndOrg($type, $org) { if (is_object($org)) { $org = $org->id; } $attrs = Attribute::whereRaw('`for` = ? AND organization_id = ?', [$type, $org])->get(); return $attrs; }
/** * Gets and sets the theme attribute (data-theme="a") * * @param string $value * @return string|self */ public function theme() { if (func_num_args() === 0) { return $this->theme->value(); } $this->theme->value(func_get_arg(0)); return $this; }
public function getPolicy() { $att = Attribute::model()->findByAttributes(array('attribute_name' => Attribute::FUP)); if (!$att) { return null; } return DatasetAttributes::model()->findByAttributes(array('dataset_id' => $this->id, 'attribute_id' => $att->id)); }
function save_singleDimension($v0390f4ac89dd, $v7dbfca66c609, $vb8f02101126e) { global $cookie; $v9661b333c109 = (int) Db::getInstance()->getValue('SELECT id_product_attribute FROM ' . _DB_PREFIX_ . 'product_attribute WHERE id_product = ' . $v0390f4ac89dd . ' AND default_on = 1 ORDER BY id_product_attribute DESC'); $v0d483f03670f = Db::getInstance()->ExecuteS('SELECT id_attribute FROM ' . _DB_PREFIX_ . 'product_attribute_combination WHERE id_product_attribute = ' . $v9661b333c109); $v2dcd27727003 = Db::getInstance()->getRow('SELECT * FROM ' . _DB_PREFIX_ . 'product_attribute WHERE default_on = 1 AND id_product = ' . $v0390f4ac89dd); Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product_attribute SET default_on = 0 WHERE id_product = ' . $v0390f4ac89dd); if (!($vd91705970ca1 = (int) Db::getInstance()->getValue('SELECT a.id_attribute FROM ' . _DB_PREFIX_ . 'attribute AS a LEFT JOIN ' . _DB_PREFIX_ . 'attribute_lang AS al ON a.id_attribute = al.id_attribute WHERE a.id_attribute_group = ' . $v7dbfca66c609 . ' AND al.id_lang = ' . (int) $cookie->id_lang . ' AND al.name = "' . $vb8f02101126e . '"'))) { if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) { $v152cf454beb9 = (int) Attribute::getHigherPosition($v7dbfca66c609); $v152cf454beb9++; $vef258eea13a5 = 'INSERT INTO ' . _DB_PREFIX_ . 'attribute (id_attribute_group, position) VALUES (' . $v7dbfca66c609 . ', ' . $v152cf454beb9 . ')'; } else { $vef258eea13a5 = 'INSERT INTO ' . _DB_PREFIX_ . 'attribute (id_attribute_group) VALUES (' . $v7dbfca66c609 . ')'; } Db::getInstance()->execute($vef258eea13a5); $vd91705970ca1 = Db::getInstance()->Insert_ID(); if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) { $v59cefedeccb8 = (int) $v1869f6698708->id_shop; Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'attribute_shop (id_attribute, id_shop) VALUES (' . $vd91705970ca1 . ', ' . $v59cefedeccb8 . ')'); } for ($vf7a487fdfbf4 = 1; $vf7a487fdfbf4 < 6; $vf7a487fdfbf4++) { Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'attribute_lang (`id_attribute`, `id_lang`, `name`) VALUES (' . $vd91705970ca1 . ', ' . $vf7a487fdfbf4 . ', ' . $vb8f02101126e . ')'); } } $v489fcc49bdb7 = ''; $v65a9a2b21a04 = ''; if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) { $v489fcc49bdb7 = ', available_date'; $v65a9a2b21a04 = ', "0000-00-00"'; } if (Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute (id_product, quantity, price, aimd_value, weight, default_on' . $v489fcc49bdb7 . ') VALUES (' . $v2dcd27727003['id_product'] . ', 1, ' . $v2dcd27727003['price'] . ', 0, ' . $v2dcd27727003['weight'] . ', 1' . $v65a9a2b21a04 . ')')) { $vb5c94481c96a = Db::getInstance()->Insert_ID(); Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product SET quantity = quantity + 1 WHERE id_product = ' . $v0390f4ac89dd); foreach ($v0d483f03670f as $v1e7b1f8152e0) { $v31b067b2f701 = (int) $v1e7b1f8152e0['id_attribute']; if ($v7dbfca66c609 == (int) Db::getInstance()->getValue('SELECT id_attribute_group FROM ' . _DB_PREFIX_ . 'attribute WHERE id_attribute = ' . $v31b067b2f701)) { $v31b067b2f701 = $vd91705970ca1; } Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . $v31b067b2f701 . ', ' . $vb5c94481c96a . ')'); } $v643e6a337530 = Db::getInstance()->getValue('SELECT id_image FROM ' . _DB_PREFIX_ . 'product_attribute_image WHERE id_product_attribute = ' . $v2dcd27727003['id_product_attribute']); if ($v643e6a337530) { Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_image (id_product_attribute, id_image) VALUES (' . $vb5c94481c96a . ', ' . $v643e6a337530 . ')'); } if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) { Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product_attribute_shop SET default_on = 0 WHERE id_product_attribute IN (SELECT id_product_attribute FROM ' . _DB_PREFIX_ . 'product_attribute WHERE ' . 'id_product = ' . $v0390f4ac89dd . ')'); if ((int) Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 1 && (Tools::getIsset('shop_linked') && Tools::getValue('shop_linked'))) { $v003fcea77e06 = array((int) Tools::getValue('shop_linked')); } else { $v003fcea77e06 = Db::getInstance()->ExecuteS('SELECT id_shop FROM ' . _DB_PREFIX_ . 'shop WHERE active = 1'); } foreach ($v003fcea77e06 as $v59cefedeccb8) { Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_shop (id_product_attribute, id_shop, price, wholesale_price, weight, minimal_quantity, default_on, available_date) VALUES (' . $vb5c94481c96a . ', ' . (int) $v59cefedeccb8['id_shop'] . ', ' . $v2dcd27727003['price'] . ', ' . $v2dcd27727003['wholesale_price'] . ', ' . $v2dcd27727003['weight'] . ', ' . $v2dcd27727003['minimal_quantity'] . ', 1, "0000-00-00")'); } } } }
public function getPlaceList() { // Выборка списка мест $placeCategory = AttributeCategory::model()->find('t.code = :code', array(':code' => AttributeCategory::PLACES_CATEGORY_CODE)); $places = Attribute::model()->category($placeCategory->id)->sortByCode()->findAll(); return CHtml::listData($places, 'code', function ($data) { return $data->code . ' - ' . $data->title; }); }
public function init() { if (is_string($this->attribute)) { $this->attribute = Attribute::model()->findByAttributes(['name' => $this->attribute]); } if (!$this->attribute instanceof Attribute || $this->attribute->type != Attribute::TYPE_NUMBER) { throw new Exception('Атрибут не найден или неправильного типа'); } parent::init(); }
/** * @throws Exception */ public function init() { if (is_string($this->attribute)) { $this->attribute = Attribute::model()->findByAttributes(['name' => $this->attribute]); } if (!$this->attribute instanceof Attribute || !$this->attribute->isMultipleValues()) { throw new Exception(Yii::t('StoreModulle.store', 'Attribute error!')); } parent::init(); }
function __construct($master_view = "n/a") { $this->arguments = array(); Attribute::Loader(array(attribute_root, global_attribute_root)); if ($master_view == "n/a") { $this->view = new view($this->master_view); } else { $this->view = new view($master_view); } }
private static function buildDBAttr($dbAttr, $pdo) { $attr = Attribute::__build($dbAttr['ID'], $dbAttr['NAME'], null); $valstmt = $pdo->prepare("SELECT * FROM ATTRIBUTEVALUE WHERE " . "ATTRIBUTE_ID = :id ORDER BY VALUE"); $valstmt->execute(array(':id' => $dbAttr['ID'])); while ($dbVal = $valstmt->fetch()) { $val = AttributeValue::__build($dbVal['ID'], $dbVal['VALUE']); $attr->addValue($val); } return $attr; }
public function actionCreate() { $model = new DatasetAttributes(); $att = Attribute::model()->findByAttributes(array('attribute_name' => Attribute::FUP)); if (!$att) { $att = new Attribute(); $att->attribute_name = Attribute::FUP; $att->definition = ''; $att->save(); } $model->attribute_id = $att->id; $image = new Images(); if (isset($_POST['DatasetAttributes'])) { $args = $_POST['DatasetAttributes']; $exist = DatasetAttributes::model()->findByAttributes(array('dataset_id' => $args['dataset_id'], 'attribute_id' => $att->id)); if ($exist) { $model = $exist; } $model->attributes = $args; $model->value = ''; //$image->attributes = $_POST['Images']; $image->license = "no license"; $image->photographer = "no author"; $image->source = "gigadb"; if ($image->validate()) { $image->save(); } else { Yii::log(print_r($image->getErrors(), true), 'debug'); } if ($image) { $model->image_id = $image->id; } if ($model->validate()) { $model->save(); $this->redirect('/dataset/' . $model->dataset->identifier); } else { Yii::log(print_r($model->getErrors(), true), 'debug'); } } $this->render('create', array('model' => $model, 'image' => $image)); }