<?php
set_include_path( dirname(__FILE__). '/services' . PATH_SEPARATOR . dirname(__FILE__). '/services/vo' . PATH_SEPARATOR . get_include_path() ); class InfoModuleRender { private $content, $structure, $config; private $service = null; private $parent = null; function __construct($parent) { $this->content = $parent->getContent(); $this->structure = $parent->getStructure(); $this->config = $parent->getConfig(); $this->parent = $parent; } function renderModule($id) { if (is_null($this->service)) $this->service = new InfoModuleService(); $data = array('structure' => null, 'data' => null); $moduleVO = ModuleVO::findById($id, $this->content); $xmlfilename = ''; $checkDom = new DOMDocument(); $checkDom->loadXML($moduleVO->data); $node = $checkDom->getElementsByTagName("dataProvider"); if ($node) { $file = $node->item(0)->nodeValue; if (strlen($file) > 0) $xmlfilename = MOTO_ROOT_DIR . '/' . $file; } if ($xmlfilename == '' || !file_exists($xmlfilename)) { return ''; } $responceVO = $this->service->getInfoModuleStructure($moduleVO->data); if (!is_null($responceVO->result) && is_array($responceVO->result->properties)) { foreach($responceVO->result->properties as $property) { $data['structure'][$property->id] = $property->type; } } $responceVO = $this->service->getInfoModuleData($moduleVO->data); if (!is_null($responceVO->result) && is_array($responceVO->result)) { foreach($responceVO->result as $newsVO) { $news = array(); $news['id'] = $newsVO->id; $news['order'] = $newsVO->order; foreach($newsVO->properties as $property) { $news['data'][] = array( 'type' => $data['structure'][$property->propertyType], 'value' => $property->value ); } $data['data'][$news['id']] = $news; } } return $this->renderHtml($data); } function renderHtml($data) { $html = ''; $html .= "\n\n" . '<div class="infoModule">'; if (isset($data['data']) && is_array($data['data'])) foreach($data['data'] as $news) { $html .= $this->_renderHtml($news); } $html .= '</div>' . "\n\n"; return $html; } function _renderHtml($obj) { $htmlData = array( 'htmlText' => '', 'image' => '', 'link' => '' ); if (isset($obj['data']) && is_array($obj['data'])) foreach($obj['data'] as $row) { switch($row['type']) { case 'image': $htmlData['image'] = $row['value']; break; case 'htmlText': $res = $this->parent->clearHtmlTextMobile($row['value'], array( 'class' => 'htmlText', 'trim' => true, 'initTag' => 'span' ) ); if (strip_tags($res) != '') $htmlData['htmlText'] = $res; break; case 'link': if ($row['value'] != 'none;') $htmlData['link'] = $this->parent->action2url('event:' . $row['value']); break; } } $html = ''; $html .= "\n"; $html .= '	<div class="infoModuleItem">' . "\n"; if ($htmlData['link'] != '') $html .= $htmlData['link']; if ($htmlData['image'] != '') { $html .= '<img src="' . rtrim(MOTO_ROOT_URL, '/') . '/' . $htmlData['image'] . '" />'; } if ($htmlData['htmlText'] != '') { $html .= $htmlData['htmlText']; } if ($htmlData['link'] != '') $html .= '</a>'; $html .= '</div>' . "\n\n"; return $html; } } 