<?php

	class FormFieldEventHandler extends kDBEventHandler {

		/**
		 * Returns form field visibility filter
		 *
		 * @return string
		 */
		function getVisiblilityFilter()
		{
			if ($this->Application->LoggedIn() && !$this->Application->isAdminUser) {
				return '%1$s.Visibility = ' . FORM_FIELD_EVERYONE;
			}

			return '';
		}

		/**
		 * Shows fields based on user logged-in status
		 *
		 * @param kEvent $event
		 */
		function SetCustomQuery(&$event)
		{
			parent::SetCustomQuery($event);

			$object =& $event->getObject();
			/* @var $object kDBList */

			$visibility_filter = $this->getVisiblilityFilter();

			$object->addFilter('visibility_filter', $visibility_filter);
		}
	}
