예제 #1
0
 public function up()
 {
     //ADMINS
     $this->createTable(models\Admin::tableName(), ['admin_id' => 'pk', 'username' => Schema::TYPE_STRING . '(32) NOT NULL', 'password' => Schema::TYPE_STRING . '(64) NOT NULL', 'auth_key' => Schema::TYPE_STRING . '(128) NOT NULL', 'access_token' => Schema::TYPE_STRING . '(128) DEFAULT NULL'], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('access_token', models\Admin::tableName(), 'access_token', true);
     //LOGINFORM
     $this->createTable(models\LoginForm::tableName(), ['log_id' => 'pk', 'username' => Schema::TYPE_STRING . '(128) NOT NULL', 'password' => Schema::TYPE_STRING . '(128) NOT NULL', 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'user_agent' => Schema::TYPE_STRING . '(1024) NOT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'success' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //MODULES
     $this->createTable(models\Module::tableName(), ['module_id' => 'pk', 'name' => Schema::TYPE_STRING . '(64) NOT NULL', 'class' => Schema::TYPE_STRING . '(128) NOT NULL', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'icon' => Schema::TYPE_STRING . '(32) NOT NULL', 'settings' => Schema::TYPE_TEXT . ' NOT NULL', 'notice' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('name', models\Module::tableName(), 'name', true);
     //PHOTOS
     $this->createTable(models\Photo::tableName(), ['photo_id' => 'pk', 'model' => Schema::TYPE_STRING . '(128) NOT NULL', 'item_id' => Schema::TYPE_INTEGER . " NOT NULL", 'thumb' => Schema::TYPE_STRING . '(128) NOT NULL', 'image' => Schema::TYPE_STRING . '(128) NOT NULL', 'description' => Schema::TYPE_STRING . '(1024) NOT NULL', 'order_num' => Schema::TYPE_INTEGER . " NOT NULL"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('model_item', models\Photo::tableName(), ['model', 'item_id']);
     //SEOTEXT
     $this->createTable(models\SeoText::tableName(), ['seotext_id' => 'pk', 'model' => Schema::TYPE_STRING . '(128) NOT NULL', 'item_id' => Schema::TYPE_INTEGER . " NOT NULL", 'h1' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'title' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'keywords' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'description' => Schema::TYPE_STRING . '(128) DEFAULT NULL'], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('model_item', models\SeoText::tableName(), ['model', 'item_id'], true);
     //SETTINGS
     $this->createTable(models\Setting::tableName(), ['setting_id' => 'pk', 'name' => Schema::TYPE_STRING . '(64) NOT NULL', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'value' => Schema::TYPE_STRING . '(1024) NOT NULL', 'visibility' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('name', models\Setting::tableName(), 'name', true);
     //CAROUSEL MODULE
     $this->createTable(Carousel::tableName(), ['carousel_id' => 'pk', 'image' => Schema::TYPE_STRING . '(128) NOT NULL', 'title' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'text' => Schema::TYPE_TEXT . ' DEFAULT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //CATALOG MODULE
     $this->createTable(catalog\models\Category::tableName(), ['category_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'fields' => Schema::TYPE_TEXT . ' NOT NULL', 'thumb' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', catalog\models\Category::tableName(), 'slug', true);
     $this->createTable(catalog\models\Item::tableName(), ['item_id' => 'pk', 'category_id' => Schema::TYPE_INTEGER . ' NOT NULL', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'description' => Schema::TYPE_TEXT . ' DEFAULT NULL', 'data' => Schema::TYPE_TEXT . ' NOT NULL', 'thumb' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'created_at' => Schema::TYPE_DATETIME . " DEFAULT NULL", 'updated_at' => Schema::TYPE_DATETIME . " DEFAULT NULL", 'created_by' => Schema::TYPE_INTEGER . " DEFAULT NULL", 'updated_by' => Schema::TYPE_INTEGER . " DEFAULT NULL"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', catalog\models\Item::tableName(), 'slug', true);
     //FEEDBACK MODULE
     $this->createTable(Feedback::tableName(), ['feedback_id' => 'pk', 'name' => Schema::TYPE_STRING . '(64) NOT NULL', 'email' => Schema::TYPE_STRING . '(128) NOT NULL', 'phone' => Schema::TYPE_STRING . '(64) DEFAULT NULL', 'title' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'text' => Schema::TYPE_TEXT . ' NOT NULL', 'answer' => Schema::TYPE_TEXT . ' DEFAULT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //FILE MODULE
     $this->createTable(File::tableName(), ['file_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'file' => Schema::TYPE_STRING . '(255) NOT NULL', 'size' => Schema::TYPE_INTEGER . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'downloads' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL'], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', File::tableName(), 'slug', true);
     //GALLERY MODULE
     $this->createTable(Album::tableName(), ['album_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'thumb' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', Album::tableName(), 'slug', true);
     //GUESTBOOK MODULE
     $this->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', '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'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //NEWS MODULE
     $this->createTable(News::tableName(), ['news_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'thumb' => 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 '0'", 'created_by' => Schema::TYPE_INTEGER . " DEFAULT NULL", 'updated_by' => Schema::TYPE_INTEGER . " DEFAULT NULL"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', News::tableName(), 'slug', true);
     //ARTICLE MODULE
     $this->createTable(article\models\Category::tableName(), ['category_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'thumb' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', article\models\Category::tableName(), 'slug', true);
     $this->createTable(article\models\Item::tableName(), ['item_id' => 'pk', 'category_id' => Schema::TYPE_INTEGER . ' NOT NULL', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'thumb' => 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', 'views' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'", 'created_by' => Schema::TYPE_INTEGER . " DEFAULT NULL", 'updated_by' => Schema::TYPE_INTEGER . " DEFAULT NULL"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', article\models\Item::tableName(), 'slug', true);
     //PAGE MODULE
     $this->createTable(Page::tableName(), ['page_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'text' => Schema::TYPE_TEXT . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL'], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', Page::tableName(), 'slug', true);
     //FAQ MODULE
     $this->createTable(Faq::tableName(), ['faq_id' => 'pk', 'question' => Schema::TYPE_TEXT . ' NOT NULL', 'answer' => Schema::TYPE_TEXT . ' NOT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //SUBSCRIBE MODULE
     $this->createTable(Subscriber::tableName(), ['subscriber_id' => 'pk', 'email' => Schema::TYPE_STRING . '(128) NOT NULL', 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('email', Subscriber::tableName(), 'email', true);
     $this->createTable(History::tableName(), ['history_id' => 'pk', 'subject' => Schema::TYPE_STRING . '(128) NOT NULL', 'body' => Schema::TYPE_TEXT . ' NOT NULL', 'sent' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //TEXT MODULE
     $this->createTable(Text::tableName(), ['text_id' => 'pk', 'text' => Schema::TYPE_TEXT . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL'], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', Text::tableName(), 'slug', true);
     //INSERT VERSION
     $this->delete(models\Setting::tableName(), ['name' => 'easyii_version']);
     $this->insert(models\Setting::tableName(), ['name' => 'easyii_version', 'value' => self::VERSION, 'title' => 'EasyiiCMS version', 'visibility' => models\Setting::VISIBLE_NONE]);
 }
예제 #2
0
 public function getPhotos()
 {
     if (!$this->_photos) {
         $this->_photos = [];
         foreach (Photo::find()->where(['class' => Item::className(), 'item_id' => $this->id])->sort()->all() as $model) {
             $this->_photos[] = new PhotoObject($model);
         }
     }
     return $this->_photos;
 }
예제 #3
0
 public function items($options = [])
 {
     if (!$this->_items) {
         $this->_items = [];
         $with = ['seo'];
         if (Yii::$app->getModule('admin')->activeModules['article']->settings['enableTags']) {
             $with[] = 'tags';
         }
         $query = Item::find()->with('seo')->where(['category_id' => $this->id])->status(Item::STATUS_ON)->sortDate();
         if (!empty($options['where'])) {
             $query->andFilterWhere($options['where']);
         }
         if (!empty($options['tags'])) {
             $query->innerJoinWith('tags', false)->andWhere([Tag::tableName() . '.name' => (new Item())->filterTagValues($options['tags'])])->addGroupBy('item_id');
         }
         $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : []]);
         foreach ($this->_adp->models as $model) {
             $this->_items[] = new ArticleObject($model);
         }
     }
     return $this->_items;
 }
 public function insertArticles()
 {
     if (article\models\Category::find()->count()) {
         return '`<b>' . article\models\Category::tableName() . '</b>` table is not empty, skipping...';
     }
     $this->db->createCommand('TRUNCATE TABLE `' . article\models\Category::tableName() . '`')->query();
     $root1 = new article\models\Category(['title' => 'Articles category 1', 'order_num' => 2]);
     $root1->makeRoot();
     $this->attachSeo($root1, 'Articles category 1 H1', 'Extended category 1 title');
     $root2 = new article\models\Category(['title' => 'Articles category 2', 'order_num' => 1]);
     $root2->makeRoot();
     $subcat1 = new article\models\Category(['title' => 'Subcategory 1', 'order_num' => 1]);
     $subcat1->appendTo($root2);
     $this->attachSeo($subcat1, 'Subcategory 1 H1', 'Extended subcategory 1 title');
     $subcat2 = new article\models\Category(['title' => 'Subcategory 1', 'order_num' => 1]);
     $subcat2->appendTo($root2);
     $this->attachSeo($subcat2, 'Subcategory 2 H1', 'Extended subcategory 2 title');
     if (article\models\Item::find()->count()) {
         return '`<b>' . article\models\Item::tableName() . '</b>` table is not empty, skipping...';
     }
     $this->db->createCommand('TRUNCATE TABLE `' . article\models\Item::tableName() . '`')->query();
     $time = time();
     $article1 = new article\models\Item(['category_id' => $root1->primaryKey, 'title' => 'First article title', 'image' => '/uploads/article/article-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.&nbsp;</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, css, bootstrap', 'time' => $time]);
     $article1->save();
     $this->attachPhotos($article1, ['/uploads/photos/article-1-1.jpg', '/uploads/photos/article-1-2.jpg', '/uploads/photos/article-1-3.jpg', '/uploads/photos/news-1-4.jpg']);
     $this->attachSeo($article1, 'First article H1');
     $article2 = new article\models\Item(['category_id' => $root1->primaryKey, 'title' => 'Second article title', 'image' => '/uploads/article/article-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, ajax', 'time' => $time - 86400]);
     $article2->save();
     $this->attachSeo($article2, 'Second article H1');
     $article3 = new article\models\Item(['category_id' => $root1->primaryKey, 'title' => 'Third article title', 'image' => '/uploads/article/article-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]);
     $article3->save();
     $this->attachSeo($article3, 'Third article H1');
     return 'Articles data inserted.';
 }
예제 #5
0
 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());
 }
예제 #6
0
 private function findItem($id_slug)
 {
     $article = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one();
     if ($article) {
         $article->updateCounters(['views' => 1]);
         return new ArticleObject($article);
     } else {
         return null;
     }
 }
예제 #7
0
 private function findItem($id_slug)
 {
     if (!($item = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one())) {
         return null;
     }
     $item->updateCounters(['views' => 1]);
     $itemObject = $this->parseItem($item);
     $itemObject->seo_h1 = $item->seo_h1;
     $itemObject->seo_title = $item->seo_title;
     $itemObject->seo_keywords = $item->seo_keywords;
     $itemObject->seo_description = $item->seo_description;
     return $itemObject;
 }
예제 #8
0
 public function getItems()
 {
     return $this->hasMany(Item::className(), ['category_id' => 'category_id'])->sort();
 }
예제 #9
0
 public function actionDelete($id)
 {
     if ($model = Item::findOne($id)) {
         $model->delete();
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse(Yii::t('easyii/article', 'Article deleted'));
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getArticleItem()
 {
     return $this->hasOne(Item::className(), ['item_id' => 'article_item_id']);
 }