<?php
/**
* СодеÑÐ¶Ð¸Ñ ÐºÐ»Ð°ÑÑ Control
*
* @package energine
* @author dr.Pavka
* @copyright ColoCall 2006
* @version $Id: Control.class.php,v 1.4 2007/12/17 14:16:14 pavka Exp $
*/
//require_once('core/framework/Object.class.php');
/**
* ÐÐ»ÐµÐ¼ÐµÐ½Ñ ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ Ð¿Ð°Ð½ÐµÐ»Ð¸ инÑÑÑÑменÑов
*
* @package energine
* @abstract
*/
abstract class Control extends Object {
/**
* ÐÐ¼Ñ Ñега ÑлеменÑа
*/
const TAG_NAME = 'control';
/**
* ÐокÑменÑ
*
* @var DOMDocument
* @access protected
*/
protected $doc;
/**
* Тип ÑлеменÑа
*
* @access protected
* @var string
*/
protected $type = false;
/**
* ÐоÑÑÑпноÑÑÑ ÑлеменÑа
*
* @access private
* @var boolean
*/
private $disabled = false;
/**
* ÐополниÑелÑнÑе аÑÑибÑÑÑ
*
* @var array
* @access private
*/
private $attributes = array();
/**
* ÐÐ°Ð½ÐµÐ»Ñ ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ Ðº коÑоÑÐ¾Ð¼Ñ Ð¿ÑивÑзан ÑÐ»ÐµÐ¼ÐµÐ½Ñ ÑпÑавлениÑ
*
* @var ToolBar
* @access private
*/
private $toolbar;
/**
* ÐÐ½Ð´ÐµÐºÑ ÑлеменÑа.
* ÐÑиÑваиваеÑÑÑ Ð¿Ð°Ð½ÐµÐ»ÑÑ Ð¸Ð½ÑÑÑÑменÑов поÑле пÑиÑÐ¾ÐµÐ´Ð¸Ð½ÐµÐ½Ð¸Ñ ÑлеменÑа.
*
* @var int
* @access private
*/
private $index = false;
/**
* ÐонÑÑÑÑкÑоÑ
*
* @param string $id
* @param string $action
* @param string $image
* @param string $title
* @param string $tooltip
* @access public
*/
public function __construct() {
parent::__construct();
$this->doc = new DOMDocument('1.0', 'UTF-8');
}
/**
* ÐÑивÑзÑваем ÑÐ»ÐµÐ¼ÐµÐ½Ñ ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ Ðº панели ÑпÑавлениÑ
*
* @param Toolbar
* @return void
* @access public
*/
public function attach($toolbar) {
$this->toolbar = $toolbar;
}
/**
* ÐозвÑаÑÐ°ÐµÑ Ð¿Ð°Ð½ÐµÐ»Ñ ÑпÑавлениÑ
*
* @return Toolbar
* @access protected
*/
protected function getToolbar() {
return $this->toolbar;
}
/**
* УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð¸Ð½Ð´ÐµÐºÑ ÑлеменÑа.
* ÐÑзÑваеÑÑÑ Ð¸Ð· панели инÑÑÑÑменÑов (Toolbar).
*
* @param int
* @return void
* @access public
*/
public function setIndex($index) {
$this->index = $index;
}
/**
* ÐозвÑаÑÐ°ÐµÑ Ð¸Ð½Ð´ÐµÐºÑ ÑлеменÑа.
* ÐÑзÑваеÑÑÑ Ð¸Ð· панели инÑÑÑÑменÑов (Toolbar).
*
* @return int
* @access public
*/
public function getIndex() {
if ($this->index === false) {
throw new SystemException('ERR_DEV_NO_CONTROL_INDEX', SystemException::ERR_DEVELOPER);
}
return $this->index;
}
/**
* ÐагÑÑзка ÑлеменÑа из XML-опиÑаниÑ.
*
* @param SimpleXMLElement $description
* @return boolean
* @access public
*/
public function loadFromXml(SimpleXMLElement $description) {
if (!isset($description['type'])) {
throw new SystemException('ERR_DEV_NO_CONTROL_TYPE', SystemException::ERR_DEVELOPER);
}
$attr = $description->attributes();
$this->setAttribute('mode', FieldDescription::computeRights($this->getToolbar()->getComponent()->getMethodRights(), !is_null($attr['ro_rights'])?(int)$attr['ro_rights']:null, !is_null($attr['fc_rights'])?(int)$attr['fc_rights']:null));
if (isset($attr['ro_rights'])) {
unset($attr['ro_rights']);
}
if (isset($attr['fc_rights'])) {
unset($attr['fc_rights']);
}
foreach ($attr as $key => $value) {
if (isset($this->$key)) {
$this->$key = (string)$value;
}
else {
$this->setAttribute($key, (string)$value);
}
}
}
/**
* ÐÑклÑÑÐ°ÐµÑ ÑÐ»ÐµÐ¼ÐµÐ½Ñ (Ð´ÐµÐ»Ð°ÐµÑ ÐµÐ³Ð¾ недоÑÑÑпнÑм).
*
* @return void
* @access public
*/
public function disable() {
$this->disabled = true;
}
/**
* ÐклÑÑÐ°ÐµÑ ÑлеменÑ.
*
* @return void
* @access public
*/
public function enable() {
$this->disabled = false;
}
/**
* ÐозвÑаÑÐ°ÐµÑ Ñип ÑлеменÑа.
*
* @return string
* @access public
*/
public function getType() {
if (!$this->type) {
throw new SystemException('ERR_DEV_NO_CONTROL_TYPE', SystemException::ERR_DEVELOPER);
}
return $this->type;
}
/**
* УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð·Ð½Ð°Ñение аÑÑибÑÑа.
*
* @param string
* @param mixed
* @return void
* @access public
*/
public function setAttribute($attrName, $attrValue) {
$this->attributes[$attrName] = $attrValue;
}
/**
* ÐозвÑаÑÐ°ÐµÑ Ð·Ð½Ð°Ñение аÑÑибÑÑа.
*
* @param string
* @return mixed
* @access public
*/
public function getAttribute($attrName) {
if (isset($this->attributes[$attrName])) {
return $this->attributes[$attrName];
}
return false;
}
/**
* ÐоÑÑÑоение ÑлеменÑа ÑпÑавлениÑ.
*
* @return DOMNode
* @access public
*/
public function build() {
$controlElem = $this->doc->createElement(self::TAG_NAME);
foreach ($this->attributes as $attrName => $attrValue) {
$controlElem->setAttribute($attrName, $attrValue);
}
if ($this->disabled) {
$controlElem->setAttribute('disabled', 'disabled');
}
$controlElem->setAttribute('type', $this->getType());
$this->doc->appendChild($controlElem);
return $this->doc->documentElement;
}
/**
* ÐеÑÐµÐ²Ð¾Ð´Ð¸Ñ ÑзÑко-завиÑимÑе аÑÑибÑÑÑ.
*
* @param array пеÑеÑÐµÐ½Ñ Ð°ÑÑибÑÑов дÑÐ»Ñ Ð¿ÐµÑевода
* @return type
* @access public
*/
public function translate($attrs = array('title', 'tooltip')) {
foreach ($attrs as $attrName) {
$attrValue = (string)$this->getAttribute($attrName);
if ($attrValue) {
$this->setAttribute($attrName, DBWorker::_translate($attrValue));
}
}
}
}