Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CmsPages::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'is_active' => $this->is_active, 'sort_order' => $this->sort_order]);
     $query->andFilterWhere(['like', 'cms_pages_lang.title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'content_heading', $this->content_heading])->andFilterWhere(['like', 'identifier', $this->identifier])->andFilterWhere(['like', 'code_id', $this->code_id])->andFilterWhere(['like', 'category_id', $this->category_id])->andFilterWhere(['like', 'mapping_id', $this->mapping_id])->andFilterWhere(['like', 'meta_keywords', $this->meta_keywords])->andFilterWhere(['like', 'meta_description', $this->meta_description]);
     $query->joinWith(['cmsPagesLangs' => function ($query) {
         $query->where(['language' => Yii::$app->language]);
     }]);
     return $dataProvider;
 }
Example #2
0
 public function actionMapping_old_171115()
 {
     if (!Yii::$app->user->isGuest) {
         $user = Yii::$app->getUser()->getIdentity();
         //@TODO new logic to find out if there are answers
         /*$answers = MembersQuestionsAnswers::find(['member_id' => $user->id])->count();
         
                     if ($answers > 0) {
                         $user->status = User::STATUS_ACTIVE;
         
                         if ($user->save()) {
                             return Yii::$app->response->redirect(array('members/index'));
                         } else {
                             Yii::$app->getSession()->setFlash('warning', Yii::t('errors', 'Can not update user status. Please contact system administrator'));
                         }
                     }*/
         $settingsModel = GeneralSettings::findOne(['name' => 'mapping_page_id']);
         $pageModel = CmsPages::findOne(['id' => $settingsModel->value]);
         $categoryModel = MappingCategories::findOne(['id' => $pageModel->mapping_id]);
         $attributesModel = MembersAttributes::findAll(['id' => $categoryModel->attributes_id]);
         $questionsModel = MappingQuestions::find(['category_id' => $categoryModel->id])->with('fieldsTypes')->all();
         $questionsAnswers = new MembersQuestionsAnswers($pageModel->category_id);
         $attributesAnswers = new MembersAttributesAnswers($categoryModel->attributes_id);
         if (Yii::$app->request->post()) {
             $mappingQuestionsSaved = false;
             $mappingAttributesSaved = false;
             if ($questionsAnswers->load(Yii::$app->request->post()) && $questionsAnswers->validate()) {
                 foreach ($questionsAnswers->attributes as $attribute_id => $attribute) {
                     $attributesArray = explode('_', $attribute_id);
                     if (count($attributesArray) > 1) {
                         list($name, $id) = $attributesArray;
                         if (!($model = MembersQuestionsAnswers::findOne(['question_id' => $id, 'member_id' => Yii::$app->getUser()->id]))) {
                             $model = new MembersQuestionsAnswers();
                         }
                         $has_option = false;
                         if ($questionsModel = MappingQuestions::findOne($id)) {
                             $type_id = $questionsModel->type_id;
                             $has_option = FieldsTypes::findOne($type_id)->has_options;
                         }
                         if ($has_option) {
                             $model->value = '';
                             $model->option_id = '';
                             if ($optionsModel = MappingQuestionsToOptions::findOne($questionsAnswers->{$attribute_id})) {
                                 $model->value = $optionsModel->title;
                                 $model->option_id = $optionsModel->id;
                             }
                         } else {
                             $model->value = $questionsAnswers->{$attribute_id};
                         }
                         $model->question_id = $id;
                         $model->member_id = Yii::$app->getUser()->id;
                         $model->save();
                     }
                 }
                 $mappingQuestionsSaved = true;
             }
             if ($attributesAnswers->load(Yii::$app->request->post()) && $attributesAnswers->validate()) {
                 foreach ($attributesAnswers->attributes as $attribute_id => $attribute) {
                     $attributesArray = explode('_', $attribute_id);
                     if (count($attributesArray) > 1) {
                         list($name, $id) = $attributesArray;
                         if (!($model = MembersAttributesAnswers::findOne(['attribute_id' => $id, 'member_id' => Yii::$app->getUser()->id]))) {
                             $model = new MembersAttributesAnswers();
                         }
                         $has_option = false;
                         if ($questionsModel = MembersAttributes::findOne($id)) {
                             $type_id = $questionsModel->type_id;
                             $has_option = FieldsTypes::findOne($type_id)->has_options;
                             $filedTypeTitle = FieldsTypes::findOne($type_id)->title;
                         }
                         if ($has_option) {
                             $model->value = '';
                             $model->option_id = '';
                             if ($optionsModel = MembersAttributesToOptions::findOne($attributesAnswers->{$attribute_id})) {
                                 $model->value = $optionsModel->title;
                                 $model->option_id = $optionsModel->id;
                             }
                         } else {
                             $model->value = $attributesAnswers->{$attribute_id};
                             if (isset($filedTypeTitle) && $filedTypeTitle == 'Date Picker') {
                                 //@TODO replace datepicker with some database constatnt value;
                                 $model->value = strtotime($attributesAnswers->{$attribute_id});
                             }
                         }
                         $model->attribute_id = $id;
                         $model->member_id = Yii::$app->getUser()->id;
                         $model->save();
                     }
                 }
                 $mappingAttributesSaved = true;
             }
             if ($mappingQuestionsSaved && $mappingAttributesSaved) {
                 $user = Yii::$app->getUser()->getIdentity();
                 $user->status = User::STATUS_ACTIVE;
                 if ($user->save()) {
                     return Yii::$app->response->redirect(array('members'));
                 } else {
                     Yii::$app->getSession()->setFlash('warning', Yii::t('errors', 'Can not save mapping data. Please contact system administrator'));
                 }
             } else {
                 $categoryModel = MappingCategories::findOne(['id' => $pageModel->category_id]);
                 $attributesModel = MembersAttributes::find(['id in ' => $categoryModel->attributes_id])->with('fieldsTypes')->all();
                 $questionsModel = MappingQuestions::find(['category_id' => $categoryModel->id])->with('fieldsTypes')->all();
                 return $this->render('mapping', ['questionsAnswers' => $questionsAnswers, 'attributesAnswers' => $attributesAnswers, 'pageModel' => $pageModel, 'categoryModel' => $categoryModel, 'questionsModel' => $questionsModel, 'attributesModel' => $attributesModel]);
             }
         } else {
             return $this->render('mapping', ['questionsAnswers' => $questionsAnswers, 'attributesAnswers' => $attributesAnswers, 'pageModel' => $pageModel, 'categoryModel' => $categoryModel, 'questionsModel' => $questionsModel, 'attributesModel' => $attributesModel]);
         }
     } else {
         return Yii::$app->response->redirect(array('site/login'));
     }
 }
 /**
  * Deletes an existing CmsPagesCategories model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     CmsPages::deleteAll(['category_id' => $id]);
     return $this->redirect(['index']);
 }
Example #4
0
use yii\helpers\Html;
use yii\grid\GridView;
use backend\models\CmsPages;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'Pages');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="cms-pages-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a(Yii::t('backend', 'Create Page'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'rowOptions' => function ($model) {
    if ($model->is_active == 0) {
        return ['class' => 'danger'];
    }
}, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'title', array('attribute' => 'is_active', 'filter' => Html::activeDropDownList($searchModel, 'is_active', CmsPages::dropdownActive(), ['class' => 'form-control', 'prompt' => Yii::t('backend', 'All')]), 'format' => 'boolean'), 'sort_order', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]);
?>

</div>
Example #5
0
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;
use backend\models\CmsPages;
/* @var $this yii\web\View */
/* @var $model backend\models\GeneralSettings */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="general-settings-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, '[]value')->dropDownList(ArrayHelper::map(CmsPages::find()->all(), 'id', 'title'), ['prompt' => Yii::t('backend', 'Select Page')])->label(false);
?>

    <?php 
echo $form->field($model, '[]id')->hiddenInput()->label(false);
?>


    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
Example #6
0
 /**
  * Finds the CmsPages model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CmsPages the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CmsPages::find()->where(['id' => $id])->multilingual()->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }