Location: PHPKode > projects > DIY Blog > diy-blog/classes/diy-blog/backend/controller/forms/PageForm.class.php
<?php

/**
 * Abstracts page creation/editing request parameters.
 * @package diy-blog.backend.controller.forms
 * @author	Martynas Jusevicius <hide@address.com>
 * @link	http://www.xml.lt
 */

class PageForm extends Form
{
	private $url = null;
	private $enterUrl = false;
	private $title = null;
	private $content = null;
	private $year = null;
	private $month = null;
	private $day = null;
	private $hour = null;
	private $minute = null;
	private $second = null;
	
	public function __construct(Request $request)
	{
		$this->url = $request->getParameter("url");
		$this->enterUrl = ($request->getParameter("enter-url") == "true");
		$this->title = $request->getParameter("title");
		$this->content = $request->getParameter("content");
		$this->year = $request->getParameter("year");
		$this->month = $request->getParameter("month");
		$this->day = $request->getParameter("day");
		$this->hour = $request->getParameter("hour");
		$this->minute = $request->getParameter("minute");
		$this->second = $request->getParameter("second");
	}

	public function getURL()
	{
		return $this->url;
	}

	public function isURLEntered()
	{
		return $this->enterUrl;
	}

	public function getTitle()
	{
		return $this->title;
	}

	public function getDateTime()
	{
		return $this->year.$this->month.$this->day." ".$this->hour.":".$this->minute.":".$this->second;
	}

	public function getYear()
	{
		return $this->year;
	}

	public function getMonth()
	{
		return $this->month;
	}

	public function getDay()
	{
		return $this->day;
	}

	public function getHour()
	{
		return $this->hour;
	}

	public function getMinute()
	{
		return $this->minute;
	}

	public function getSecond()
	{
		return $this->second;
	}

	public function getContent()
	{
		return $this->content;
	}

	public function validate()
	{
		$errors = array();

		if ($this->year == null || $this->month == null || $this->day == null || $this->hour == null || $this->minute == null || $this->second == null) $errors[] = new Error("noDateTime");
		if (!checkdate((int)$this->month, (int)$this->day, (int)$this->year)) $errors[] = new Error("invalidDateTime");
		if (!((int)$this->hour >= 0 && (int)$this->hour < 24 && (int)$this->minute >= 0 && (int)$this->minute < 60 && (int)$this->second >= 0 && (int)$this->second < 60)) $errors[] = new Error("invalidDateTime");

		if ($this->title == null) $errors[] = new Error("noTitle");
		if ($this->content == null) $errors[] = new Error("noContent");

		$doc = new DOMDocument();
		if (!@$doc->loadXML("<div>".$this->content."</div>")) $errors[] = new Error("invalidContent");

		return $errors;
	}
}

?>
Return current item: DIY Blog