コード例 #1
0
 public function actionIndex()
 {
     $query = Posts::find();
     $pagination = new Pagination(['defaultPageSize' => 6, 'totalCount' => $query->count()]);
     $query = $query->orderBy('date DESC')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['query' => $query, 'pagination' => $pagination]);
 }
コード例 #2
0
ファイル: SiteController.php プロジェクト: htom78/yf2-demo
 /**
  * Loads our model and throws an exception if we encounter an error
  * @param int $id 	The $id of the model we want to delete
  */
 private function loadModel($id)
 {
     $model = Posts::find($id);
     if ($model == NULL) {
         throw new HttpException(404, 'Model not found.');
     }
     return $model;
 }
コード例 #3
0
 public function delete()
 {
     if (!$this->request->is('post') && !$this->request->is('delete')) {
         $msg = "Posts::delete can only be called with http:post or http:delete.";
         throw new DispatchException($msg);
     }
     Posts::find($this->request->id)->delete();
     $this->redirect('Posts::index');
 }
コード例 #4
0
ファイル: PostsSearch.php プロジェクト: raguila/islc
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         $query->joinWith(['users']);
         return $dataProvider;
     }
     $query->andFilterWhere(['PostID' => $this->PostID, 'PostTypeID' => $this->PostTypeID, 'AttachmentTypeID' => $this->AttachmentTypeID, 'UserID' => $this->UserID, 'Likes' => $this->Likes, 'Pinned' => $this->Pinned, 'TimeStamp' => $this->TimeStamp]);
     $query->andFilterWhere(['like', 'PostTitle', $this->PostTitle])->andFilterWhere(['like', 'PostContent', $this->PostContent])->andFilterWhere(['like', 'Tags', $this->Tags])->andFilterWhere(['like', 'Attachment', $this->Attachment]);
     return $dataProvider;
 }
コード例 #5
0
 /**
  * Render the profile page
  * @param $username
  */
 public static function profile($username)
 {
     # fetch account data by username
     $account = Accounts::findByUsername($username);
     # fecth all categories
     $categories = Categories::all();
     # fetch all of this member's post
     $posts = Posts::find(['id_account' => $account['id']]);
     # fetch all accounts
     $users = Accounts::find(['type' => 2]);
     View::render('member/profile', ['account' => $account, 'posts' => $posts, 'users' => $users, 'categories' => $categories]);
 }
コード例 #6
0
ファイル: Posts.php プロジェクト: sydorenkovd/yii2Basic
 public static function setNumbers($posts)
 {
     $all_releases = Posts::find()->where(['is_release' => 1])->orderBy("date")->all();
     $number = 1;
     foreach ($all_releases as $release) {
         foreach ($posts as $post) {
             if ($post->id == $release->id) {
                 $post->number = $number;
             }
         }
         $number++;
     }
 }
コード例 #7
0
ファイル: PostsSearch.php プロジェクト: romdim/yii2-cms
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::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, 'date' => $this->date, 'published' => $this->published, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'short', $this->short])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
コード例 #8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['post_id' => $this->post_id, 'author_id' => $this->author_id]);
     $query->andFilterWhere(['like', 'post_title', $this->post_title])->andFilterWhere(['like', 'post_description', $this->post_description]);
     return $dataProvider;
 }
コード例 #9
0
ファイル: PostsSearch.php プロジェクト: cfycfysx/learningYii2
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]);
     $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, 'date' => $this->date, 'auther_id' => $this->auther_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
コード例 #10
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::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_time' => $this->created_time, 'update_time' => $this->update_time]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'source', $this->source])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'created_by', $this->created_by])->andFilterWhere(['like', 'updated_by', $this->updated_by]);
     return $dataProvider;
 }
コード例 #11
0
ファイル: PostOthers.php プロジェクト: sydorenkovd/yii2Basic
 public function run()
 {
     $posts = Posts::find()->where(['hide' => 0])->limit(5)->where(['not', ['id' => $this->id]])->orderBy("rand()")->all();
     $trs = "";
     foreach ($posts as $post) {
         $img = Html::tag('img', null, ['src' => $post->img, 'alt' => $post->title]);
         $td_1 = Html::tag('td', $img);
         $a_span = Html::tag('a', '«' . $post->title . '»', ['href' => $post->link]);
         $a_span .= Html::tag('span', $post->date, ['class' => 'date']);
         $td_2 = Html::tag('td', $a_span);
         $trs .= Html::tag('tr', $td_1 . $td_2);
     }
     return Html::tag('table', $trs, ['id' => 'post_others']);
 }
コード例 #12
0
ファイル: PostsSearch.php プロジェクト: liubo2055/lazadatest
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::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' => $this->created, 'modfied' => $this->modfied]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
コード例 #13
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::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, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'created_at', $this->created_at])->andFilterWhere(['like', 'updated_at', $this->updated_at])->andFilterWhere(['like', 'full_text', $this->full_text])->andFilterWhere(['like', 'intro_text', $this->intro_text])->andFilterWhere(['like', 'meta_keys', $this->meta_keys])->andFilterWhere(['like', 'meta_desc', $this->meta_desc])->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
コード例 #14
0
 protected function getPosts(&$posts, $page = 0)
 {
     $page = $page < 0 ? 1 : $page;
     $validates = array();
     if ($page != 0) {
         $validates['limit'] = ITEMS_PAGE;
         $validates['page'] = $page;
     }
     if (!Auth::check('default')) {
         $validates['conditions'] = array('visibility' => 1);
     }
     $posts = Posts::find('all', $validates);
     return count($posts);
 }
コード例 #15
0
ファイル: PostsSearch.php プロジェクト: ynijar/basic
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::find()->where(['user_id' => Yii::$app->user->getId()]);
     $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->joinWith('status');
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'end_date' => $this->end_date]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'status.name', $this->status_id]);
     return $dataProvider;
 }
コード例 #16
0
ファイル: PostsSearch.php プロジェクト: elgorm/yii2-blogervk
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'recordId' => $this->recordId, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'published' => $this->published]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
コード例 #17
0
ファイル: PostsSearch.php プロジェクト: NavaINT1876/stage2php
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::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, 'date' => $this->date]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text]);
     if ($this->date_from != '' && $this->date_to != '') {
         $query->andFilterWhere(['>=', 'date', strtotime($this->date_from)])->andFilterWhere(['<=', 'date', strtotime($this->date_to)]);
     }
     return $dataProvider;
 }
コード例 #18
0
ファイル: PostsController.php プロジェクト: roopesh90/BlogN
 public function viewedit($id = null)
 {
     if (!Auth::check('default')) {
         return $this->redirect('Sessions::add');
     } else {
         $success = false;
         if (!is_null($id)) {
             $post = Posts::find('first', array('conditions' => array('_id' => $id)));
         }
         if ($this->request->data) {
             $success = $post->save($this->request->data);
             Posts::remove(array('title' => ''));
         }
     }
     // elseif($this->request->data) {
     //$success = Posts::update($this->request->data);
     //$success = $post->delete();
     //return compact('success');
     // }
     return compact('post', 'success');
 }
コード例 #19
0
ファイル: _form.php プロジェクト: cfycfysx/learningYii2

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'content')->textarea(['rows' => 6]);
?>

 <?php 
echo $form->field($model, 'date')->widget(DatePicker::className(), ['inline' => false, 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]);
?>

     <?php 
echo $form->field($model, 'auther_id')->widget(Select2::classname(), ['data' => \yii\helpers\ArrayHelper::map(\app\models\Posts::find()->all(), 'auther_id', 'auther_id'), 'language' => 'us']);
?>


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

    <?php 
ActiveForm::end();
?>


コード例 #20
0
ファイル: PostsController.php プロジェクト: hysdop/YobaCMS
 /**
  * Отображает новости
  * @return string
  * @throws HttpException
  */
 public function actionPosts($category_url = null)
 {
     $this->layout = 'main';
     $query = Posts::find()->where(['active' => 1]);
     if ($category_url) {
         $category = Categories::findOne(['active' => 1, 'url' => $category_url]);
         if (!$category) {
             throw new HttpException(404, 'Категория не существует.');
         }
         $query = $query->andWhere(['category_id' => $category->id]);
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 5, 'pageParam' => 'pageNum', 'forcePageParam' => false, 'pageSizeParam' => false]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('posts', ['posts' => $models, 'pages' => $pages]);
 }
コード例 #21
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $page = Posts::find($id);
     if ($page) {
         $page = $page->delete();
     } else {
         $page = Posts::withTrashed()->find($id)->forceDelete();
     }
     return response()->json($page);
 }
コード例 #22
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $post = Posts::find($id);
     $post->delete();
     return \Redirect::route('posts.index')->with('success', 'You have deleted a post.');
 }
コード例 #23
0
 /**
  * Renders index page with all posts.
  * @return string
  */
 public function actionIndex()
 {
     $posts = Posts::find()->all();
     return $this->render('index', ['posts' => $posts]);
 }
コード例 #24
0
ファイル: PostsController.php プロジェクト: garf/0ez
 private function _setPostStatus($post_id, $status)
 {
     $post = Posts::find($post_id);
     $post->status = $status;
     $post->save();
     return $post;
 }
コード例 #25
0
 public function actionSearch()
 {
     $q = Yii::$app->getRequest()->getQueryParam('q');
     $query = Posts::find()->where(['hide' => 0])->where(['like', 'full_text', $q]);
     $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $query->count()]);
     $posts = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     Posts::setNumbers($posts);
     return $this->render('search', ['posts' => $posts, 'q' => $q, 'active_page' => Yii::$app->request->get("page", 1), 'count_pages' => $pagination->getPageCount(), 'pagination' => $pagination]);
 }
コード例 #26
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request, $id)
 {
     $post = Posts::find($id);
     if ($post && ($post->author_id == $request->user()->id || $request->user()->is_admin())) {
         $post->delete();
         $data['message'] = 'Post deleted Successfully';
     } else {
         $data['errors'] = 'Invalid Operation. You have not sufficient permissions';
     }
     return redirect('/')->with($data);
 }
コード例 #27
0
 public function actionBlog($id = null)
 {
     $user = Yii::$app->user->id;
     /** @var $profile \app\models\Profile */
     if ($id === null) {
         $profile = Profile::findOne(['user_id' => $user]);
         $queryPosts = Posts::find()->where(['user_id' => $user]);
     } else {
         $queryPosts = Posts::find()->where(['user_id' => $id]);
         $profile = Profile::findOne(['user_id' => $id]);
         if (!isset($profile)) {
             Yii::$app->getSession()->setFlash('error', 'that profile not found');
             return $this->goHome();
         }
     }
     $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $queryPosts->count()]);
     $posts = $queryPosts->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     $model = new Posts();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->createPost()) {
             $this->refresh();
         } else {
             $errors = $model->errors;
             Yii::$app->session->setFlash('error', 'Error: check the fields');
         }
     }
     return $this->render('blog', ['posts' => $posts, 'profile' => $profile, 'activePage' => Yii::$app->request->get('page', 1), 'countPages' => $pagination->getPageCount(), 'pagination' => $pagination, 'model' => $model]);
 }