public function actionIndex() { $user = Yii::$app->user; $dashboard = []; if ($user->can('partner_view')) { $dashboard[] = ['name' => Html::tag('b', __('Partners')), 'link' => Url::to(['partner/index']), 'count' => Partner::find()->count()]; } if ($user->can('visit_view') || $user->can('visit_view_all')) { $dashboard[] = ['name' => __('Visits'), 'link' => Url::to(['visit/index']), 'count' => Visit::find()->count()]; } if ($user->can('donate_view') || $user->can('donate_view_all')) { $dashboard[] = ['name' => __('Donates'), 'link' => Url::to(['donate/index']), 'count' => Donate::find()->count()]; } if ($user->can('task_view') || $user->can('task_view_all')) { $dashboard[] = ['name' => __('Tasks'), 'link' => Url::to(['task/index']), 'count' => Task::find()->count()]; } if ($user->can('newsletter_view')) { $dashboard[] = ['name' => __('Mailing lists'), 'link' => Url::to(['mailing-list/index']), 'count' => MailingList::find()->count()]; $dashboard[] = ['name' => __('Newsletters'), 'link' => Url::to(['newsletter/index']), 'count' => Newsletter::find()->count()]; $dashboard[] = ['name' => __('Printing templates'), 'link' => Url::to(['print-template/index']), 'count' => PrintTemplate::find()->count()]; } if ($user->can('user_manage')) { $dashboard[] = ['name' => __('Users'), 'link' => Url::to(['user/index']), 'count' => User::find()->count()]; } return $this->render('index', ['dashboard' => $dashboard]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PrintTemplate::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSizeLimit' => [10, 100]], 'sort' => ['defaultOrder' => ['name' => SORT_ASC]]]); $params = $this->processParams($params); if (!($this->load($params) && $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, 'status' => $this->status]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'content', $this->content]); $this->addRangeCondition($query, 'created_at'); $this->addRangeCondition($query, 'updated_at'); return $dataProvider; }
/** * Finds the PrintTemplate model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PrintTemplate the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PrintTemplate::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getTemplate() { return $this->hasOne(PrintTemplate::className(), ['id' => 'template_id']); }
public function getTemplates() { return $this->hasMany(PrintTemplate::className(), ['id' => 'template_id'])->viaTable('print_template_mailing_list', ['list_id' => 'id']); }