当前位置: 首页>>代码示例>>PHP>>正文


PHP models\Object类代码示例

本文整理汇总了PHP中app\models\Object的典型用法代码示例。如果您正苦于以下问题:PHP Object类的具体用法?PHP Object怎么用?PHP Object使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Object类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionSave

 function actionSave()
 {
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         throw new MyException('Вы не туда попали.');
     }
     if (empty($_POST['title'])) {
         throw new MyException('Поле "Заголовок" - обязательное!');
     }
     if ($_FILES['img']['name']) {
         $types = array('image/gif', 'image/png', 'image/jpeg');
         $size = 10000000;
         if (!in_array($_FILES['img']['type'], $types)) {
             throw new MyException('Мы такие форматы не грузим.');
         }
         if ($_FILES['img']['size'] > $size) {
             throw new MyException('Слишком большой размер картинки.');
         }
         $image = file_get_contents($_FILES['img']['tmp_name']);
     }
     $obj = new ObjectModel();
     $obj->title = $_POST['title'];
     $obj->text = $_POST['text'];
     $obj->type = $_POST['type'];
     $obj->img = $image ? $image : null;
     $obj->insert();
     header("Location: http://work/objectForDB/");
     exit;
 }
开发者ID:Mavellol,项目名称:work,代码行数:28,代码来源:Object.php

示例2: run

 public function run()
 {
     $this->genButton = Html::a(Icon::show('edit') . Yii::t('app', 'Generate'), '#', ['class' => 'btn btn-success', 'id' => 'btn-generate']);
     $parent_id = $this->model->main_category_id;
     $owner_id = $this->model->id;
     $this->addButton = Html::a(Icon::show('plus') . Yii::t('app', 'Add'), Url::toRoute(['/shop/backend-product/edit', 'parent_id' => $parent_id, 'owner_id' => $owner_id, 'returnUrl' => \app\backend\components\Helper::getReturnUrl()]), ['class' => 'btn btn-success', 'id' => 'btn-add']);
     if (!empty($this->footer)) {
         $this->footer = Html::tag('div', $this->addButton . ' ' . $this->genButton, ['class' => 'widget-footer']);
     }
     $this->object = Object::getForClass(get_class($this->model));
     $rest_pg = (new Query())->select('id, name')->from(PropertyGroup::tableName())->where(['object_id' => $this->object->id])->orderBy('sort_order')->all();
     $this->property_groups_to_add = [];
     foreach ($rest_pg as $row) {
         $this->property_groups_to_add[$row['id']] = $row['name'];
     }
     $optionGenerate = Json::decode($this->model->option_generate);
     if (null === PropertyGroup::findOne($optionGenerate['group'])) {
         $this->model->option_generate = $optionGenerate = null;
     }
     $groupModel = null;
     if (isset($optionGenerate['group'])) {
         $groupModel = PropertyGroup::findOne($optionGenerate['group']);
         $properties = Property::getForGroupId($optionGenerate['group']);
     } else {
         $group_ids = array_keys($this->property_groups_to_add);
         $group_id = array_shift($group_ids);
         $groupModel = PropertyGroup::findOne($group_id);
         $properties = Property::getForGroupId($group_id);
     }
     if (is_null($groupModel)) {
         $groupModel = new PropertyGroup();
     }
     return $this->render($this->viewFile, ['model' => $this->model, 'form' => $this->form, 'groups' => $this->property_groups_to_add, 'groupModel' => $groupModel, 'properties' => $properties, 'optionGenerate' => $optionGenerate, 'footer' => $this->footer]);
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:34,代码来源:OptionGenerate.php

示例3: actionExport

 public function actionExport($importModel)
 {
     /** @var ImportModel $model */
     $model = new ImportModel();
     $model->unserialize($importModel);
     if ($model->validate()) {
         /** @var Export $exportStatus */
         $exportStatus = Export::find()->where(['user_id' => $model->getUser(), 'object_id' => $model->object])->one();
         $exportStatus->status = Export::STATUS_PROCESS;
         $exportStatus->save();
         try {
             $object = Object::findById($model->object);
             if ($object === null) {
                 throw new Exception('Object not found');
             }
             $filename = $model->getFilename('Export');
             $import = \app\modules\data\components\Import::createInstance(['object' => $object, 'filename' => $filename, 'type' => $model->type]);
             $import->processExport($model->fields, $model->conditions);
             $exportStatus->filename = $filename;
             $exportStatus->status = Export::STATUS_COMPLETE;
             $exportStatus->save();
         } catch (\Exception $e) {
             $exportStatus->status = Export::STATUS_FAILED;
             $exportStatus->save();
             echo $e->getMessage();
             throw $e;
         }
     } else {
         echo 'Model is not valid';
         throw new Exception('Model is not valid');
     }
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:32,代码来源:FileController.php

示例4: function

 function __construct($filename)
 {
     if (is_file($filename)) {
         $this->filename = $filename;
         $xml = new \XMLReader();
         if (false !== $xml->open($filename)) {
             $this->xml = $xml;
             $rootCategory = Category::findOne(['parent_id' => 0]);
             if (empty($rootCategory)) {
                 if (null === ($rootCategory = Category::createEmptyCategory(0, null, 'Каталог'))) {
                     $this->xml->close();
                     $this->xml = null;
                 }
                 $this->rootCategoryCache = $rootCategory->id;
             } else {
                 $this->rootCategoryCache = $rootCategory->id;
             }
             if (empty(static::$propertiesCache)) {
                 static::$propertiesCache = array_reduce(CommercemlGuid::find([['>', 'model_id', 0], ['type' => 'PROPERTY']])->all(), function ($result, $item) {
                     $result[$item['guid']] = $item->property;
                     return $result;
                 }, []);
             }
             $this->objectProduct = Object::getForClass(Product::className());
         }
     }
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:27,代码来源:XmlFileReader.php

示例5: run

 public function run()
 {
     $query = Category::find();
     $query->andWhere([Category::tableName() . '.active' => 1]);
     if ($this->root_category_id !== null) {
         $query->andWhere([Category::tableName() . '.parent_id' => $this->root_category_id]);
     }
     if ($this->category_group_id !== null) {
         $query->andWhere([Category::tableName() . '.category_group_id' => $this->category_group_id]);
     }
     $query->groupBy(Category::tableName() . ".id");
     $query->orderBy($this->sort);
     if ($this->limit !== null) {
         $query->limit($this->limit);
     }
     $object = Object::getForClass(Category::className());
     \app\properties\PropertiesHelper::appendPropertiesFilters($object, $query, $this->values_by_property_id, []);
     $sql = $query->createCommand()->getRawSql();
     $cacheKey = "FilteredCategoriesWidget:" . md5($sql);
     $result = Yii::$app->cache->get($cacheKey);
     if ($result === false) {
         $categories = Category::findBySql($sql)->all();
         $result = $this->render($this->viewFile, ['categories' => $categories]);
         Yii::$app->cache->set($cacheKey, $result, 86400, new \yii\caching\TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Category::tableName())]));
     }
     return $result;
 }
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:27,代码来源:FilteredCategoriesWidget.php

示例6: actionIndex

 public function actionIndex($category_id = null)
 {
     $searchModel = new Category();
     $searchModel->active = 1;
     $params = Yii::$app->request->get();
     $dataProvider = $searchModel->search($params);
     $selectedCategory = null;
     if ($category_id !== null) {
         $selectedCategory = Category::findById($category_id);
     }
     if ($selectedCategory !== null) {
         if (Yii::$app->request->isPost === true) {
             $newProperty = isset($_GET['add_property_id']) ? Property::findById($_GET['add_property_id']) : null;
             if ($newProperty !== null) {
                 $filterSet = new FilterSets();
                 $filterSet->category_id = $selectedCategory->id;
                 $filterSet->property_id = $newProperty->id;
                 $filterSet->sort_order = 65535;
                 $filterSet->save();
             }
         }
     }
     $groups = PropertyGroup::getForObjectId(Object::getForClass(Product::className())->id, false);
     $propertiesDropdownItems = [];
     foreach ($groups as $group) {
         $item = ['label' => $group->name, 'url' => '#', 'items' => []];
         $properties = Property::getForGroupId($group->id);
         foreach ($properties as $prop) {
             $item['items'][] = ['label' => $prop->name, 'url' => '?category_id=' . $category_id . '&add_property_id=' . $prop->id, 'linkOptions' => ['class' => 'add-property-to-filter-set', 'data-property-id' => $prop->id, 'data-action' => 'post']];
         }
         $propertiesDropdownItems[] = $item;
     }
     return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'selectedCategory' => $selectedCategory, 'propertiesDropdownItems' => $propertiesDropdownItems]);
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:34,代码来源:FilterSetsController.php

示例7: actionPrint

 /**
  * @return string
  */
 public function actionPrint()
 {
     $this->layout = 'print';
     $products = ProductCompareHelper::getProductsList(true);
     $object = Object::getForClass(Product::className());
     return $this->render('print', ['error' => empty($products) || null === $object, 'message' => Yii::t('app', 'No products for comparing'), 'object' => $object, 'products' => $products]);
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:10,代码来源:ProductCompareController.php

示例8: down

 public function down()
 {
     $objects = \app\models\Object::find()->asArray()->all();
     foreach ($objects as $object) {
         $this->dropColumn($object['eav_table_name'], 'property_group_id');
     }
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:7,代码来源:m150320_080911_eav_property_group_id_add.php

示例9: cleanUpRelations

 /**
  * Delete relations
  * @return bool
  */
 public function cleanUpRelations()
 {
     if (!is_subclass_of($this->owner, '\\yii\\db\\ActiveRecord')) {
         return false;
     }
     if (isset($this->owner->is_deleted) && 0 === intval($this->owner->is_deleted)) {
         return false;
     }
     if (null === ($object = Object::getForClass($this->owner->className()))) {
         return false;
     }
     $whereDelete = ['object_id' => $object->id, 'object_model_id' => $this->owner->id];
     ObjectPropertyGroup::deleteAll($whereDelete);
     ObjectStaticValues::deleteAll($whereDelete);
     Image::deleteAll($whereDelete);
     ViewObject::deleteAll($whereDelete);
     try {
         Yii::$app->db->createCommand()->delete($object->categories_table_name, ['object_model_id' => $this->owner->id])->execute();
         Yii::$app->db->createCommand()->delete($object->column_properties_table_name, ['object_model_id' => $this->owner->id])->execute();
         Yii::$app->db->createCommand()->delete($object->eav_table_name, ['object_model_id' => $this->owner->id])->execute();
     } catch (Exception $e) {
         // do nothing
     }
     return true;
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:29,代码来源:CleanRelations.php

示例10: actionEdit

 public function actionEdit($id = null)
 {
     $model = new PrefilteredPages();
     $model->loadDefaultValues();
     if ($id !== null) {
         $model = PrefilteredPages::findOne($id);
     }
     $static_values_properties = [];
     $property_groups_ids_for_object = (new Query())->select('id')->from(PropertyGroup::tableName())->where(['object_id' => Object::getForClass(Product::className())->id])->column();
     $properties = Property::find()->andWhere(['in', 'property_group_id', $property_groups_ids_for_object])->all();
     foreach ($properties as $prop) {
         /** @var Property $prop */
         $static_values_properties[$prop->id] = ['property' => $prop, 'static_values_select' => PropertyStaticValues::getSelectForPropertyId($prop->id), 'has_static_values' => $prop->has_static_values === 1];
     }
     $post = \Yii::$app->request->post();
     if ($model->load($post) && $model->validate()) {
         $save_result = $model->save();
         if ($save_result) {
             Yii::$app->session->setFlash('info', Yii::t('app', 'Object saved'));
             $returnUrl = Yii::$app->request->get('returnUrl', ['index', 'id' => $model->id]);
             switch (Yii::$app->request->post('action', 'save')) {
                 case 'next':
                     return $this->redirect(['edit', 'returnUrl' => $returnUrl]);
                 case 'back':
                     return $this->redirect($returnUrl);
                 default:
                     return $this->redirect(Url::toRoute(['edit', 'id' => $model->id, 'returnUrl' => $returnUrl]));
             }
             //return $this->redirect(['/backend/prefiltered-pages/edit', 'id' => $model->id]);
         } else {
             \Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data'));
         }
     }
     return $this->render('prefiltered-page-form', ['model' => $model, 'static_values_properties' => $static_values_properties]);
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:35,代码来源:BackendPrefilteredPagesController.php

示例11: getData

 public function getData()
 {
     $objectClass = Object::findById($this->objectId)->object_class;
     $object = new $objectClass();
     $this->data = $object->attributeLabels();
     return parent::getData();
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:7,代码来源:filterFormFields.php

示例12: getLinks

 protected function getLinks()
 {
     if (!is_null($this->frontendLink) || !is_null($this->backendLink)) {
         return true;
     }
     /** @var Image $image */
     $image = Image::findById($this->img_id);
     if (is_null($image) || is_null($object = Object::findById($image->object_id))) {
         return false;
     }
     /** @var \app\models\Object $object */
     switch ($object->object_class) {
         case Page::className():
             $this->getPageLinks($image->object_model_id);
             break;
         case Category::className():
             $this->getCategoryLinks($image->object_model_id);
             break;
         case Product::className():
             $this->getProductLinks($image->object_model_id);
             break;
         default:
             return false;
     }
     return true;
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:26,代码来源:ErrorImage.php

示例13: unifiedAction

 /**
  * Unified action for import and export
  * @param $id
  * @param $importMode
  * @return string|\yii\web\Response
  * @throws ErrorException
  */
 private function unifiedAction($id, $importMode)
 {
     $object = Object::findById($id);
     /* @var $className \app\modules\data\models\Import */
     $className = $importMode ? 'app\\modules\\data\\models\\Import' : 'app\\modules\\data\\models\\Export';
     if ($object !== null) {
         $model = new ImportModel(['object' => $id]);
         $fields = \app\modules\data\components\Import::getFields($model->object);
         if (\Yii::$app->request->isPost) {
             if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
                 $import = $className::find()->where(['user_id' => Yii::$app->user->id, 'object_id' => $id])->one();
                 if ($import === null) {
                     $import = new $className(['user_id' => Yii::$app->user->id, 'object_id' => $id]);
                 }
                 $import->filename = null;
                 if ($importMode === true) {
                     $file = UploadedFile::getInstance($model, 'file');
                     $model->type = $file->extension;
                     $filename = $model->getFilename('Import');
                     $import->filename = $filename;
                     $fullFilename = Yii::$app->getModule('data')->importDir . '/' . $filename;
                     if ($file->saveAs($fullFilename) === false) {
                         throw new ErrorException("Unable to save file");
                     }
                 }
                 $import->status = $className::STATUS_PROCESS;
                 $task_options = Yii::$app->request->post('Task', []);
                 if ($import->save()) {
                     BackgroundTasks::addTask(['name' => $importMode ? 'import' : 'export', 'description' => ($importMode ? 'import' : 'export') . " {$model->object}", 'action' => 'data/file/' . ($importMode ? 'import' : 'export'), 'params' => $model->serialize(), 'init_event' => $importMode ? 'import' : 'export'], ['create_notification' => isset($task_options['create_notification']) && 1 == $task_options['create_notification'] ? true : false]);
                     \Yii::$app->session->setFlash('info', \Yii::t('app', 'Task is queued. Come back later.'));
                 } else {
                     \Yii::$app->session->setFlash('error', \Yii::t('app', 'Import Error'));
                 }
                 return $this->redirect(['/data/file']);
             }
         }
         $availablePropertyGroups = [];
         /** @var \app\modules\shop\models\Product $exampleModel - product for example */
         $exampleModel = new $object->object_class();
         if ($exampleModel->hasMethod('getPropertyGroups')) {
             $availablePropertyGroups = $exampleModel->getPropertyGroups(false, true);
         }
         \Yii::$app->session->setFlash('info', \Yii::t('app', 'Specify fields to import and select the file'));
         $fields['additionalFields'] = [];
         if ($exampleModel instanceof ExportableInterface) {
             $fields['additionalFields'] = $exampleModel::exportableAdditionalFields();
         }
         if ($model->type === null) {
             $model->type = Yii::$app->modules['data']->defaultType;
         }
         return $this->render('import-export', ['model' => $model, 'object' => $object, 'fields' => $fields, 'availablePropertyGroups' => $availablePropertyGroups, 'importMode' => $importMode]);
     } else {
         \Yii::$app->session->setFlash('error', \Yii::t('app', 'Object not found'));
         return $this->redirect(['/data/file']);
     }
 }
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:63,代码来源:FileController.php

示例14: down

 public function down()
 {
     $this->dropTable('{{%special_price_list_type}}');
     $this->dropTable('{{%special_price_object}}');
     $this->dropColumn('{{%special_price_list}}', 'type_id');
     $this->addColumn('{{%special_price_list}}', 'type', "ENUM('core', 'discount', 'delivery', 'project') DEFAULT 'project'");
     $this->update('{{%special_price_list}}', ['type' => 'core'], ['class' => 'app\\modules\\shop\\models\\Currency', 'object_id' => Object::getForClass(Product::className())->id]);
     $this->update('{{%special_price_list}}', ['type' => 'discount'], ['class' => 'app\\modules\\shop\\models\\Discount', 'object_id' => Object::getForClass(Product::className())->id]);
     $this->delete('{{%special_price_list}}', ['class' => 'app\\modules\\shop\\models\\Discount', 'object_id' => Object::getForClass(Order::className())->id]);
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:10,代码来源:m150519_120719_spetial_price_order.php

示例15: getBindedAddons

 public function getBindedAddons()
 {
     $object_id = Object::getForClass($this->className())->id;
     return $this->hasMany(Addon::className(), ['id' => 'addon_id'])->viaTable('{{%addon_bindings}}', ['object_model_id' => 'id'], function ($query) use($object_id) {
         /** @var \yii\db\Query $query */
         $query->andWhere(['appliance_object_id' => $object_id]);
         $query->orderBy(['sort_order' => SORT_ASC]);
         return $query;
     })->innerJoin('{{%addon_bindings}}', 'addon_id=addon.id AND appliance_object_id=:aoid AND object_model_id=:oid', [':aoid' => $object_id, ':oid' => $this->id])->orderBy(['addon_bindings.sort_order' => SORT_ASC]);
 }
开发者ID:lzpfmh,项目名称:dotplant2,代码行数:10,代码来源:HasAddonTrait.php


注:本文中的app\models\Object类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。