<?php

	namespace Mocha\UI\Pages;
	use Mocha\Core\InstanceKey;
	use Mocha\Core\KnownInstanceGuids;
	use Mocha\Core\KnownRelationshipGuids;
	use Mocha\Core\OmsContext;
	use Mocha\UI\Renderers\HTML\HTMLRenderer;
	use Phast\RenderingEventArgs;
	use Phast\WebPage;

	class TaskPage extends WebPage
	{

		protected function OnRendering(RenderingEventArgs $re)
		{
			parent::OnRendering($re);

			/**
			 * @var \Mocha\Oms\MySQLDatabaseOms
			 */
			$oms = mocha_get_oms();

			$taskKey = InstanceKey::Parse($this->Page->GetPathVariableValue("instid"));
			$taskInstance = $oms->getInstanceByKey($taskKey);
			$initiatingElement = $oms->getRelatedInstance($taskInstance, KnownRelationshipGuids::Task__has_initiating__Element);

			$context = new OmsContext();
			$taskRenderer = new HTMLRenderer($context);
			//$taskRenderer->TargetInstance = $instance;
			$taskRenderer->IsPostback = $this->Page->IsPostback;
			if ($this->Page->IsPostback)
			{
				$taskRenderer->processPostback(element: $initiatingElement);
			}
			$taskRenderer->renderTask($taskInstance);
			exit();
		}

	}
?>