All pastes #362245 Raw Edit

Unnamed

public php v1 · immutable
·published 2007-02-18 17:39 UTC
rendered paste body
class ArticlesLibraryController extends ContentPageController{	/**	 * INPUT:	 * ? action: One of 'search', null.	 */	public function execute()	{			parent::execute();				global $IO;		// read input				$this->input('?','action')->isOneOf(array('search'));		$IO['articles'] = null;				switch($IO->action) {			case 'search':				$this->onSearch();				break;			case null:				$this->onDefault();				break;			default:				$this->onInvalid();				break;		}	}		/**	 * Search action.	 * 	 * INPUT: 	 * ? page: Number of the current page. 	 * ? count: Number of news per page. 	 * ? query: The search string entry based on what the module returns 	 *     the filtered article list. 	 * ? level: Article level, one of 'a', 'b', 'c'. 	 * 	 * OUTPUT: 	 * totalCount: The count of all articles after the search filter. 	 * articles: Indexed array of assoc arrays. 	 *     articles[][id]: Article id. 	 *     articles[][title]: Article title. 	 *     articles[][authorId]: The id of the article's author. 	 *     articles[][authorName]: The full name of the article's author. 	 *     articles[][snippet]: Article excerpt (first 255 symbols of the body).	 */	private function onSearch()	{		global $IO;				$articles = Articles::getInstance();				$totalCount = $articles->getCount($IO['query'], $filter);						$maxPages = ceil($totalCount / $IO['count']);		$offset = ($IO['page']-1)*$IO['count'];				// read input		$this->input('?','query')->isNotEmpty();		$this->input('?','level')->isOneOf(array('a','b','c'));		$this->input('?','page',1)->isInt()->setRange(1,$maxPages);		$this->input('?','count',10)->isInt()->setRange(5,50);				if (!$IO['query']) {			$this->onDefault();			return;		}						// generate output		$IO['totalCount'] = $totalCount;		$IO['articles'] = $articles->getAll(			$offset, 			$IO['count'],			$IO['query']		);	}		private function onDefault()	{		global $IO;				// ....		// ....	}		private function onInvalid()	{		global $IO;				$this->addMessage('Invalid action.', '', E_USER_ERROR, 4);		$IO['action'] = null;	}}