Esempio n. 1
0
 /**
  * Creates a new Page model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Page();
     $model->language = Language::getCurrent();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'layouts' => Page::getLayouts(), 'templates' => Page::getTemplates(), 'active' => Page::getActiveList()]);
     }
 }
Esempio n. 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Page::find()->where(['language' => Language::getCurrent()]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'layout', $this->layout])->andFilterWhere(['like', 'template', $this->template])->andFilterWhere(['like', 'active', $this->active]);
     return $dataProvider;
 }
Esempio n. 3
0
 /**
  * @param string $route
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionRoute($route = 'index')
 {
     /* @var $dp Page */
     $page = Page::parse($route);
     $dp = Page::find()->where('name = :name AND active = :active AND language = :language', [':name' => $page, ':active' => Page::ACTIVE_YES, ':language' => Language::getCurrent()])->one();
     if ($dp === null) {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
     }
     $this->registerLayout($dp->layout);
     return $this->render($dp->template, ['dp' => $dp]);
 }
Esempio n. 4
0
 /**
  * @param array|string $params
  * @return string
  */
 public function createUrl($params)
 {
     $params = (array) $params;
     $language = isset($params['language']) ? $params['language'] : Language::getCurrent();
     if (!Language::isLanguage($language)) {
         $language = Language::getCurrent();
     }
     unset($params['route'], $params['language']);
     $params['0'] = $language . '/' . trim($params['0'], '/');
     return parent::createUrl($params);
 }
Esempio n. 5
0
 /**
  * Updates an existing I18nSource model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $i18nSource = $this->findModel($id);
     $i18nMessage = I18nMessage::find()->where(['id' => $id, 'language' => Language::getCurrent()])->one();
     if (Yii::$app->request->isPost) {
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $i18nSource->load(Yii::$app->request->post());
             if ($i18nSource->save()) {
                 $i18nMessage->load(Yii::$app->request->post());
                 if ($i18nMessage->save()) {
                     $transaction->commit();
                 }
             }
             return $this->redirect(['view', 'id' => $id]);
         } catch (\Exception $e) {
             $transaction->rollBack();
             return $this->redirect(['update', 'id' => $id]);
         }
     }
     return $this->render('update', ['i18nSource' => $i18nSource, 'i18nMessage' => $i18nMessage]);
 }
Esempio n. 6
0
File: Magic.php Progetto: apurey/cmf
 public function registerUploadDir()
 {
     $this->uploadDir = $this->uploadDir . DIRECTORY_SEPARATOR . Language::getCurrent();
     FileHelper::createDirectory(Yii::getAlias('@webroot' . DIRECTORY_SEPARATOR . $this->uploadDir), 0777, true);
 }
Esempio n. 7
0
 /**
  * @return string
  */
 public function run()
 {
     return Json::encode(ArrayHelper::merge([['name' => Yii::t('imperavi', 'Link to the page'), 'url' => '#']], ArrayHelper::getColumn(Page::find()->where(['language' => Language::getCurrent()])->asArray()->all(), function ($row) {
         return ['name' => $row['title'], 'url' => Yii::$app->getUrlManager()->createUrl($row['name'])];
     })));
 }
Esempio n. 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getI18nMessage()
 {
     return $this->hasOne(I18nMessage::className(), ['id' => 'id'])->where(['language' => Language::getCurrent()]);
 }