Location: PHPKode > projects > DIY Blog > diy-blog/classes/diy-blog/model/PostResource.php
<?php

require_once 'diy-blog/model/FrontEndResource.php';

require_once 'diy-blog/model/om/BaseFrontEndResource.php';

/**
 * A frontend Resource for diplaying a single PostPage.
 * Originally generated by Propel.
 *
 * @package	diy-blog.model
 * @author	Martynas Jusevicius <hide@address.com>
 * @link	http://www.xml.lt
 */

class PostResource extends FrontEndResource
{

	/**
	 * Constructs a new PostResource class, setting the Type column to FrontEndResourcePeer::CLASSKEY_POSTRESOURCE.
	 */
	public function __construct()
	{

		$this->setType(FrontEndResourcePeer::CLASSKEY_POSTRESOURCE);
	}

	public function doGet(Request $request, Response $response)
	{
		$view = null;
		$parent = parent::doGet($request, $response);

		if ($parent != null) $view = $parent;
		else $view = new ReadPostView($this);

		return $view;
	}

	public function doPost(Request $request, Response $response)
	{
		$view = null;
		$parent = parent::doPost($request, $response);

		if ($parent != null) $view = $parent;
		else
		{
			if ($request->getParameter("action") == "comment")
			{
				
				$errors = array();
				$form = new CommentForm($request);
				$errors = $form->validate();

				try
				{
					if (count($errors) != 0) throw new InvalidFormException();

					if ($form->getCaptcha() != $request->getSession()->getAttribute("captcha"))
					{
						$errors[] = new Error("invalidCaptcha");
						throw new InvalidFormException();
					}

					$post = $this->getPages();
					$post = $post[0];
					$comment = new Comment();
					if ($form->getName() != null) $comment->setName($form->getName());
					if ($form->getTitle() != null) $comment->setTitle($form->getTitle());
					if ($form->getWebsite() != null) $comment->setWebsite($form->getWebsite());
					$comment->setContent($form->getContent());
					$comment->setPage($post);
					$comment->setDateTime(date("Y-m-d H:i:s"));

					$comment->save();

					$request->setAttribute("comment-result", "success");
				}
				catch (InvalidFormException $e)
				{
					$request->setAttribute("comment-result", "failure");
				}

				$request->setAttribute("comment-form", $form);
				$request->setAttribute("comment-errors", $errors);
			}

			$view = new ReadPostView($this);
		}
		return $view;
	}

} // PostResource
Return current item: DIY Blog