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 = Newsletter::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(['newsletter_id' => $this->newsletter_id]); $query->andFilterWhere(['like', 'news', $this->news]); return $dataProvider; }
public function actionSend($id) { if (Yii::$app->user->isGuest || Yii::$app->user->identity->user_role != 4 && Yii::$app->user->identity->user_role != 3) { return $this->goHome(); } $model = Newsletter::find()->where(['newsletter_id' => $id])->one(); $model->sent = true; $model->update(); $users = User::find()->where(['newsletter' => 1])->all(); $mailer = Yii::$app->spoolmailer; foreach ($users as $user) { $mailer->newMail('*****@*****.**', $user->email, 'Newsletter ze strony', $model->news); } $mailer->send(); return $this->redirect(['index']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Newsletter::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSizeLimit' => [10, 100]], 'sort' => ['defaultOrder' => ['subject' => SORT_ASC]]]); $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]); $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'body', $this->body]); $this->addRangeCondition($query, 'created_at'); $this->addRangeCondition($query, 'updated_at'); return $dataProvider; }
public function sendNewsletter($id) { $newsletter = Newsletter::find($id); if (is_null($newsletter)) { return \Redirect::route('Newsletter.index')->with('error', 'El Newsletter no existe.'); } if ($newsletter->enviado == 1) { return \Redirect::route('Newsletter.index')->with('error', 'El Newsletter no puede ser enviado porque ya ha sido enviado anteriormente.'); } //ponemos enviado el newsletter $newsletter->fecha_envio = Carbon::now()->toDateString(); $newsletter->enviado = 1; $newsletter->save(); $this->guardarSuscriptoresParaEnvio($newsletter); $this->iniciarEnvio($newsletter); return \Redirect::route('Newsletter.index')->with('message', 'El Newsletter fue ENVIADO con éxito.'); }
public function orderMin($langs = null, $cid = null) { $query = Newsletter::find()->min('ordering'); return $query; }