Example #1
0
 public function actionIndex()
 {
     $model = new GuestbookModel();
     $model->scenario = 'send';
     $request = Yii::$app->request;
     if ($model->load($request->post())) {
         $returnUrl = $model->save() ? $request->post('successUrl') : $request->post('errorUrl');
         return $this->redirect($returnUrl);
     } else {
         return $this->redirect(Yii::$app->request->baseUrl);
     }
 }
Example #2
0
 public function actionIndex()
 {
     $model = new Guestbook();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash(Guestbook::FLASH_KEY, 'success');
         } else {
             Yii::$app->session->setFlash(Guestbook::FLASH_KEY, 'error');
         }
         return $this->redirect(Yii::$app->request->referrer);
     } else {
         return $this->redirect(Yii::$app->request->baseUrl);
     }
 }
Example #3
0
 public function dbInstall()
 {
     $db = Yii::$app->db;
     $tableOptions = null;
     if ($db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=MyISAM';
     }
     $db->createCommand()->createTable(Guestbook::tableName(), ['guestbook_id' => 'pk', 'name' => Schema::TYPE_STRING . '(128) NOT NULL', 'title' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'text' => Schema::TYPE_TEXT . ' NOT NULL', 'answer' => Schema::TYPE_TEXT . ' DEFAULT NULL', 'email' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'new' => Schema::TYPE_BOOLEAN . " DEFAULT '0'", 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], $tableOptions)->execute();
 }
Example #4
0
 public function actionSetnew($id)
 {
     $model = Guestbook::findOne($id);
     if ($model === null) {
         $this->flash('error', Yii::t('easyii', 'Not found'));
     } else {
         $model->new = 1;
         if ($model->update()) {
             $this->flash('success', Yii::t('easyii/guestbook', 'Guestbook updated'));
         } else {
             $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
         }
     }
     return $this->redirect($this->getReturnUrl(['/admin/guestbook']));
 }
 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.';
 }
 public function down()
 {
     $this->dropTable(models\Admin::tableName());
     $this->dropTable(models\LoginForm::tableName());
     $this->dropTable(models\Module::tableName());
     $this->dropTable(models\Photo::tableName());
     $this->dropTable(models\Setting::tableName());
     $this->dropTable(Carousel::tableName());
     $this->dropTable(catalog\models\Category::tableName());
     $this->dropTable(catalog\models\Item::tableName());
     $this->dropTable(article\models\Category::tableName());
     $this->dropTable(article\models\Item::tableName());
     $this->dropTable(Feedback::tableName());
     $this->dropTable(File::tableName());
     $this->dropTable(gallery\models\Category::tableName());
     $this->dropTable(Guestbook::tableName());
     $this->dropTable(News::tableName());
     $this->dropTable(Page::tableName());
     $this->dropTable(Subscriber::tableName());
     $this->dropTable(History::tableName());
     $this->dropTable(Text::tableName());
 }
Example #7
0
 public function api_save($data)
 {
     $model = new GuestbookModel($data);
     $model->scenario = 'send';
     if ($model->save()) {
         return ['result' => 'success'];
     } else {
         return ['result' => 'error', 'error' => $model->getErrors()];
     }
 }
Example #8
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;
 }