Exemple #1
0
 public function api_last($limit = 1)
 {
     if ($limit === 1 && $this->_last) {
         return $this->_last;
     }
     $result = [];
     foreach (GuestbookModel::find()->status(GuestbookModel::STATUS_ON)->sortDate()->limit($limit)->all() as $item) {
         $result[] = new PostObject($item);
     }
     if ($limit > 1) {
         return $result;
     } else {
         $this->_last = count($result) ? $result[0] : null;
         return $this->_last;
     }
 }
 public function insertGuestbook()
 {
     if (Guestbook::find()->count()) {
         return '`<b>' . Guestbook::tableName() . '</b>` table is not empty, skipping...';
     }
     $this->db->createCommand('TRUNCATE TABLE `' . Guestbook::tableName() . '`')->query();
     $time = time();
     $post1 = new Guestbook(['name' => 'First user', 'text' => 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.']);
     $post1->time = $time;
     $post1->save();
     $post2 = new Guestbook(['name' => 'Second user', 'text' => 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.']);
     $post2->time = $time - 86400;
     $post2->answer = 'Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.';
     $post2->save();
     $post2->new = 0;
     $post2->update();
     $post3 = new Guestbook(['name' => 'Third user', 'text' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.']);
     $post3->time = $time - 86400 * 2;
     $post3->save();
     return 'Guestbook data inserted.';
 }
Exemple #3
0
 protected function getAdp()
 {
     if (!$this->_adp) {
         $query = GuestbookModel::find()->status(GuestbookModel::STATUS_ON)->desc();
         if ($this->_options['where']) {
             $query->andWhere($this->_options['where']);
         }
         $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $this->_options['pageSize']]]);
     }
     return $this->_adp;
 }
Exemple #4
0
 public function actionNoanswer()
 {
     $this->setReturnUrl();
     $data = new ActiveDataProvider(['query' => Guestbook::find()->where(['answer' => ''])->desc()]);
     return $this->render('index', ['data' => $data]);
 }