public function render($viewId = null, $defines = array())
 {
     if ($viewId === null) {
         throw new ZException('ViewId must defined at call of ' . get_class($this) . '#render().');
     }
     /*
      * Binding viewId to the composition's
      */
     $this->viewId = $viewId;
     $this->coreLibrary = $this->getAspect()->getLibraryNamespace(self::CORE_LIBRARY);
     $this->insertTagname = empty($this->coreLibrary) ? self::INSERT_TAGNAME : $this->coreLibrary . ':' . self::INSERT_TAGNAME;
     $inserts = ZXmlUtil::getElementsByName($this->getDocumentTree(), self::INSERT_TAGNAME, $this->coreLibrary);
     $inserts = $this->getNameAttributeBinded($inserts);
     $defines = $this->getNameAttributeBinded($defines);
     foreach ($inserts as &$insert) {
         if (!array_key_exists(ZXml::TAG_ATTRIBUTES_KEY, $insert) || !array_key_exists(self::INSERT_NAME_ATTRIBUTE, $insert[ZXml::TAG_ATTRIBUTES_KEY])) {
             throw new ZElementException('Insert element must have "' . self::INSERT_NAME_ATTRIBUTE . '" attribute.');
         }
         $name = $insert[ZXml::TAG_ATTRIBUTES_KEY][self::INSERT_NAME_ATTRIBUTE];
         /*
          * Replace children if matches any define element.
          */
         if (array_key_exists($name, $defines) && array_key_exists(ZXml::TAG_CHILDREN_KEY, $defines[$name])) {
             $insert[ZXml::TAG_CHILDREN_KEY] = $defines[$name][ZXml::TAG_CHILDREN_KEY];
         }
     }
     /*
      * Binding own meta insert.
      */
     $this->bindInserts($inserts, $this->document[1]);
     return parent::render();
 }
 public function render()
 {
     parent::render();
     $o = ZXmlUtil::renderArray(array(0 => 'grid', 1 => array('flex' => $this->flex, 'id' => $this->id)), true);
     $o .= '<columns>';
     for ($i = 0; $i < $this->columns; ++$i) {
         $o .= ZXmlUtil::renderArray(array(0 => 'column', 1 => array('flex' => $this->flex)));
     }
     $o .= '</columns>';
     $o .= '<rows>';
     $childNum = 0;
     foreach ($this->renderedChildren as $child) {
         if (is_string($child) && trim($child) == '') {
             continue;
         }
         if ($childNum == 0) {
             $o .= '<row>';
         }
         $o .= $child;
         if (++$childNum == $this->columns) {
             $o .= '</row>';
             $childNum = 0;
         }
     }
     if ($childNum != 0) {
         $o .= '</row>';
     }
     $o .= '</rows>';
     $o .= '</grid>';
     return $o;
 }
 public function init()
 {
     if ($this->template == null) {
         throw new ZElementException('Composition must have template');
     }
     $this->templateDocument = $this->getAspect()->createTemplateDocument(APP_PATH . $this->template);
     $coreNamespace = $this->getAspect()->getLibraryNamespace('core');
     $mySelf = array(ZXml::TAG_NAME_KEY => $this->fullName, ZXml::TAG_CHILDREN_KEY => $this->children);
     $defineElements = ZXmlUtil::getElementsByName($mySelf, 'define', $coreNamespace);
     $this->defines = $defineElements;
     $params = ZXmlUtil::getElementsByName($mySelf, 'param', $coreNamespace);
     foreach ($params as $param) {
         if (!isset($param[ZXml::TAG_ATTRIBUTES_KEY]['name']) || !isset($param[ZXml::TAG_ATTRIBUTES_KEY]['name'])) {
             throw new ZElementException('Param element must have "name" and "value" attributes.');
         }
         $key = $param[ZXml::TAG_ATTRIBUTES_KEY]['name'];
         $value = $param[ZXml::TAG_ATTRIBUTES_KEY]['value'];
         $value = $this->evaluateZX($value);
         $this->templateDocument->setContext($key, $value);
     }
 }
 public function handleReRender()
 {
     $reRender = isset($_REQUEST['reRender']) ? $_REQUEST['reRender'] : false;
     $jsonResult = array();
     if ($reRender) {
         $toReRender = explode(',', $reRender);
         $toReRender = array_map('trim', $toReRender);
         foreach ($toReRender as $rendering) {
             list($viewId, $id) = array_map('trim', explode(':', $rendering));
             $doc = ZXmlParser::fromFileToTree(APP_PATH . $viewId);
             $element = ZXmlUtil::getElementById($doc[1], $id);
             $wrapper = array(0 => '', 1 => array(0 => 'z:fragment', 1 => array('xmlns:z' => 'lib://core', 'xmlns:c' => 'lib://control', 'xmlns:f' => 'lib://form', 'xmlns:l' => 'lib://layout'), 2 => array($element)));
             $docToRender = $this->aspect->createDocumentFromTree($viewId, $wrapper);
             $rendered = $docToRender->render();
             $xmlTree = ZXmlParser::toTree($rendered);
             $jsonResult[$id] = $xmlTree[1];
         }
         $this->envelope->reRender = $jsonResult;
         echo $this->envelope->toJSON();
     }
 }