<?php


/*
 * created on 11.3.2007
 * project: zend-hello-world
 * author: vlasta
 * version: $
 */
 
require_once('business/pers/Category.php');
require_once('business/pers/Article.php');

class ArticleService {
	private $categories;

	public function __construct() {
		$this->categories = array ();

		$article1 = new Article();
		$article1->name = "Úvod do Zend Frameworku";
		$article1->str = "uvod-do-zend-frameworku";
		$article1->text = "Toto je text článku 'Úvod do Zend Frameworku'";

		$article2 = new Article();
		$article2->name = "Zend Framework - Hello World projekt";
		$article2->str = "zend-framework-hello-world-projekt";
		$article2->text = "Toto je text článku 'Zend Framework - Hello World projekt'";

		$article3 = new Article();
		$article3->name = "Kódování JSP stránek a fmt tag library";
		$article3->str = "kodovani-jsp-stranek-a-fmt-tag-library";
		$article3->text = "Toto je text článku 'Kódování JSP stránek a fmt tag library'";

		$cat1 = new Category();
		$cat1->name = "PHP";
		$cat1->str = "php";
		$cat1->articles = array (
			$article1,
			$article2
		);

		$cat2 = new Category();
		$cat2->name = "Java";
		$cat2->str = "java";
		$cat2->articles = array (
			$article3
		);
		
		$article1->category = $cat1;
		$article2->category = $cat1;
		$article3->category = $cat2;
		
		$this->categories = array($cat1, $cat2);
	}

	public function getCategoryByStr($categoryStr) {
		foreach ($this->categories as $category) {
			if ($category->str == $categoryStr) {
				return $category;
			}
		}
		return null;
	}

	public function getArticleByStr($articleStr) {
		foreach ($this->categories as $category) {
			foreach ($category->articles as $article) {
				if ($article->str == $articleStr) {
					return $article;
				}
			}
		}
		return null;
	}

	public function findAllCategories() {
		return $this->categories;
	}
}
?>