<?php

class FeedController extends Controller
{
	static public function actionIndex()
	{
		$feed = array();

		// --------- NEWS
		$news = News::model()->getAll(array(
			'order' => '`pubDate` DESC',
			'limit' => 5,
		));
		foreach ($news as $new) {
			$feed[$new->date] = array(
				'title' => $new->name,
				'text' => $new->description,
				'img' => '',
				'type' => 'news',
			);
		}

		// --------- POINTS
		$points = Point::model()->getAll(array(
			'where' => '`status` = "published" AND `categoryId` NOT IN ('.  implode(',', Category::$paidIds).')',
			'order' => '`ord` DESC',
			'limit' => 5,
		));
		foreach ($points as $point) {
			$feed[$point->date] = array(
				'title' => $point->name,
				'text' => $point->description,
				'img' => $point->getImg(),
				'type' => 'point',
			);
		}

		// --------- ARTICLES
		$articles = Article::model()->getAll(array(
			'where' => '`status` = "published"',
			'order' => '`pubDate` DESC',
			'limit' => 5,
		));
		foreach ($articles as $article) {
			$feed[$article->pubDate] = array(
				'title' => $article->title,
				'text' => $article->text,
				'img' => $article->getImg(),
				'type' => 'article',
			);
		}

		// --------- SORT

		krsort($feed);

		self::$layout = 'layouts/page.php';
		self::addScript('/js/jquery-2.1.0.min.js');
		self::addScript('/js/jquery-ui-1.10.4.custom.min.js');
		self::addScript('/js/bootstrap.min.js');
		self::addScript('/js/jquery.cookie.js');
		self::addScript('/js/app.js?ver=' . App::getConfig('version'));
		self::addStyle('/css/style.css?ver=' . App::getConfig('version'));
		self::addStyle('/css/pageStyle.css?ver=' . App::getConfig('version'));
		self::addStyle('/css/feed.css?ver=' . App::getConfig('version'));
		self::addStyle('/css/bootstrap.min.css');
		self::addStyle('/css/bootstrap-theme.min.css');

		self::render('feed/index.php', array(
			'news' => $news,
			'articles' => $articles,
			'points' => $points,
				));
	}
}
