Пример #1
0
 public function init()
 {
     self::$modelSetting = new GoogleFeed();
     self::$modelSetting->loadConfig();
     $this->handlers = Json::decode(self::$modelSetting->feed_handlers);
     foreach ($this->handlers as $handler) {
         if (is_subclass_of($handler, ModificationDataInterface::class)) {
             $this->on(self::MODIFICATION_DATA, [$handler, 'processData']);
         }
     }
     parent::init();
     if ($this->mainCurrency === null) {
         $this->mainCurrency = Currency::findOne(['iso_code' => self::$modelSetting->shop_main_currency]);
     }
     if ($this->host === null) {
         $this->host = self::$modelSetting->shop_host;
     }
     if ($this->title === null) {
         $this->title = self::$modelSetting->shop_name;
     }
     if ($this->description === null) {
         $this->description = self::$modelSetting->shop_description;
     }
     if ($this->fileName === null) {
         $this->fileName = self::$modelSetting->feed_file_name;
     }
 }
 public function actionEdit($id = null)
 {
     $model = new Currency();
     $model->loadDefaultValues();
     if ($id !== null) {
         $model = Currency::findOne($id);
     }
     $post = \Yii::$app->request->post();
     if ($model->load($post) && $model->validate() && !isset($_GET['Currency'])) {
         $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]));
             }
         } else {
             \Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data'));
         }
     }
     return $this->render('currency-form', ['model' => $model]);
 }
Пример #3
0
 /**
  * Returns model instance by ID using IdentityMap
  * @param integer $id
  * @return Currency
  */
 public static function findById($id)
 {
     if (!isset(static::$identity_map[$id])) {
         static::$identity_map[$id] = Yii::$app->cache->get('Currency: ' . $id);
         if (static::$identity_map[$id] === false) {
             static::$identity_map[$id] = Currency::findOne($id);
             if (is_object(static::$identity_map[$id])) {
                 Yii::$app->cache->set('Currency: ' . $id, static::$identity_map[$id], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(Currency::className(), $id)]]));
             }
         }
     }
     return static::$identity_map[$id];
 }