Beispiel #1
0
 /**
  * Updates an existing Activity model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $categories = ActivityCategory::find()->all();
     $model = $this->findModel($id);
     if ($model->load(\Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'categories' => $categories]);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ActivityCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug]);
     return $dataProvider;
 }
Beispiel #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(ActivityCategory::className(), ['id' => 'category_id']);
 }
Beispiel #4
0
 public static function getActivitiesDataProviderByCatSlug($dataProvider, $slug)
 {
     $activityCat = ActivityCategory::findOne(['slug' => $slug]);
     $dataProvider->query->FilterWhere(['category_id' => $activityCat->id, 'status' => Activity::STATUS_IN_USE]);
     $dataProvider->pagination = ['pageSize' => 10];
     $dataProvider->refresh();
     return $dataProvider;
 }
Beispiel #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getActivityCategories()
 {
     return $this->hasMany(ActivityCategory::className(), ['parent_id' => 'id']);
 }
Beispiel #6
0
use yii\helpers\ArrayHelper;
use yii\grid\GridView;
use common\models\Activity;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\ActivitySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('common', 'Activity');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="activity-index">

	<?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

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

	<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'category_id', 'value' => function ($model) {
    return $model->category ? $model->category->title : null;
}, 'filter' => ArrayHelper::map(\common\models\ActivityCategory::find()->all(), 'id', 'title')], 'title', 'start_time:datetime', 'end_time:datetime', ['attribute' => 'thumbnail', 'format' => 'html', 'value' => function ($model) {
    return Html::img($model->getThumbnailUrl(), ['class' => 'img-responsive', 'styles' => 'width:100px;']);
}], ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'status', 'enum' => Activity::getStatus()], 'sort', ['class' => 'yii\\grid\\ActionColumn']], 'layout' => "{items}\n{summary}\n{pager}"]);
?>

</div>
 /**
  * Finds the ActivityCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ActivityCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ActivityCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }