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]); }
public function destroy($id) { try { Newsletter::destroy($id); session()->flash('flash_message', 'Registro apagado com sucesso'); } catch (\Exception $e) { LogR::exception('destroy newsletters', $e); session()->flash('flash_message', 'Ops!! Ocorreu algum problema!. ' . $e->getMessage()); } return Redirect::back(); }
/** * 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; }
/** * 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 static function otherNewsletter($key) { $data = \App\Models\Newsletter::whereNotIn('id', [$key])->get(); $return = ""; foreach ($data as $key => $value) { $param = url('newsletter/detail/' . $value->id . '/' . preg_replace('/\\s+/', '', GlobalHelper::formatDate($value->created_at, 'd m Y')) . '/' . $value->slug); $return .= '<div class="media"> <div class="pull-left"> <a href="' . $param . '"><img src="' . GlobalHelper::checkImage($value->image, 'article') . '" style="width:52px;height:52px" alt=""></a> </div> <div class="media-body"> <h4><a href="' . $param . '">' . GLobalHelper::softTrim($value->title, 51) . ',</a></h4> <p>posted on ' . GLobalHelper::formatDate($value->created_at, 'd F Y') . '</p> </div> </div>'; } return $return; }
public function getNewsletter() { return $this->hasOne(Newsletter::className(), ['id' => 'newsletter_id']); }
private function order($id = null, $ordering = null, $direction = null) { if ($id != null || $ordering != null || $direction != null) { $sess = Yii::$app->session->get('sessNewsletter'); if ($direction == "up") { $newSortOrder = $ordering - 1; } else { if ($direction == "down") { $newSortOrder = $ordering + 1; } } $parent = Newsletter::findOne($id); $where = array(); $where[] = "ordering = '{$newSortOrder}'"; $connection = Yii::$app->db; $sql = "SELECT id FROM tbl_newsletter " . (count($where) ? "\n WHERE " . implode(' AND ', $where) : ''); $command = $connection->createCommand($sql); $reader = $command->query(); foreach ($reader as $row) { $otherId = $row["id"]; } $where = array(); $where[] = "id = '{$id}'"; $sql = 'UPDATE tbl_newsletter SET ordering = "' . $newSortOrder . '" ' . (count($where) ? "\n WHERE " . implode(' AND ', $where) : ''); $command = $connection->createCommand($sql); $command->execute(); if ($reader->getRowCount() > 0) { $where = array(); $where[] = "id = '{$otherId}'"; $sql = 'UPDATE tbl_newsletter SET ordering = "' . $ordering . '"' . (count($where) ? "\n WHERE " . implode(' AND ', $where) : ''); $command = $connection->createCommand($sql); $command->execute(); } return $this->redirect(['index', 'page' => $_REQUEST['page']]); } }
public static function saveEmail($email) { $data = ['email' => $email]; Newsletter::insert($data); }
protected function iniciarEnvio(Newsletter $newsletter) { $destinatarios = $newsletter->Mail()->get(); foreach ($destinatarios as $destinatario) { $this->enviarMailNewsletter($newsletter, $destinatario); } }
public function getNewsletters() { return $this->hasMany(Newsletter::className(), ['id' => 'newsletter_id'])->viaTable('newsletter_mailing_list', ['list_id' => 'id']); }
public function orderMin($langs = null, $cid = null) { $query = Newsletter::find()->min('ordering'); return $query; }
/** * Finds the Newsletter model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Newsletter the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Newsletter::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }