public function run() { $config = new CConfiguration(Yii::app()->basePath . '/config/pager.php'); $session = Yii::app()->session; $cookies = Yii::app()->request->cookies; // If referrer is not our action delete search parameters from session. if (strpos(Yii::app()->request->urlReferrer, '/tag/list') === false) { unset($session['search']); } if (!empty($_POST['search']) && is_array($_POST['search'])) { $search = $_POST['search']; $session['search'] = $search; } else { if (!empty($session['search'])) { $search = $session['search']; } else { $search = array('name' => ''); } } $criteria = new CDbCriteria(); $criteria->condition = 'name LIKE :name'; $criteria->params = array(':name' => "%{$search['name']}%"); $criteria->order = 'name'; $pages = new CPagination(Tag::model()->count($criteria)); $config->applyTo($pages); $pages->applyLimit($criteria); $tags = Tag::model()->with('quotesCount')->findAll($criteria); $showSearchForm = !empty($cookies['showSearchForm']) && $cookies['showSearchForm']->value ? true : false; $this->controller->render('list', array('tags' => $tags, 'pages' => $pages, 'search' => $search, 'showSearchForm' => $showSearchForm)); }
public function run() { $config = new CConfiguration(Yii::app()->basePath . '/config/pager.php'); $form = new SearchForm(); // If referrer is not our action delete search parameters from session. if (strpos(Yii::app()->request->urlReferrer, '/site/search') === false) { Yii::app()->session->remove('siteSearch'); } else { if (!empty(Yii::app()->session['SearchForm'])) { $siteSearch = Yii::app()->session['SearchForm']; $form->text = $siteSearch['text']; $form->authorId = $siteSearch['authorId']; } } if (!empty($_POST['SearchForm']) && is_array($_POST['SearchForm'])) { $form->attributes = $_POST['SearchForm']; Yii::app()->session['SearchForm'] = array('text' => $form->text, 'authorId' => $form->authorId); } $criteria = new CDbCriteria(); $criteria->order = 'approvedTime DESC'; $criteria->condition = 'approvedTime AND (textRu LIKE :text OR textEn LIKE :text) ' . ($form->authorId ? 'AND (authorId LIKE :authorId)' : ''); $criteria->params = array(':text' => "%{$form->text}%") + ($form->authorId ? array(':authorId' => $form->authorId) : array()); $pages = new CPagination(Quote::model()->count($criteria)); $config->applyTo($pages); $pages->applyLimit($criteria); $quotes = Quote::model()->with('tags')->findAll($criteria); $criteria = new CDbCriteria(); $criteria->order = 'name'; $authors = Author::model()->findAll($criteria); $this->controller->render('search', array('quotes' => $quotes, 'pages' => $pages, 'form' => $form, 'authors' => $authors)); }
public function testException() { $config = new CConfiguration(array('invalid' => 'value')); $object = new MyClass(); $this->setExpectedException('CException'); $config->applyTo($object); }
public function run() { $session = Yii::app()->session; $config = new CConfiguration(Yii::app()->basePath . '/config/pager.php'); $cookies = Yii::app()->request->cookies; // If referrer is not our controller delete search parameters from session. if (strpos(Yii::app()->request->urlReferrer, '/quote/list') === false) { unset($session['search']); } if (!empty($_POST['search']) && is_array($_POST['search'])) { $search = $_POST['search']; $session['search'] = $search; } else { if (!empty($session['search'])) { $search = $session['search']; } else { $search = array('text' => '', 'authorId' => 0, 'approved' => 'all'); } } $criteria = new CDbCriteria(); $criteria->condition = '(textRu LIKE :text OR textEn LIKE :text) ' . ($search['authorId'] ? 'AND authorId = :authorId ' : '') . ($search['approved'] == 'approved' ? 'AND approvedTime ' : '') . ($search['approved'] == 'unApproved' ? 'AND (approvedTime IS NULL OR approvedTime = 0) ' : ''); $criteria->params = array(':text' => "%{$search['text']}%") + ($search['authorId'] ? array(':authorId' => $search['authorId']) : array()); $criteria->order = 'Quote.id DESC'; $pages = new CPagination(Quote::model()->count($criteria)); $config->applyTo($pages); $pages->applyLimit($criteria); $quotes = Quote::model()->with('tags', 'author')->findAll($criteria); $showSearchForm = !empty($cookies['showSearchForm']) && $cookies['showSearchForm']->value ? true : false; $criteria = new CDbCriteria(); $criteria->order = 'name'; $authors = Author::model()->findAll($criteria); $this->controller->render('list', array('quotes' => $quotes, 'pages' => $pages, 'authors' => $authors, 'search' => $search, 'showSearchForm' => $showSearchForm)); }
public function run() { $config = new CConfiguration(Yii::app()->basePath . '/config/pager.php'); $criteria = new CDbCriteria(); $criteria->order = 'approvedTime DESC'; $criteria->condition = 'approvedTime'; $pages = new CPagination(Quote::model()->count($criteria)); $config->applyTo($pages); $pages->applyLimit($criteria); $quotes = Quote::model()->with('tags', 'author')->findAll($criteria); $this->controller->render('list', array('quotes' => $quotes, 'pages' => $pages)); }
public function run() { $config = new CConfiguration(Yii::app()->basePath . '/config/pager.php'); $session = Yii::app()->session; $cookies = Yii::app()->request->cookies; $criteria = new CDbCriteria(); $criteria->order = 'name'; $pages = new CPagination(Author::model()->count($criteria)); $config->applyTo($pages); $pages->applyLimit($criteria); $authors = Author::model()->with('quotesCount')->findAll($criteria); $this->controller->render('list', array('authors' => $authors, 'pages' => $pages)); }
public function run() { $config = new CConfiguration(Yii::app()->basePath . '/config/pager.php'); $author = Author::model()->findByPk($_GET['authorId']); if ($author === null) { throw new CHttpException(404, 'Author not found'); } $criteria = new CDbCriteria(); $criteria->condition = 'authorId = :authorId'; $criteria->params = array(':authorId' => $author->id); $pages = new CPagination(Quote::model()->count($criteria)); $config->applyTo($pages); $pages->applyLimit($criteria); $quotes = Quote::model()->findAll($criteria); $this->controller->render('author', array('author' => $author, 'quotes' => $quotes, 'pages' => $pages)); }
public function __construct($config = NULL) { $config = new CConfiguration($config); $config->applyTo($this); }
public function __construct($parent, $config = NULL) { $this->setParent($parent); $config = new CConfiguration($config); $config->applyTo($this); }
public function run() { $config = new CConfiguration(Yii::app()->basePath . '/config/pager.php'); $connection = Yii::app()->db; $tag = Tag::model()->findByAttributes(array('name' => $_GET['tag'])); if ($tag === null) { throw new CHttpException(404, 'Tag not found'); } /* * Get total number of approved quotes for this tag. */ $countSql = "SELECT COUNT(*) AS totalCount FROM `Quote`\n LEFT JOIN QuoteTag\n ON Quote.id = QuoteTag.quoteId\n WHERE approvedTime AND tagId = {$tag->id}"; $command = $connection->createCommand($countSql); $reader = $command->query(); $reader->next(); $row = $reader->current(); $totalCount = $row['totalCount']; $pages = new CPagination($totalCount); $config->applyTo($pages); /* * Get IDs of current page quotes. */ $offset = $pages->pageSize * $pages->currentPage; $limit = $pages->pageSize; $quotesIdSql = "SELECT id FROM Quote\n LEFT JOIN QuoteTag\n ON Quote.id = QuoteTag.quoteId\n WHERE approvedTime AND tagId = {$tag->id}\n GROUP BY quoteId\n ORDER BY approvedTime DESC\n LIMIT {$offset}, {$limit}"; $command = $connection->createCommand($quotesIdSql); $reader = $command->query(); $ids = array(); foreach ($reader as $row) { $ids[] = $row['id']; } $criteria = new CDbCriteria(); //$criteria->condition = 'approvedTime'; $criteria->addInCondition('id', $ids); $criteria->order = 'approvedTime DESC'; $quotes = Quote::model()->findAll($criteria); /* foreach($quotes as $quote) echo $quote->id, ","; return; */ /* $tagName = $_GET['tag']; $config = new CConfiguration(Yii::app()->basePath . '/config/pager.php'); $criteria = new CDbCriteria(); $criteria->condition = 'name = :name'; $criteria->params = array(':name' => $tagName); /* * Find total count of this tag quotes. * $connection = Yii::app()->db; $command = $connection->createCommand("SELECT COUNT(*) AS totalCount FROM QuoteTag WHERE tagId = ( SELECT id FROM Tag WHERE `name` = '{$tagName}' LIMIT 1 )"); $reader = $command->query(); $row = $reader->read(); $quotesCount = $row['totalCount']; $pages = new CPagination($quotesCount); $config->applyTo($pages); //$pages->applyLimit($criteria); $tag = Tag::model()->with(array('quotes' => array( 'condition' => 'approvedTime', 'order' => 'approvedTime DESC', 'offset' => 0, 'limit' => 1, )))->find($criteria); if($tag === null) throw new CHttpException(404, 'Tag not found'); */ $this->controller->render('tag', array('tag' => $tag, 'quotes' => $quotes, 'pages' => $pages)); }