public function up() { $submissionObject = Object::getForClass(\app\models\Submission::className()); /** @var PropertyHandler $propertyHandler */ $propertyHandler = PropertyHandler::findOne(['name' => 'Text']); $this->addColumn(Review::tableName(), 'submission_id', 'INT UNSIGNED NOT NULL'); $form = new \app\models\Form(); $form->name = 'Review form'; $form->email_notification_addresses = ''; $form->email_notification_view = '@app/modules/review/views/review-email-template.php'; $form->save(false, ['name', 'email_notification_addresses', 'email_notification_view']); $propertyGroup = new PropertyGroup(); $propertyGroup->attributes = ['object_id' => $form->object->id, 'name' => 'Review form additional properties', 'hidden_group_title' => 1]; $propertyGroup->save(true, ['object_id', 'name', 'hidden_group_title']); $nameProperty = new Property(); $nameProperty->attributes = ['property_group_id' => $propertyGroup->id, 'name' => 'Name', 'key' => 'name', 'property_handler_id' => $propertyHandler->id, 'handler_additional_params' => '{}', 'is_eav' => 1]; $nameProperty->save(true, ['property_group_id', 'name', 'key', 'property_handler_id', 'is_eav', 'handler_additional_params']); $phoneProperty = new Property(); $phoneProperty->attributes = ['property_group_id' => $propertyGroup->id, 'name' => 'Phone', 'key' => 'phone', 'property_handler_id' => $propertyHandler->id, 'handler_additional_params' => '{}', 'is_eav' => 1]; $phoneProperty->save(true, ['property_group_id', 'name', 'key', 'property_handler_id', 'is_eav', 'handler_additional_params']); $objectPropertyGroup = new ObjectPropertyGroup(); $objectPropertyGroup->attributes = ['object_id' => $form->object->id, 'object_model_id' => $form->id, 'property_group_id' => $propertyGroup->id]; $objectPropertyGroup->save(true, ['object_id', 'object_model_id', 'property_group_id']); $reviews = Review::find()->all(); foreach ($reviews as $review) { $submission = new \app\models\Submission(); $submission->form_id = $form->id; $submission->processed_by_user_id = $review->author_user_id; $submission->date_received = $review->date_submitted; $submission->save(false, ['form_id', 'processed_by_user_id', 'date_received']); $review->submission_id = $this->db->lastInsertID; $review->save(true, ['submission_id']); $this->insert(ObjectPropertyGroup::tableName(), ['object_id' => $submissionObject->id, 'object_model_id' => $submission->id, 'property_group_id' => $propertyGroup->id]); $this->insert($submissionObject->eav_table_name, ['object_model_id' => $submission->id, 'property_group_id' => $propertyGroup->id, 'key' => $nameProperty->key, 'value' => $review->author_name]); $this->insert($submissionObject->eav_table_name, ['object_model_id' => $submission->id, 'property_group_id' => $propertyGroup->id, 'key' => $phoneProperty->key, 'value' => $review->author_phone]); } $this->dropColumn(Review::tableName(), 'date_submitted'); $this->dropColumn(Review::tableName(), 'author_user_id'); $this->dropColumn(Review::tableName(), 'author_name'); $this->dropColumn(Review::tableName(), 'author_phone'); $this->dropColumn(Review::tableName(), 'rate'); $this->renameColumn(Review::tableName(), 'text', 'review_text'); $this->alterColumn(Review::tableName(), 'rating_id', 'CHAR(32)'); $this->update(BackendMenu::tableName(), ['route' => 'review/backend-rating/index'], ['route' => 'backend/rating/index']); $this->update(BackendMenu::tableName(), ['route' => 'review/backend-review/index'], ['name' => 'Reviews']); $this->delete(BackendMenu::tableName(), ['route' => ['review/backend/products', 'review/backend/pages']]); $this->alterColumn(RatingValues::tableName(), 'rating_id', 'CHAR(32) NOT NULL'); $this->alterColumn(RatingValues::tableName(), 'object_id', 'INT UNSIGNED NOT NULL'); $this->alterColumn(RatingValues::tableName(), 'object_model_id', 'INT UNSIGNED NOT NULL'); $this->alterColumn(RatingValues::tableName(), 'rating_item_id', 'INT UNSIGNED NOT NULL'); $this->alterColumn(RatingValues::tableName(), 'user_id', 'INT UNSIGNED NOT NULL'); $this->createIndex('ix-rating_values-rating_id', RatingValues::tableName(), 'rating_id'); $this->createIndex('ix-rating_values-object_id-object_model_id', RatingValues::tableName(), ['object_id', 'object_model_id']); $this->createIndex('ix-rating_item-rating_group', RatingItem::tableName(), 'rating_group'); }
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]); }
private function getValues($model) { /** @var $model Product */ $params = ''; $eav = Yii::$app->getDb()->cache(function ($db) use($model) { return (new Query())->from($model->object->eav_table_name)->select(Property::tableName() . '.id, ' . $model->object->eav_table_name . '.value')->innerJoin(Property::tableName(), Property::tableName() . '.property_group_id = ' . $model->object->eav_table_name . '.property_group_id' . ' AND ' . Property::tableName() . '.key = ' . $model->object->eav_table_name . '.key')->where(['object_model_id' => $model->id, $model->object->eav_table_name . '.key' => array_column(static::$ymlEavProperties, 'key'), $model->object->eav_table_name . '.property_group_id' => array_column(static::$ymlEavProperties, 'group_id'), Property::tableName() . '.id' => array_keys(static::$ymlEavProperties)])->andWhere(['<>', 'value', ''])->all(); }); foreach ($eav as $prop) { if (false === isset($prop['id'])) { continue; } $unit = empty(static::$ymlEavProperties[$prop['id']]['unit']) ? '' : ' unit="' . static::$ymlEavProperties[$prop['id']]['unit'] . '"'; $val = htmlspecialchars($prop['value']); switch (static::$ymlEavProperties[$prop['id']]['handler_id']) { case 3: $val = $val == 1 ? Yii::t('yii', 'Yes') : Yii::t('yii', 'No'); break; } $params .= '<param name="' . static::$ymlEavProperties[$prop['id']]['name'] . '"' . $unit . '>' . $val . '</param>' . PHP_EOL; } $psv = Yii::$app->getDb()->cache(function ($db) use($model) { return (new Query())->from(PropertyStaticValues::tableName())->innerJoin(ObjectStaticValues::tableName(), ObjectStaticValues::tableName() . '.property_static_value_id = ' . PropertyStaticValues::tableName() . '.id')->where(['object_model_id' => $model->id, 'object_id' => $model->object->id, 'property_id' => array_keys(static::$ymlStaticProperties)])->andWhere(['<>', 'value', ''])->all(); }); foreach ($psv as $prop) { if (false === isset($prop['property_id'])) { continue; } $unit = empty(static::$ymlStaticProperties[$prop['property_id']]['unit']) ? '' : ' unit="' . static::$ymlStaticProperties[$prop['property_id']]['unit'] . '"'; $params .= '<param name="' . static::$ymlStaticProperties[$prop['property_id']]['name'] . '"' . $unit . '>' . htmlspecialchars($prop['value']) . '</param>' . PHP_EOL; } return $params; }
public function actionEdit($id = null) { $model = new DynamicContent(); $model->loadDefaultValues(); if ($id !== null) { $model = DynamicContent::findOne($id); } $static_values_properties = []; if (isset($_GET['DynamicContent'])) { if (isset($_GET['DynamicContent']['object_id'])) { $model->object_id = intval($_GET['DynamicContent']['object_id']); } } $property_groups_ids_for_object = (new Query())->select('id')->from(PropertyGroup::tableName())->where([])->column(); $properties = Property::find()->where(['has_static_values' => 1, 'has_slugs_in_values' => 1])->andWhere(['in', 'property_group_id', $property_groups_ids_for_object])->all(); foreach ($properties as $prop) { $static_values_properties[$prop->id] = ['has_static_values' => true, 'property' => $prop, 'static_values_select' => PropertyStaticValues::getSelectForPropertyId($prop->id)]; } $post = \Yii::$app->request->post(); if (isset($_GET['DynamicContent'])) { $post = $_GET; } if ($model->load($post) && $model->validate() && !isset($_GET['DynamicContent'])) { $save_result = $model->save(); if ($save_result) { return $this->redirectUser($model->id); } else { \Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data')); } } return $this->render('dynamic-content-form', ['model' => $model, 'static_values_properties' => $static_values_properties]); }
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]); }
/** * Renders the widget. * * @return string */ public function run() { if ($this->type == 'list') { $items = []; foreach ($this->model->options as $option) { $items[] = $option->name; } return $this->render($this->listView, ['items' => $items, 'model' => $this->model]); } else { $propertyGroup = Json::decode($this->model->option_generate)['group']; $items = []; $optionsJson = []; foreach ($this->model->options as $option) { $optionProperties = $option->getPropertyGroups()[$propertyGroup]; $itemsJson = []; foreach ($optionProperties as $key => $property) { foreach ($property->values as $name => $propValue) { if (!isset($items[$key])) { $items[$key] = ['name' => Property::findById($propValue['property_id'])->name]; } if (!isset($firstOption)) { $firstOption[$key] = $propValue['psv_id']; } $items[$key]['values'][$propValue['psv_id']] = $propValue['name']; $itemsJson[$key] = $propValue['psv_id']; } } $optionsJson[] = ['id' => $option->id, 'values' => $itemsJson, 'price' => $option->convertedPrice(), 'old_price' => $option->convertedPrice(null, true)]; } return $this->render($this->formView, ['model' => $this->model, 'items' => $items, 'optionsJson' => $optionsJson]); } }
/** * @inheritdoc */ public function getNextPart($full_url, $next_part, &$previous_parts) { $property = Property::findById($this->property_id); if (is_null($property)) { return false; } if ($property->has_static_values && $property->has_slugs_in_values) { $cacheTags = []; $static_values = PropertyStaticValues::getValuesForPropertyId($this->property_id); $slugs = explode('/', $next_part); foreach ($static_values as $value) { if ($slugs[0] === $value['slug']) { $this->parameters = ['properties' => [$this->property_id => [$value['id']]]]; if (!empty($value['title_append'])) { $this->parameters['title_append'] = [$value['title_append']]; } $cacheTags[] = ActiveRecordHelper::getObjectTag(PropertyStaticValues::className(), $value['id']); $part = new self(['gathered_part' => $value['slug'], 'rest_part' => mb_substr($next_part, mb_strlen($value['slug'])), 'parameters' => $this->parameters, 'cacheTags' => $cacheTags]); return $part; } } return false; } else { return false; } }
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]); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Factory::create(); for ($i = 0; $i < 100; $i++) { \App\Models\Property::create(['user_id' => $faker->randomElement([1, 2, 3, 4]), 'property_url' => $faker->url, 'image' => $faker->imageUrl(242, 162), 'property_title' => $faker->sentence, 'bid_price' => $faker->randomFloat(null, 1000, 100000), 'location' => $faker->address . ', ' . $faker->city . ', ' . $faker->country, 'lat' => $faker->latitude, 'lng' => $faker->longitude, 'city_id' => $faker->randomElement([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 'bid_start_date_time' => Carbon::now()->addMinutes(($i + 1) * 5), 'bid_close_date_time' => Carbon::now()->addMinutes(($i + 1) * 10)]); } }
public function beforeAction($action) { $storeName = Property::getPropertyValue('store_name', ''); Yii::$app->view->title = Property::getPropertyValue('store_title', $storeName); Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => Property::getPropertyValue('store_description', $storeName)], 'description'); Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => Property::getPropertyValue('store_keywords', $storeName)], 'keywords'); return parent::beforeAction($action); }
public function up() { $this->insert('{{%theme_active_widgets}}', ['part_id' => 5, 'widget_id' => 5, 'variation_id' => 2]); $propertyId1 = \app\models\Property::find()->where(['key' => 'tip_pamyati'])->select('id')->scalar(); $propertyId2 = \app\models\Property::find()->where(['key' => 'tip_ekrana'])->select('id')->scalar(); $this->insert('{{%filter_sets}}', ['category_id' => 3, 'sort_order' => 2, 'property_id' => $propertyId2]); $this->insert('{{%filter_sets}}', ['category_id' => 3, 'sort_order' => 1, 'property_id' => $propertyId1]); }
public function getTitle($lang = null) { if (empty($lang)) { $lang = Property::getDefaultLanguage(); } $model = $this->getBlockLang($lang); return !is_null($model) ? $model->title : null; }
public function getPropertyList($user_id, $date) { $query = Property::where('user_id', '<>', $user_id); if (empty($date)) { $query->where('bid_start_date_time', '>', Carbon::now())->orWhere('bid_close_date_time', '>', Carbon::now()); } return $query->orderBy('bid_start_date_time', 'asc')->get(); }
public function actionProperties() { if (isset($_REQUEST['properties']) && is_array($_REQUEST['properties'])) { foreach ($_REQUEST['properties'] as $propID => $propValue) { Property::setPropertyValue($propID, $propValue); } } return $this->render('properties'); }
/** * AuthorizeNetCIM constructor. */ public function __construct() { $this->loginName = Property::getPropertyValue('authorize_login'); $this->transactionKey = Property::getPropertyValue('authorize_key'); if (Property::getPropertyValue('authorize_live', 'no') == 'yes') { $this->apiHost = 'api.authorize.net'; $this->apiMode = 'liveMode'; } }
public function getData() { $query = new Query(); $query->select(Property::tableName() . '.id, ' . Property::tableName() . '.name')->from(Property::tableName()); $query->leftJoin(PropertyGroup::tableName(), PropertyGroup::tableName() . '.id = ' . Property::tableName() . '.property_group_id'); $query->andWhere([PropertyGroup::tableName() . '.object_id' => $this->objectId]); $command = $query->createCommand(); $this->data = ArrayHelper::map($command->queryAll(), 'id', 'name'); return parent::getData(); }
public function generateEmailForgotPassword() { if (!empty($emailTo = $this->email)) { $mail = new Mail(); $mail->to = $emailTo; $mail->subject = Yii::t('app', 'Information from {store_name}', ['store_name' => Property::getPropertyValue('store_name', '')]); $mail->body = StoreUtils::renderView('//mail/_destination_forgot_password', ['model' => $this]); $mail->save(); } }
/** * * @return Response */ public function show($id) { $owner = Owner::findOrFail($id); $owner->Properties = $owner->Properties; foreach ($owner->Properties as $property) { $allTransactions = Property::find($property->id)->allTransactions(); $property->transactions = $allTransactions; } return \Response::json(['success' => true, 'message' => 'Owners Loaded.', 'data' => $owner]); }
protected function getProperties() { $result = []; $query = new Query(); $query->select(Property::tableName() . '.key, ' . Property::tableName() . '.name')->from(Property::tableName()); $query->innerJoin(PropertyGroup::tableName(), PropertyGroup::tableName() . '.id = ' . Property::tableName() . '.property_group_id'); $query->andWhere([PropertyGroup::tableName() . '.object_id' => $this->object->id]); $command = $query->createCommand(); return ArrayHelper::map($command->queryAll(), 'key', 'name'); }
/** * @inheritdoc * @param int $id * @return int|mixed * @throws NotFoundHttpException */ public function run($id) { /** @var Form|HasProperties $form */ if (null === ($form = Form::findById($id))) { throw new NotFoundHttpException(); } $post = Yii::$app->request->post(); $form->abstractModel->setAttrubutesValues($post); /** @var AbstractModel|SpamCheckerBehavior $model */ $model = $form->getAbstractModel(); if (Yii::$app->request->isAjax && isset($post['ajax'])) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } /** @var \app\models\Object $object */ $object = Object::getForClass(Form::className()); $propGroups = ObjectPropertyGroup::find()->where(['and', 'object_id = :object', 'object_model_id = :id'], [':object' => $object->id, ':id' => $id])->asArray()->all(); $propIds = ArrayHelper::getColumn($propGroups, 'property_group_id'); // Spam checking $activeSpamChecker = SpamChecker::getActive(); $data = []; $haveSpam = false; if ($activeSpamChecker !== null && !empty($activeSpamChecker->api_key)) { $data[$activeSpamChecker->name]['class'] = $activeSpamChecker->behavior; $data[$activeSpamChecker->name]['value']['key'] = $activeSpamChecker->api_key; $properties = Property::getForGroupId($propIds[0]); foreach ($properties as $prop) { if (!isset($activeSpamChecker->{$prop->interpret_as}) || empty($activeSpamChecker->{$prop->interpret_as})) { continue; } $data[$activeSpamChecker->name]['value'][$activeSpamChecker->{$prop->interpret_as}] = is_array($post[$form->abstractModel->formName()][$prop->key]) ? implode(' ', $post[$form->abstractModel->formName()][$prop->key]) : $post[$form->abstractModel->formName()][$prop->key]; } $model->attachBehavior('spamChecker', ['class' => SpamCheckerBehavior::className(), 'data' => $data]); $haveSpam = $model->isSpam(); } $date = new \DateTime(); /** @var Submission|HasProperties $submission */ $submission = new Submission(['form_id' => $form->id, 'date_received' => $date->format('Y-m-d H:i:s'), 'ip' => Yii::$app->request->userIP, 'user_agent' => Yii::$app->request->userAgent, 'spam' => (int) $haveSpam]); if (false === Yii::$app->user->isGuest) { $submission->processed_by_user_id = Yii::$app->user->identity->getId(); } if (!($form->abstractModel->validate() && $submission->save())) { return "0"; } if (isset($post[$form->abstractModel->formName()])) { $data = ['AddPropetryGroup' => [$submission->formName() => array_keys($form->getPropertyGroups())], $submission->abstractModel->formName() => $post[$form->abstractModel->formName()]]; if (isset($_FILES[$form->abstractModel->formName()])) { $_FILES[$submission->abstractModel->formName()] = $_FILES[$form->abstractModel->formName()]; } $submission->saveProperties($data); } return $submission->id; }
/** * @return mixed */ public function store() { $input = \Request::all(); $validator = \Validator::make($input, ['property_id' => 'required', 'unit_name' => 'required|max:255']); if ($validator->fails()) { \App::abort(400, $validator->messages()->first()); } $unit = new Unit($input); $property = Property::find($input['property_id']); $unit = $property->Units()->save($unit); return \Response::json(['success' => true, 'message' => 'Unit Created.', 'data' => $unit]); }
/** * Sends an email to the specified email address using the information collected by this model. * @param string $email the target email address * @return boolean whether the model passes validation */ public function contact($email) { if ($this->validate()) { $mail = new Mail(); $mail->subject = Yii::t('app', 'Comment received on {store}', ['store' => Property::getPropertyValue('store_name', '')]); $mail->body = StoreUtils::renderView('//mail/_comment', ['model' => $this]); $mail->to = $email; $mail->save(); return true; } return false; }
/** * @param null $property_id * @param null $handler_action * @param null $model_id * @return mixed */ public function run($property_id = null, $handler_action = null, $model_id = null) { if (null === $handler_action || null === $property_id || null === $model_id) { return ''; } $property = Property::findById($property_id); if (null === $property) { return ''; } $actionParams = ['model_name' => $this->modelName, 'model_id' => $model_id, 'object_id' => $this->objectId, 'property' => $property]; $propertyHandler = PropertyHandlers::createHandler($property->handler); return $propertyHandler->runAction($handler_action, $actionParams); }
public function delete($id) { return Property::destroy($id); // $delSuccess = Property::destroy($id); // if ($delSuccess) { // $images[] = Image::where('propertyId', $id)->get(); // //unlink the image. // foreach ($images as $key => $filename) { // $imagePath = base_path() .'/public/uploads/' . $filename[0]->filename; // if (file_exists($imagePath)) { // unlink($imagePath); // } // } // } }
/** * Updates an existing Banner model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { foreach (Property::getLanguages() as $lang) { $file = UploadedFile::getInstanceByName('image_' . $lang); if (!is_null($file)) { ImageManager::addBannerImage($model->id, $file, $lang); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }
/** * @inheritdoc */ public function getNextPart($full_url, $next_part, &$previous_parts) { $property = Property::findById($this->property_id); if (is_null($property)) { return false; } if ($property->has_static_values && $property->has_slugs_in_values) { $cacheTags = []; $static_values = PropertyStaticValues::getValuesForPropertyId($this->property_id); $slugs = explode('/', $next_part); $currentSlug = 0; $slugsCount = count($slugs); $appliedParts = []; foreach ($static_values as $value) { if ($slugs[$currentSlug] === $value['slug']) { $appliedParts[] = $value['slug']; if (isset($this->parameters['properties'][$this->property_id])) { $this->parameters['properties'][$this->property_id][] = $value['id']; } else { $this->parameters = ['properties' => [$this->property_id => [$value['id']]]]; } if (!empty($value['title_append'])) { if ($value["title_prepend"] == 1) { $this->addParam("title_prepend", $value["title_append"]); } else { $this->addParam("title_append", $value["title_append"]); } } $cacheTags[] = ActiveRecordHelper::getObjectTag(PropertyStaticValues::className(), $value['id']); $currentSlug++; if ($currentSlug == $slugsCount) { break; } } } if ($currentSlug > 0) { $appliedPartsString = implode('/', $appliedParts); $part = new self(['gathered_part' => $appliedPartsString, 'rest_part' => mb_substr($next_part, mb_strlen($appliedPartsString)), 'parameters' => $this->parameters, 'cacheTags' => $cacheTags]); return $part; } return false; } else { return false; } }
public function up() { $objects = \app\models\Object::find()->asArray()->all(); foreach ($objects as $object) { if ($object['name'] == 'Submission') { continue; } else { if ($object['name'] == 'Form') { $submissionObject = \app\models\Object::findOne(['name' => 'Submission']); $this->addColumn($object['eav_table_name'], 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`'); $this->addColumn($submissionObject->eav_table_name, 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`'); $groups = \app\models\PropertyGroup::find()->where(['object_id' => $object['id']])->asArray()->all(); foreach ($groups as $group) { $forms = \app\models\ObjectPropertyGroup::find()->select('object_model_id')->where(['property_group_id' => $group['id']])->asArray()->all(); $formIDs = []; foreach ($forms as $formID) { if (!in_array($formID['object_model_id'], $formIDs)) { $formIDs[] = $formID['object_model_id']; } } $submissionIDs = \app\models\Submission::find()->select('id')->where(['form_id' => $formIDs])->asArray()->all(); $subIDs = []; foreach ($submissionIDs as $submission) { $subIDs[] = $submission['id']; } $properties = \app\models\Property::find()->select(['id', 'key'])->where(['property_group_id' => $group['id'], 'is_eav' => 1])->asArray()->all(); foreach ($properties as $property) { $this->update($submissionObject->eav_table_name, ['property_group_id' => $group['id']], ['key' => $property['key']]); } } } else { $this->addColumn($object['eav_table_name'], 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`'); $groups = \app\models\PropertyGroup::find()->where(['object_id' => $object['id']])->asArray()->all(); foreach ($groups as $group) { $properties = \app\models\Property::find()->select(['id', 'key'])->where(['property_group_id' => $group['id'], 'is_eav' => 1])->asArray()->all(); foreach ($properties as $property) { $this->update($object['eav_table_name'], ['property_group_id' => $group['id']], ['key' => $property['key']]); } } } } } }
/** * @inheritdoc */ public function run() { $this->object = Object::getForClass(get_class($this->model)); $cacheKey = 'PropertiesWidget: ' . get_class($this->model) . ':' . $this->model->id; $data = Yii::$app->cache->get($cacheKey); if ($data === false) { $this->objectPropertyGroups = ObjectPropertyGroup::getForModel($this->model); $addedPropertyGroupsIds = []; foreach ($this->objectPropertyGroups as $opg) { $addedPropertyGroupsIds[] = $opg->property_group_id; } $restPg = (new Query())->select('id, name')->from(PropertyGroup::tableName())->where(['object_id' => $this->object->id])->andWhere(['not in', 'id', $addedPropertyGroupsIds])->orderBy('sort_order')->all(); $this->propertyGroupsToAdd = ArrayHelper::map($restPg, 'id', 'name'); Yii::$app->cache->set($cacheKey, ['objectPropertyGroups' => $this->objectPropertyGroups, 'propertyGroupsToAdd' => $this->propertyGroupsToAdd], 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(get_class($this->model)), ActiveRecordHelper::getCommonTag(PropertyGroup::className()), ActiveRecordHelper::getCommonTag(Property::className())]])); } else { $this->objectPropertyGroups = $data['objectPropertyGroups']; $this->propertyGroupsToAdd = $data['propertyGroupsToAdd']; } return $this->render($this->viewFile, ['model' => $this->model, 'object' => $this->object, 'object_property_groups' => $this->objectPropertyGroups, 'property_groups_to_add' => $this->propertyGroupsToAdd, 'form' => $this->form, 'widget_id' => $this->getId()]); }
protected static function getRelation($model, $relationName, $default_value = '') { $result = $default_value; $relation = self::$modelSetting->{$relationName}; if ($relation['type'] === 'field' && !empty($relation['key'])) { try { $result = $model->{$relation['key']}; } catch (Exception $e) { } } elseif ($relation['type'] === 'property' && !empty($relation['key'])) { try { $propertyKey = Property::find()->select('key')->where(['id' => $relation['key']])->asArray()->scalar(); $result = $model->property($propertyKey); } catch (Exception $e) { } } elseif ($relation['type'] === 'relation' && !empty($relation['key']) && !empty($relation['value'])) { $relModel = $model->{$relation['key']}(); $result = $relModel->{$relation}['value']; } return $result; }
public function postLogin(Request $request) { $messages = ['username.required' => 'กรุณาใส่รหัสผู้ใช้', 'username.exists' => 'ไม่มีรหัสผู้ใช้ดังกล่าวในระบบ', 'password.required' => 'กรุณาใส่พาสเวิร์ด']; $validator = Validator::make($request->all(), ['username' => 'required|exists:ch_employee,username', 'password' => 'required'], $messages); //$request->session()->put('data', 'value'); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } if (Session::has('hotel')) { $property = Property::where("code", '=', Session::get('hotel'))->first(); if ($property) { $member = $property->employees()->where("username", "=", $request->username)->first(); if (Hash::check($request->password, $member->password)) { $request->session()->put('member', $member); return redirect('/property'); } else { return redirect()->back()->withErrors(['พาสเวิร์ดหรือชื่อผู้ใช้ของคุณไม่สัมพันธ์กัน'])->withInput(); } } } return redirect('/'); }