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(News::tableName(), ['news_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'image' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'short' => Schema::TYPE_STRING . '(1024) DEFAULT NULL', 'text' => Schema::TYPE_TEXT . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'views' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '1'"], $tableOptions)->execute(); $db->createCommand()->createIndex('slug', News::tableName(), 'slug', true)->execute(); }
public function getPhotos() { if (!$this->_photos) { $this->_photos = []; foreach (Photo::find()->where(['class' => NewsModel::className(), 'item_id' => $this->id])->sort()->all() as $model) { $this->_photos[] = new PhotoObject($model); } } return $this->_photos; }
protected function getAdp() { if (!$this->_adp) { $query = NewsModel::find()->status(NewsModel::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; }
private function findNews($id_slug) { //asline $news = NewsModel::find()->where(['or', 'news_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(NewsModel::STATUS_ON)->one(); if (is_integer($id_slug)) { $news = NewsModel::find()->where('news_id=:id_slug', [':id_slug' => $id_slug])->status(NewsModel::STATUS_ON)->one(); } else { $news = NewsModel::find()->where('slug=:id_slug', [':id_slug' => $id_slug])->status(NewsModel::STATUS_ON)->one(); } if ($news) { $news->updateCounters(['views' => 1]); return new NewsObject($news); } else { return null; } }
public function insertNews() { if (News::find()->count()) { return '`<b>' . News::tableName() . '</b>` table is not empty, skipping...'; } $this->db->createCommand('TRUNCATE TABLE `' . News::tableName() . '`')->query(); $time = time(); $news1 = new News(['title' => 'First news title', 'image' => '/uploads/news/news-1.jpg', 'short' => 'At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt molliti', 'text' => '<p><strong>Sed ut perspiciatis</strong>, 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, 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. </p><ul><li>item 1</li><li>item 2</li><li>item 3</li></ul><p>ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?</p>', 'tagNames' => 'php, yii2, jquery', 'time' => $time]); $news1->save(); $this->attachPhotos($news1, ['/uploads/photos/news-1-1.jpg', '/uploads/photos/news-1-2.jpg', '/uploads/photos/news-1-3.jpg', '/uploads/photos/news-1-4.jpg']); $this->attachSeo($news1, 'First news H1'); $news2 = new News(['title' => 'Second news title', 'image' => '/uploads/news/news-2.jpg', 'short' => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip', 'text' => '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p><ol> <li>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. </li><li>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</li></ol>', 'tagNames' => 'yii2, jquery, html', 'time' => $time - 86400]); $news2->save(); $this->attachSeo($news2, 'Second news H1'); $news3 = new News(['title' => 'Third news title', 'image' => '/uploads/news/news-3.jpg', 'short' => 'At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt molliti', 'text' => '<p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.</p>', 'time' => $time - 86400 * 2]); $news3->save(); $this->attachSeo($news3, 'Third news H1'); return 'News 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()); }
public function actionClearImage($id) { $model = News::findOne($id); if ($model === null) { $this->flash('error', Yii::t('easyii', 'Not found')); } else { $model->image = ''; if ($model->update()) { @unlink(Yii::getAlias('@webroot') . $model->image); $this->flash('success', Yii::t('easyii', 'Image cleared')); } else { $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors())); } } return $this->back(); }