model() public static method

public static model ( null | string $className = __CLASS__ )
$className null | string
 /**
  * @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 loadModel($id)
 {
     if (($model = Attribute::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
 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}}');
 }
Beispiel #4
0
 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));
 }
 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;
     });
 }
Beispiel #6
0
 /**
  * @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();
 }
 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();
 }
 public function init()
 {
     parent::init();
     // Выборка категорий/атрибутов
     $this->categoriesA = AttributeCategory::model()->is_a()->with('attrs')->findAll();
     $this->categoriesB = AttributeCategory::model()->is_b()->with('attrs')->findAll();
     // Выборка списка мест
     $placeCategory = AttributeCategory::model()->find('t.code = :code', array(':code' => AttributeCategory::PLACES_CATEGORY_CODE));
     $this->places = Attribute::model()->category($placeCategory->id)->sortByCode()->findAll();
     $this->operations = array('and' => 'и присутствует', 'and_not' => 'и отсутствует', 'or' => 'или');
     $this->cells = array('sameСell' => 'Та же ячейка', 'anotherOpenCellInSameColumn' => 'Другая открытая ячейка в том же столпе', 'rightAndLeftCells' => 'Ячейки, стоящие справа и слева', 'notRightAndLeftCells' => 'Любая ячейка, кроме стоящих непосредственно слева и справа', 'anotherCell' => 'Любая другая ячейка', 'destinyPillars' => 'Столпы судьбы', 'currentLuckPillar' => 'Текущий столп удачи', 'eventPillars' => 'Столпы рассматриваемой даты');
 }
 function actionAttribute($id = null)
 {
     if ($id == null) {
         $this->render('attributes', array('attributes' => Attribute::model()->findAll()));
     } else {
         $c = Attribute::model()->findByPk($id);
         if ($c == null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
         $this->render('attribute', array('attribute' => $c));
     }
 }
 public function actionSort()
 {
     if (isset($_POST['items']) && is_array($_POST['items'])) {
         $i = 0;
         foreach ($_POST['items'] as $item) {
             $project = Attribute::model()->findByPk($item);
             $project->sort_order = $i;
             $project->save();
             $i++;
         }
     }
 }
 /**
  * @param $id
  * @throws CHttpException
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if (($data = Yii::app()->getRequest()->getPost('Type')) !== null) {
         $model->setAttributes($data);
         if ($model->save() && $model->storeTypeAttributes(Yii::app()->getRequest()->getPost('attributes', []))) {
             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('StoreModule.store', 'Product type is updated'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['update', 'id' => $model->id]));
         }
     }
     $criteria = new CDbCriteria();
     $criteria->addNotInCondition('id', CHtml::listData($model->attributeRelation, 'attribute_id', 'attribute_id'));
     $availableAttributes = Attribute::model()->findAll($criteria);
     $this->render('update', ['model' => $model, 'availableAttributes' => $availableAttributes]);
 }
Beispiel #12
0
 /**
  * @param StoreCategory $category
  * @return Attribute[]
  */
 public function getForCategory(StoreCategory $category)
 {
     $criteria = new CDbCriteria(['condition' => 't.is_filter = 1 AND t.type != :type', 'params' => [':type' => Attribute::TYPE_TEXT], 'join' => 'LEFT JOIN {{store_type_attribute}} ON t.id = {{store_type_attribute}}.attribute_id
                    LEFT JOIN {{store_type}} ON {{store_type_attribute}}.type_id = {{store_type}}.id
                    LEFT JOIN {{store_product}} AS products ON products.type_id = {{store_type}}.id', 'distinct' => true]);
     $categories = $category->getChildsArray();
     if (!empty($categories)) {
         $categoriesCriteria = new CDbCriteria(['condition' => 'products.category_id = :category', 'params' => [':category' => $category->id]]);
         $categoriesCriteria->addInCondition('products.category_id', $categories, 'OR');
         $criteria->mergeWith($categoriesCriteria, 'AND');
     } else {
         $criteria->addCondition('products.category_id = :category');
         $criteria->params[':category'] = $category->id;
     }
     return Attribute::model()->findAll($criteria);
 }
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (($data = Yii::app()->getRequest()->getPost('Type')) !== null) {
         $model->setAttributes($data);
         $model->categories = serialize(Yii::app()->getRequest()->getPost('categories'));
         if ($model->save()) {
             $model->setTypeAttributes(Yii::app()->getRequest()->getPost('attributes'));
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('StoreModule.type', 'Тип обновлен.'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['update', 'id' => $model->id]));
         }
     }
     $criteria = new CDbCriteria();
     $criteria->addNotInCondition('id', CHtml::listData($model->attributeRelation, 'attribute_id', 'attribute_id'));
     $availableAttributes = Attribute::model()->findAll($criteria);
     $this->render('update', ['model' => $model, 'availableAttributes' => $availableAttributes]);
 }
Beispiel #14
0
 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));
 }
Beispiel #15
0
 public function save()
 {
     $attribute = Attribute::model()->findByPk($this->id);
     if (is_null($attribute)) {
         // is insert
         $attribute = new Attribute();
         $attribute->attribute_group_id = $this->group;
         $attribute->sort_order = $this->sortOrder;
         $attribute->save();
         $attributeDescription = new AttributeDescription();
         $attributeDescription->attribute_id = $attribute->attribute_id;
         $attributeDescription->language_id = 1;
         // TODO: read locale
         $attributeDescription->name = $this->name;
         $attributeDescription->save();
     } else {
         $attribute->attribute_group_id = $this->group;
         $attribute->sort_order = $this->sortOrder;
         $attribute->save();
         $attribute->description->name = $this->name;
         $attribute->description->save();
     }
 }
 public function loadModel($id)
 {
     $model = Attribute::model()->findByPk($id);
     if ($model === null)
         throw new CHttpException(404, 'The requested page does not exist.');
     return $model;
 }
Beispiel #17
0
 public function findByCode($code)
 {
     return Attribute::model()->find(array('condition' => 't.code = :code', 'params' => array(':code' => $code)));
 }
Beispiel #18
0
	<div class="row">
		<?php 
echo $form->label($model, 'beneficiary_id');
?>
		<?php 
echo $form->dropDownList($model, 'beneficiary_id', GxHtml::listDataEx(Beneficiary::model()->findAllAttributes(null, true)), array('prompt' => Yii::t('app', 'All')));
?>
	</div>

	<div class="row">
		<?php 
echo $form->label($model, 'attribute_id');
?>
		<?php 
echo $form->dropDownList($model, 'attribute_id', GxHtml::listDataEx(Attribute::model()->findAllAttributes(null, true)), array('prompt' => Yii::t('app', 'All')));
?>
	</div>

	<div class="row">
		<?php 
echo $form->label($model, 'value');
?>
		<?php 
echo $form->textField($model, 'value', array('maxlength' => 255));
?>
	</div>

	<div class="row">
		<?php 
echo $form->label($model, 'create_date');
 public function getFullTitle()
 {
     $title = $this->title . ' ' . $this->code;
     if ($this->code_attr != '') {
         $attribute = Attribute::model()->find('t.code = :code', array(':code' => $this->code_attr));
         if ($attribute !== null) {
             $title = $attribute->title . ' ' . $attribute->code . ' (' . $title . ')';
         }
     }
     return $title;
 }
Beispiel #20
0
    $selectedAttributes[] = $attribute->id;
}
foreach ((array) AttributeGroup::model()->findAll() as $group) {
    $items = [];
    $groupHasNotSelectedAttribute = false;
    $groupItems = (array) $group->groupAttributes;
    foreach ($groupItems as $item) {
        $selected = in_array($item->id, $selectedAttributes);
        if (!$selected) {
            $groupHasNotSelectedAttribute = true;
        }
        $items[] = ['text' => CHtml::tag('div', ['class' => 'checkbox'], CHtml::label(CHtml::checkBox('attributes[]', $selected, ['value' => $item->id]) . $item->title, null))];
    }
    $tree[] = ['text' => CHtml::tag('div', ['class' => 'checkbox'], CHtml::label(CHtml::checkBox('', count($groupItems) && !$groupHasNotSelectedAttribute, ['class' => 'group-checkbox']) . $group->name, null)), 'children' => $items];
}
foreach ((array) Attribute::model()->findAllByAttributes(['group_id' => null]) as $attribute) {
    $tree[] = ['text' => CHtml::tag('div', ['class' => 'checkbox'], CHtml::label(CHtml::checkBox('attributes[]', in_array($attribute->id, $selectedAttributes), ['value' => $attribute->id]) . $attribute->title, null))];
}
?>
    <div class="col-sm-7">
        <div class="panel panel-default">
            <div class="panel-heading">
                <?php 
echo Yii::t("StoreModule.store", "Type attributes");
?>
            </div>
            <div class="panel-body">
                <?php 
$this->widget('CTreeView', ['data' => $tree, 'collapsed' => true]);
?>
            </div>
Beispiel #21
0
 public function beforeValidate()
 {
     if (!$this->slug) {
         $this->slug = yupe\helpers\YText::translit($this->name);
     }
     foreach ((array) $this->_eavAttributes as $name => $value) {
         $model = Attribute::model()->getAttributeByName($name);
         if (!$model->isType(Attribute::TYPE_CHECKBOX) && $model->isRequired() && !$value) {
             $this->addError('eav.' . $name, Yii::t("StoreModule.store", "{title} attribute is required", ['title' => $model->title]));
         }
     }
     return parent::beforeValidate();
 }
 /**
  * Save file attributes from File
  * @param File $file
  * @param boolean $update
  */
 private function setAutoFileAttributes($file, $update = false)
 {
     // We download the file first in /tmp/ folder
     if (!file_exists(ReadFile::TEMP_FOLDER . $file->name)) {
         ReadFile::downloadRemoteFile($file->location, $file->name);
     }
     // from update page, we delete all auto attributes and make them again
     if ($update) {
         $criteria = new CDbCriteria();
         $criteria->addCondition('file_id = ' . $file->id);
         $fileAttributes = FileAttributes::model()->findAll($criteria);
         foreach ($fileAttributes as $fileAttribute) {
             if (strpos(Attribute::AUTO_ATTRIBUTE, $fileAttribute->attribute->structured_comment_name)) {
                 $fileAttribute->delete();
             }
         }
     }
     $fileAttribute = new FileAttributes();
     $fileAttribute->file_id = $file->id;
     /*$name = strpos($file->name, '.') ? explode('.', $file->name) : $file->name;
       $name = is_array($name) ? $name[0] : $name;*/
     $extension = str_replace('.', '', $file->extension);
     switch ($extension) {
         case 'fasta':
         case 'fa':
         case 'fastq':
         case 'seq':
         case 'bam':
         case 'sam':
         case 'cram':
             // Launche the python script to get the result
             list($aminoAcids, $nucleotides) = ReadFile::readPythonFile($file->name);
             // Number of Amino Acids
             $numberAminoAcids = clone $fileAttribute;
             $attribute = Attribute::model()->findByAttributes(array('structured_comment_name' => 'num_amino_acids'));
             $numberAminoAcids->attribute_id = $attribute->id;
             $numberAminoAcids->value = $aminoAcids;
             $numberAminoAcids->save();
             // Number of nucleotides
             $numberNucleotides = clone $fileAttribute;
             $attribute = Attribute::model()->findByAttributes(array('structured_comment_name' => 'num_nucleotides'));
             $numberNucleotides->value = $nucleotides;
             $numberNucleotides->attribute_id = $attribute->id;
             $numberNucleotides->save();
             break;
         case 'txt':
         case 'text':
         case 'doc':
         case 'docx':
         case 'rtf':
         case 'odt':
         case 'wpd':
         case 'lwd':
         case 'readme':
         case 'README':
         case 'pdf':
         case '':
             $result = null;
             if (in_array($extension, array('txt', 'text', 'readme', 'README', '', 'wpd', 'lwd'))) {
                 $result = ReadFile::readTextFile($file->name);
             }
             if (in_array($extension, array('docx', 'odt'))) {
                 $result = ReadFile::readDocxOdtFile($file->name);
             }
             if ($extension == 'doc') {
                 $result = ReadFile::readDocFile($file->name);
             }
             if ($extension == 'rtf') {
                 $result = ReadFile::readRtfFile($file->name);
             }
             if ($extension == 'pdf') {
                 $result = ReadFile::readPdfFile($file->name);
             }
             $numberOfLines = $numberOfWords = 0;
             $numberOfWords = str_word_count($result);
             $numberOfLines = substr_count($result, "\n");
             // Number of words
             $numberWords = clone $fileAttribute;
             $attribute = Attribute::model()->findByAttributes(array('structured_comment_name' => 'num_words'));
             $numberWords->attribute_id = $attribute->id;
             $numberWords->value = $numberOfWords;
             $numberWords->save();
             // Number of lines
             $numberLines = clone $fileAttribute;
             $attribute = Attribute::model()->findByAttributes(array('structured_comment_name' => 'num_lines'));
             $numberLines->attribute_id = $attribute->id;
             $numberLines->value = $numberOfLines;
             $numberLines->save();
             break;
         case 'csv':
         case 'tsv':
         case 'xls':
         case 'xlsx':
         case 'tab':
         case 'sdc':
         case 'ods':
         case 'gff':
         case 'gff3':
         case 'snp':
         case 'vcf':
         case 'ipr':
             $rows = $columns = 0;
             if ($extension == 'xls') {
                 list($rows, $columns) = ReadFile::readXlsFile($file->name);
             }
             if ($extension == 'ods') {
                 list($rows, $columns) = ReadFile::readOdsFile($file->name);
             }
             if ($extension == 'xlsx') {
                 list($rows, $columns) = ReadFile::readXlsxFile($file->name);
             }
             if (in_array($extension, array('csv', 'tsv', 'vcf', 'gff'))) {
                 list($rows, $columns) = ReadFile::readTableFile($file->name, $extension);
             }
             // Number of rows
             $numberRows = clone $fileAttribute;
             $attribute = Attribute::model()->findByAttributes(array('structured_comment_name' => 'num_rows'));
             $numberRows->attribute_id = $attribute->id;
             $numberRows->value = $rows;
             $numberRows->save();
             // Number of columns
             $numberColumns = clone $fileAttribute;
             $attribute = Attribute::model()->findByAttributes(array('structured_comment_name' => 'num_columns'));
             $numberColumns->value = $columns;
             $numberColumns->attribute_id = $attribute->id;
             $numberColumns->save();
             break;
     }
 }
 public function getAttributesList($type = 'default')
 {
     $attribute = $type == 'finish' ? 'finishAttributesArray' : 'attributesArray';
     if (is_array($this->{$attribute})) {
         $criteria = new CDbCriteria();
         $criteria->select = 'id, code, title';
         $criteria->addInCondition('t.code', $this->{$attribute});
         $attributes = Attribute::model()->findAll($criteria);
         $attributesList = CHtml::listData($attributes, 'code', 'titleWithCode');
         return implode('<br />', $attributesList);
     }
     return '-';
 }
Beispiel #24
0
 /**
  * @param CHttpRequest $request
  * @return array
  */
 public function getTypeAttributesForSearchFromQuery(CHttpRequest $request)
 {
     $attributes = Yii::app()->getCache()->get('Store::filter::attributes');
     if (false === $attributes) {
         $attributes = [];
         $models = Attribute::model()->findAll(['select' => ['name', 'id', 'type']]);
         foreach ($models as $model) {
             $attributes[$model->name] = $model;
         }
         Yii::app()->getCache()->set('Store::filter::attributes', $attributes);
     }
     $result = [];
     $attributeValue = new AttributeValue();
     foreach ($attributes as $name => $attribute) {
         $searchParams = $request->getQuery($attribute->name);
         //пропускаем пустые значения
         if (null === $searchParams) {
             continue;
         }
         if (is_array($searchParams)) {
             if (isset($searchParams['from']) && null == $searchParams['from']) {
                 unset($searchParams['from']);
             }
             if (isset($searchParams['to']) && null == $searchParams['to']) {
                 unset($searchParams['to']);
             }
             if (empty($searchParams)) {
                 continue;
             }
         }
         $result[$attribute->name] = ['value' => $searchParams, 'attribute_id' => (int) $attribute->id, 'column' => $attributeValue->column($attribute->type)];
     }
     return $result;
 }
Beispiel #25
0
 /**
  * @param CHttpRequest $request
  * @return array
  */
 public function getEavAttributesForSearchFromQuery(CHttpRequest $request)
 {
     $result = $params = [];
     $attributes = Attribute::model()->cache(Yii::app()->getModule('yupe')->coreCacheTime)->findAll(['select' => ['name']]);
     foreach ($attributes as $attribute) {
         if ($request->getQuery($attribute->name)) {
             $searchParams = $request->getQuery($attribute->name);
             if (!is_array($searchParams)) {
                 $result[$attribute->name] = $searchParams;
                 continue;
             }
             $isFrom = array_key_exists('from', $searchParams);
             $isTo = array_key_exists('to', $searchParams);
             if (false === $isFrom && false === $isTo) {
                 $result[$attribute->name] = $searchParams;
                 continue;
             }
             if (true === $isFrom && !empty($searchParams['from'])) {
                 $result[] = ['>=', $attribute->name, (double) $searchParams['from']];
             }
             if (true === $isTo && !empty($searchParams['to'])) {
                 $result[] = ['<=', $attribute->name, (double) $searchParams['to']];
             }
         }
     }
     return $result;
 }
Beispiel #26
0
 protected function _loadAttributesPool()
 {
     $this->_attributesPool = CHtml::listData(Attribute::model()->with(array('parent', 'element'))->findAll(), 'code', function ($data) {
         return $data;
     });
 }
 public static function getOptionName($attributeName, $value)
 {
     $attribute = Attribute::model()->findByAttributes(['name' => $attributeName]);
     $attributeOption = self::model()->findByAttributes(['attribute_id' => $attribute->id, 'id' => $value]);
     return $attributeOption->value;
 }
 /**
  * @param $attributeId
  * @param $value
  * @param Product $product
  * @return bool
  */
 public function store($attributeId, $value, Product $product)
 {
     $attribute = null;
     if (!isset($this->attributes[$attributeId])) {
         $attribute = Attribute::model()->findByPk($attributeId);
         $this->attributes[$attributeId] = $attribute;
     } else {
         $attribute = $this->attributes[$attributeId];
     }
     switch ($attribute->type) {
         case Attribute::TYPE_DROPDOWN:
             $this->option_value = empty($value) ? null : (int) $value;
             break;
         case Attribute::TYPE_CHECKBOX_LIST:
             $this->option_value = empty($value) ? null : (int) $value;
             break;
         case Attribute::TYPE_CHECKBOX:
             $this->number_value = empty($value) ? 0 : 1;
             break;
         case Attribute::TYPE_NUMBER:
             $this->number_value = empty($value) ? null : (double) $value;
             break;
         case Attribute::TYPE_TEXT:
             $this->text_value = $value;
             break;
         case Attribute::TYPE_SHORT_TEXT:
             $this->string_value = $value;
             break;
         default:
             throw new InvalidArgumentException('Error attribute!');
     }
     $this->product_id = $product->id;
     $this->attribute_id = $attribute->id;
     return $this->save();
 }
 /**
  * Возвращает модель по указанному идентификатору
  * Если модель не будет найдена - возникнет HTTP-исключение.
  *
  * @param integer $id - идентификатор нужной модели
  *
  * @return Attribute $model
  *
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Attribute::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('StoreModule.attribute', 'Page was not found!'));
     }
     return $model;
 }
Beispiel #30
0
<?php

$this->breadcrumbs = array($model->label(2) => array('index'), Yii::t('app', 'Manage'));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create')));
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('beneficiary-attribute-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>

<h1><?php 
echo Yii::t('app', 'Manage') . ' ' . GxHtml::encode($model->label(2));
?>
</h1>

<p>
You may optionally enter a comparison operator (&lt;, &lt;=, &gt;, &gt;=, &lt;&gt; or =) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<?php 
echo GxHtml::link(Yii::t('app', 'Advanced Search'), '#', array('class' => 'search-button'));
?>
<div class="search-form">
<?php 
$this->renderPartial('_search', array('model' => $model));
?>
</div><!-- search-form -->

<?php 
$this->widget('zii.widgets.grid.CGridView', array('id' => 'beneficiary-attribute-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('id', array('name' => 'beneficiary_id', 'value' => 'GxHtml::valueEx($data->beneficiary)', 'filter' => GxHtml::listDataEx(Beneficiary::model()->findAllAttributes(null, true))), array('name' => 'attribute_id', 'value' => 'GxHtml::valueEx($data->attribute)', 'filter' => GxHtml::listDataEx(Attribute::model()->findAllAttributes(null, true))), 'value', 'create_date', 'deleted_at', array('class' => 'CButtonColumn'))));