<?php
/*
 * created on 16.10.2007
 * project: zf-konference
 * author: Vlastimil Vávrů (http://vavru.cz)
 * version: $
 */

/**
 * Article service layer class. Contains all business methods associated with @link Articles.
 */
class ArticleService {

	/**
	 * Articles model
	 * 
	 * @var Articles
	 */
	private $_articles;
	
	/**
     * Public constructor
     */
	public function __construct() {}
	
	public function getArticles() {
		if($this->_articles == null) {
			$this->_articles = new Articles();
		}
		return $this->_articles;
	}
	
	/**
	 * Finds products with specified restrictions.
	 * 
	 * @return Venturia_Db_Table_Rowset_ScrollAble scrollable rowset
	 */
	public function findArticles($filter = null, $order = null, $maxResults = null, $firstResult = null) {
		return $this->getArticles()->fetchAllScrollAble($filter, $order, $maxResults, $firstResult);
	}
	
	/**
	 * Returns article specified by rewrite string. If article not found NULL is returned.
	 * 
	 * @param string $rewriteString
	 */
	public function getArticleByRewriteString($rewriteString) {
		return $this->getArticles()->fetchRow(array (
			'rewrite_string = ?' => $rewriteString
		));
	}
	
	/**
	 * Returns article specified by id. If article not found NULL is returned.
	 * 
	 * @param int $id
	 */
	public function getArticleById($id) {
		return $this->getArticles()->fetchRow(array (
			'id = ?' => $id
		));
	}
	
	/**
	 * Updates or inserts @link Article to database. 
	 * 
	 * @param Article $article
	 */
	public function saveArticle(Article $article) {
		$article->save();
	}
	
	/**
	 * Deletes @link Article from database. 
	 * 
	 * @param Article $article
	 */
	public function deleteArticle(Article $article) {
		$article->delete();
	}
}

?>
