Location: PHPKode > projects > Mocovie web framework > webs/common/controls/overviewlist.php
<?php
/**
 *  Copyright (C) 2010  Kai Dorschner
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Kai Dorschner <the-hide@address.com>
 * @copyright Copyright 2010, Kai Dorschner
 * @license http://www.gnu.org/licenses/gpl.html GPLv3
 * @package mocovi
 * @subpackage controls
 */

/**
 * Require Dirlist Control
 */
ControlFactory::load('dirlist');

/**
 * An overview list shows the directly descendant content in a preview.
 *
 * The descendant content is parsed and the first headline, image and paragraph
 * will be chosen to build a preview of the following content.
 *
 * @package mocovi
 * @subpackage controls
 */
class overviewlist_control extends dirlist_control
{
	protected $defaultOptions = array
		( 'source'		=> '.'	// Source from where the elements are shown
		, 'hidecurrent'	=> '0'	// Prevent current page from being displayes
		, 'maxelements'	=> '10'	// Maximum displayed elements
		);

	/**
	 * Defines the childname for XML. Later this name will be needed to parse
	 * it with XSL, so be sure to be conventional
	 */
	protected $childname = 'element';

	// @todo Bei run(); soll erst überprüft werden ob Unterlemente vorhanden sind, dann soll der Node created werden.

	/**
	 * @override
	 */
	protected function program()
	{
		$this->setRules();
		if($this->getOption('source') != '')
		{
			if($this->getOption('source') == '.')
				$this->options['source'] = $GLOBALS['page'] . '/';
			$list = $GLOBALS['filesystem']->getList($this->getOption('source'));
			$this->node->setAttribute('source', $this->getOption('source'));
			$i = 0;
			foreach($list as $element)
			{
				$current = $this->dom->createElement($this->childname);
				$dom = new DomDocument();
				$dom->appendChild($dom->importNode($element, true));
				$xpath = new DomXPath($dom);
				$xpath->registerNameSpace('mocovi', Mocovi::$namespace);
				if($this->isValid($xpath->query('@name')->item(0)->nodeValue))
				{
					$currentpage = $this->getOption('source').$element->getAttribute('name');
					if($currentpage == $GLOBALS['page'])
					{
						if($this->getOption('hidecurrent') == '1')
							continue;
						else
							$current->setAttribute('active', 'true');
					}
					$current->setAttribute('source', $element->getAttribute('name'));
					if($node = $xpath->query('mocovi:model//mocovi:article//mocovi:headline[1]')->item(0))
						$current->appendChild(controlFactory::create($node)->load($this->node)->run());

					if($node = $xpath->query('//mocovi:image[1]|//mocovi:descriptionimage[1]')->item(0))
						$current->appendChild(controlFactory::create($node)->load($this->node)->run());

					if($node = $xpath->query('mocovi:model//mocovi:prefacetext[1]|mocovi:model//mocovi:paragraph[1]|mocovi:model//mocovi:wikitext[1]|mocovi:model//mocovi:text[1]')->item(0))
						$current->appendChild(controlFactory::create($node)->load($this->node)->run());

					$this->node->appendChild($current);
					if($this->getOption('maxelements') <= $i+1)
						break;
					else
						$i++;
				}
			}
		} /* elseif(!$this->hasChilds()) {
			If empty
		}*/
	}
}
Return current item: Mocovie web framework