<?php

include_once 'classes/core/Site.class.php';

/**
 * @author vinadelmar <vinadelmar@users.sourceforge.net>
 * @since  2006-04-05
 * @static
 */
class Family {
	/**
	 * @return integer;
	 */
	function getParentObjAclId(&$obj) {
		$class_name = strtolower(get_class($obj));
		
		switch ($class_name) {
		case 'content':
			$aclId = Family::_getContentParentAclId($obj);
			break;
			
		case 'container':
			$aclId = Family::_getContainerParentAclId($obj);
			break;
			
		case 'containerslist':
			$aclId = Family::getPageAclId();
			break;
			
		case 'menu':
			$aclId = Family::getPageAclId();
			break;
			
		case 'page':
			$acl = &$obj->getPageAcl();
			$aclId = $acl->getAclId();
			break;
		}
		
		return $aclId;
	}
	
	/**
	 * @acces  private
	 * @return integer acl id or 0 if error
	 */
	function _getContentParentAclid(&$content) {
		$site = &Site::getInstance();
		$dbManipulator = &$site->getDBManipulator();
		
		$contentId = $content->getContentId();
		$contentType = $content->getContentTypeName();
		
		$result = $dbManipulator->queryGetContainerOfContent($contentId, $contentType);
		
		if (!$result || !$dbManipulator->getNumRows())
			return 0;
			
		$row = $dbManipulator->fetchArray($result);
		
		$aclId = (int )$row['acl_id'];
		
		return $aclId;
	}
	
	/**
	 * @acces  private
	 * @return integer acl id or 0 if error
	 */
	function _getContainerParentAclId(&$container) {
		$site = &Site::getInstance();
		$dbManipulator = &$site->getDBManipulator();
		
		$containerId      = $container->getContainerId();
		$containerName    = $container->getContainerName();
		$containersListId = $container->getContainersListId();
		
		//echo '<pre>',var_dump($container->getContainersListId()),'</pre>';
		
		if (!$containersListId) {
			return Family::getPageAclId();
		}
		
		$result = $dbManipulator->queryGetContainersListOfContainer($containersListId, $containerId);
		
		if (!$result || !$dbManipulator->getNumRows()) {
			return 0;
		}
			
		$row = $dbManipulator->fetchArray($result);
		
		$aclId = (int )$row['acl_id'];
		
		return $aclId;
	}
	
	/**
	 * @acces  private
	 * @return integer acl id or 0 if error
	 */
	function _getContainersListParentAclId(&$containersList) {
		return Family::getPageAclId();
	}
	
	/**
	 * @acces  private
	 * @return integer acl id or 0 if error
	 */
	function _getMenuParentAclId(&$menu) {
		return Family::getPageAclId();
	}
	
	function getPageAclId() {
		$site = &Site::getInstance();
		$page = &$site->getCurrentPage();
		
		$pageAcl = &$page->getPageAcl();
		$aclId   = $pageAcl->getAclId();
		
		return $aclId;
	}
}

?>