protected function _render() { $content = null; $elems = View::getObjects(View::PH_DEFAULT); if (is_array($elems)) { foreach ($elems as $elem) { $object = $elem[0]; $params = $elem[1]; if (!is_object($object)) { continue; } /* @var $object t41\View\ViewObject */ switch (get_class($object)) { case 't41\\View\\ListComponent': case 't41\\View\\TableComponent': $object->setDecorator(); $decorator = Decorator::factory($object); $content .= $decorator->render(); break; default: break; } } } return $content; }
public function render() { if (($value = $this->_obj->getValue()) !== false) { if (($value instanceof ObjectModel\BaseObject || $value instanceof ObjectModel\DataObject) && $value->getUri()) { $value = $this->_obj->getParameter('altkey') ? $value->getProperty($this->_obj->getParameter('altkey'))->getValue() : $value->getUri()->getIdentifier(); } else { if ($value instanceof ObjectModel\ObjectUri) { $value = $value->getIdentifier(); } else { $value = null; } } } $name = $this->_obj->getId(); // set correct name for field name value depending on 'mode' parameter value if ($this->getParameter('mode') == View\FormComponent::SEARCH_MODE) { $name = ViewUri::getUriAdapter()->getIdentifier('search') . '[' . $name . ']'; } View::addCoreLib(array('core.js', 'locale.js', 'view.js', 'view:table.js', 'view:action:autocomplete.js')); $acfield = new View\FormComponent\Element\FieldElement('_' . $this->_nametoDomId($name)); $acfield->setValue($value); $action = new AutocompleteAction($this->_obj->getCollection()); $objsearchprops = $this->_obj->getParameter('search') ? $this->_obj->getParameter('search') : $this->_obj->getParameter('display'); $action->setParameter('searchprops', explode(',', $this->getParameter('searchprops') ? $this->getParameter('searchprops') : $objsearchprops)); $action->setParameter('searchmode', $this->getParameter('searchmode')); $action->setParameter('display', explode(',', $this->_obj->getParameter('display'))); $action->setParameter('sdisplay', explode(',', $this->_obj->getParameter('sdisplay') ? $this->_obj->getParameter('sdisplay') : $this->_obj->getParameter('display'))); $action->setParameter('event', 'keyup'); // if a list of properties to be returned exists, pass it to the action if ($this->getParameter('retprops')) { $action->setParameter('member_reduce_params', array('props' => explode(',', $this->getParameter('retprops')))); } $action->setContextData('onclick', 't41.view.element.autocomplete.close'); $action->setContextData('target', $this->_nametoDomId($name)); $action->bind($acfield); $deco = View\Decorator::factory($acfield); $html = $deco->render(); $deco = View\Decorator::factory($action); $deco->render(); $html .= sprintf('<input type="hidden" name="%s" id="%s" value="%s"/>', $name, $this->_nametoDomId($name), $value); return $html . "\n"; }
public function render() { // set correct name for field name value depending on 'mode' parameter value $name = $this->_obj->getId(); $prefix = Core::getController('medias'); if (!$prefix) { $prefix = '/t41/medias/'; } $uri = $prefix . 'upload'; View::addCoreLib(array('core.js', 'locale.js', 'view.js', 'uploader.css', 'view:action:upload.js')); View::addEvent(sprintf("t41.view.register('%s_ul', new t41.view.action.upload(jQuery('#%s_ul'),'%s'))", $name, $name, $uri), 'js'); $html = ''; // @todo code media deletion JS if ($this->_obj->getValue() != null) { $html .= sprintf('<span><a href="%s" target="_blank">%s %s</a> | <a href="#" onclick="t41.view.get(\'%s_ul\').reset(this)">%s</a></span>', MediaElement::getDownloadUrl($this->_obj->getValue()->getUri()), 'Télécharger', $this->_obj->getValue()->getLabel(), $name, 'Supprimer'); } $html .= sprintf('<div id="%s_ul" class="qq-upload-list"></div>', $this->_nametoDomId($name)); $html .= sprintf('<input type="hidden" name="%s" id="%s" value="%s" class="hiddenfilename"/>', $name, $this->_nametoDomId($name), $this->_obj->getValue() ? $this->_obj->getValue()->getIdentifier() : null); return $html; $action = new UploadAction($this->_obj); $deco = View\Decorator::factory($action); $deco->render(); return $html . "\n"; }
protected function _renderButton(Element\ButtonElement $button) { $deco = View\Decorator::factory($button, array('size' => 'medium')); return $deco->render(); }
public function _contentRendering() { $p = '<fieldset>'; foreach ($this->_obj->getColumns() as $key => $element) { $field = $element; $p .= '<span class="field">'; $p .= sprintf('<span class="label"><label for="%s[%s]">%s</label></span>', $this->_searchIdentifier, $field->getId(), $field->getTitle() ? $field->getTitle() : 'ID'); // get current field value from env if (isset($this->_env[$this->_searchIdentifier][$field->getId()])) { $field->setValue($this->_env[$this->_searchIdentifier][$field->getId()]); } // Reset default value to empty $field->setDefaultValue(''); $data = isset($this->_env[$this->_searchIdentifier]) ? $this->_env[$this->_searchIdentifier] : null; $deco = Decorator::factory($field, array('mode' => FormComponent::SEARCH_MODE, 'data' => $data)); $p .= ' ' . $deco->render(); $p .= '</span>'; } if ($this->_obj->getParameter('buttons') != false) { View::addCoreLib(array('buttons.css', 'sprites.css')); $p .= sprintf('<div class="clear"><a class="element button medium icon" onclick="jQuery(\'#t41sf\').submit()"><span class="search-blue"></span>Rechercher</a>' . '<a class="element button medium icon" onclick="jQuery(\'#t41sf\').find(\':input\').each(function() {jQuery(this).val(null)})"><span class="refresh"></span>RAZ</a></div>', $this->_obj->getParameter('baseurl')); } $p .= '</fieldset></form>'; return $p; }
protected function _formatValue($field, $value) { if ($value instanceof View\ObjectModel) { $deco = View\Decorator::factory($value); return $deco->render(); } else { return nl2br(htmlentities($field->formatValue($value))); } }
protected function _buttonsRendering(array $data) { $line = '<td id="buttons">'; foreach ($this->_obj->getButtons() as $button) { $deco = Decorator::factory($button); $deco->setParameter('data', $data); $line .= $deco->render(); } $line .= '</td>'; return $line; }
/** * Add all mandatory paths to configuration */ public static function preInit() { /* add application & t41 config files path (in first position if none was declared before) */ Config::addPath(self::$basePath . 'application/configs/', Config::REALM_CONFIGS); Config::addPath(self::$basePath . 'vendor/quatrain/t41/configs/', Config::REALM_CONFIGS); /* add templates folder path (in first position if none was declared before) */ Config::addPath(self::$basePath . 'application/views/', Config::REALM_TEMPLATES); /* add t41 & application controllers paths (in first position if none was declared before) */ Config::addPath(self::$basePath . 'application/controllers/', Config::REALM_CONTROLLERS, null, 'default'); Config::addPath(self::$basePath . 'vendor/quatrain/t41/controllers/', Config::REALM_CONTROLLERS, null, 't41'); /* register default REST controllers path */ /* @todo allow override in config file or even later */ Config::addPath(self::$basePath . 'vendor/quatrain/t41/controllers/rest/', Config::REALM_CONTROLLERS, null, 'rest'); /* register default path where to find view objects decorators */ Decorator::addPath(self::$basePath . 'vendor/quatrain/t41/library/t41'); // without 'View' }
protected function _formatValue($field, $value, $width = null) { if ($value instanceof ViewObject) { $deco = Decorator::factory($value); $this->_pdf->setXY($this->_pdf->getX() + 1, $this->_pdf->getY() + 1); return $deco->render($this->_pdf, $width * 0.8); } else { return $field->formatValue($value); } }
protected function _() { $template = file_get_contents($this->_template); // transform some characters $template = str_replace("\t", str_repeat(" ", 15), $template); $template = str_replace("\n", "<br/>", $template); $tagPattern = "/%([a-z0-9]+)\\:([a-z0-9.]*)\\{*([a-zA-Z0-9:,\\\"']*)\\}*%/"; $tags = array(); preg_match_all($tagPattern, $template, $tags, PREG_SET_ORDER); // PHASE 1 foreach ($tags as $key => $tag) { $content = ''; if ($tag[1] == 'env') { $content = \t41\Core::htmlEncode(\t41\View::getEnvData($tag[2])); unset($tag[$key]); } if (isset($tag[0])) { $template = str_replace($tag[0], $content, $template); } } $this->_document->writeHTML($template); // PHASE 2 - other tags foreach ($tags as $tag) { $content = ''; switch ($tag[1]) { case 'container': $elems = \t41\View::getObjects($tag[2]); if (is_array($elems)) { foreach ($elems as $elem) { $object = $elem[0]; $params = $elem[1]; if (!is_object($object)) { continue; } /* @var $object t41_Form_Abstract */ switch (get_class($object)) { case 't41_Form_List': case 't41_View_Table': case 't41_View_Image': case 't41_View_Component': case 't41_View_Error': case 't41_View_Spacer': $decorator = \t41\View\Decorator::factory($object, $params); $decorator->render($this->_document, $this->_width); break; default: break; } } } break; } } }
protected function _render() { $template = file_get_contents($this->_template); $tagPattern = "/%([a-z0-9]+)\\:([a-z0-9.]*)\\{*([a-zA-Z0-9:,\\\"']*)\\}*%/"; $tagPattern = "/%([a-z0-9]+)\\:([a-z0-9_.]*)\\{*([a-zA-Z0-9:_,\\\"']*)\\}*%/"; $tags = array(); preg_match_all($tagPattern, $template, $tags, PREG_SET_ORDER); // PHASE 1: analyse et parsing of content-generating tags foreach ($tags as $tag) { $content = false; switch ($tag[1]) { case 'helper': $tmp = explode('.', $tag[2]); $class = sprintf('%s\\View\\Web\\%s', $tmp[0], ucfirst($tmp[1])); try { $helper = new $class(); $content = $helper->render(); } catch (Exception $e) { if (Core::$env == Core::ENV_DEV) { $content = $e->getMessage(); } } break; case 'container': $elems = View::getObjects($tag[2]); if (is_array($elems)) { foreach ($elems as $elem) { $object = $elem[0]; $params = $elem[1]; if (!is_object($object)) { continue; } // look for a custom decorator $decorator = View\Decorator::factory($object, $params); $content .= $decorator->render(); } } break; } if ($content !== false) { $template = str_replace($tag[0], $content, $template); } } preg_match_all($tagPattern, $template, $tags, PREG_SET_ORDER); // PHASE 2: analyze & parsing of other tags (components linking & env variables) foreach ($tags as $tag) { $content = null; switch ($tag[1]) { case 'components': $content = $this->_renderComponents($tag[2], $tag[3]); break; case 'env': case 'var': $content = View::getEnvData($tag[2]); break; case 'obj': // obj: $tmp = explode('.', $tag[2]); $obj = View::getEnvData($tmp[0]); if ($obj instanceof MediaObject && isset($tmp[1])) { // meta properties handling switch ($tmp[1]) { case '_base64': $content = sprintf('data:%s;base64,%s', $obj->getMime(), base64_encode($obj->loadBlob('media'))); break; case '_icon': $content = 'file-' . $obj->getExtension(); break; case '_size': $content = MediaElement::getDisplaySize($obj->getSize()); break; case '_url': $content = MediaElement::getDownloadUrl($obj->getUri()); break; default: break; } } if (!$content) { if ($obj instanceof BaseObject) { $content = isset($tmp[1]) && $tmp[1] == ObjectUri::IDENTIFIER ? $obj->getIdentifier() : $obj->getProperty($tmp[1]); $content = $content instanceof AbstractProperty ? $content->getDisplayValue() : $content; } else { $content = Core::$env == Core::ENV_DEV ? sprintf("Can't substitute any value to '%s'", $tag[0]) : null; } } break; } $template = str_replace($tag[0], $content, $template); } // PHASE 3: actions attachment $this->actionAttach(); // PHASE 4: events attachment $template = str_replace('</body>', $this->eventAttach() . '</body>', $template); // PHASE 5: display logged errors in dev mode if (Core::$env == Core::ENV_DEV) { $errors = View::getErrors(); if (count($errors) > 0) { $str = "\n"; foreach ($errors as $errorCode => $errorbloc) { $str .= $errorCode . "\n"; foreach ($errorbloc as $error) { $str .= "\t" . $error[0] . "\n"; } } $template = str_replace('</body>', '</body><!--' . $str . ' -->', $template); } } return $template; }
/** * Parse given tags against current template * * @param array $tags */ protected function _parseTags($tags) { foreach ($tags as $tag) { $value = null; switch ($tag[1]) { case 'var': $keys = explode('.', $tag[2]); $value = $this->_obj->getVariable($keys[0]); if (count($keys) > 1) { $value = $value[$keys[1]]; } break; case 'env': $value = View::getEnvData($tag[2]); break; case 'container': if (($templates = $this->_obj->getSubtemplates($tag[2])) !== false) { $value = ''; foreach ($templates as $template) { $deco = Decorator::factory($template); $value .= $deco->render(); } } break; default: // obj: $tmp = explode('.', $tag[2]); $obj = $this->_obj->getVariable($tmp[0]); if ($obj instanceof MediaObject && isset($tmp[1])) { // meta properties handling switch ($tmp[1]) { case '_base64': $value = sprintf('data:%s;base64,%s', $obj->getMime(), base64_encode($obj->loadBlob('media'))); break; case '_icon': $value = 'file-' . $obj->getExtension(); break; case '_size': $value = MediaElement::getDisplaySize($obj->getSize()); break; case '_url': $value = MediaElement::getDownloadUrl($obj->getUri()); default: break; } } if (!$value) { if ($obj instanceof BaseObject) { $value = isset($tmp[1]) && $tmp[1] == ObjectUri::IDENTIFIER ? $obj->getIdentifier() : $obj->getProperty($tmp[1]); $value = $value instanceof AbstractProperty ? $value->getDisplayValue() : $value; } else { $value = Core::$env == Core::ENV_DEV ? sprintf("Can't substitute any value to '%s'", $tag[0]) : null; } } break; } if ($value instanceof ViewObject) { $deco = Decorator::factory($value); $value = $deco->render(); } else { //$value = $this->_escape($value); } $this->_template = str_replace($tag[0], $value, $this->_template); } }
public function render(\TCPDF $pdf, $width) { $this->_collection = $this->_obj->getCollection(); // set relevant uri adapter and get some identifiers if (!ViewUri::getUriAdapter() instanceof ViewUri\Adapter\GetAdapter) { $tmp = explode('?', $_SERVER['REQUEST_URI']); $this->_uriAdapter = new ViewUri\Adapter\GetAdapter($tmp[0]); } else { $this->_uriAdapter = ViewUri::getUriAdapter(); } $this->_offsetIdentifier = $this->_uriAdapter->getIdentifier('offset'); $this->_sortIdentifier = $this->_uriAdapter->getIdentifier('sort'); $this->_searchIdentifier = $this->_uriAdapter->getIdentifier('search'); // set data source for environment $this->_env = $this->_uriAdapter->getEnv(); $this->_uriAdapter->setEnvData($this->_uriAdapter->getIdentifier('offset'), 0); $this->_obj->query($this->_uriAdapter); // calculate columns & alignment for each column foreach ($this->_obj->getColumns() as $key => $column) { // minimum column width should be based on label width $this->_colsWidth[$key] = strlen($column->getTitle()); $this->_colsAlignment[$key] = $column->getParameter('align'); } /* add optional extra columns */ if ($this->getParameter('extra_cols') > 0) { for ($i = 0; $i < $this->getParameter('extra_cols'); $i++) { $this->_colsWidth[] = 10; } } $i = 0; $rows = $this->_obj->getCollection(); $sampleLength = $rows->getTotalMembers() > 30 ? 30 : $rows->getTotalMembers(); // now walk through a sample of all data rows to find longest value for each column while ($i < $sampleLength) { $rnd = rand(0, $rows->getTotalMembers() - 1); // get a random row if (($data = $rows->getMember($rnd, ObjectModel::MODEL)) === false) { continue; } foreach ($this->_obj->getColumns() as $key => $column) { $property = $data->getProperty($column->getParameter('property')); if ($column->getParameter('recursion')) { foreach ($column->getParameter('recursion') as $recursion) { if ($property instanceof AbstractProperty) { $property = $property->getValue(ObjectModel::DATA); } if ($property instanceof ObjectModel || $property instanceof DataObject) { $property = $property->getProperty($recursion); } } } $value = $property instanceof AbstractProperty ? $property->getDisplayValue() : null; $content = explode("\n", $value); $strlen = strlen($content[0]); if ($strlen > $this->_colsWidth[$key]) { $this->_colsWidth[$key] = $strlen; } } $i++; } $floor = array_sum($this->_colsWidth) * 0.05; // adds 50% to cols using less than 5% of total */ foreach ($this->_colsWidth as $key => $colWidth) { if ($colWidth > $floor) { continue; } $this->_colsWidth[$key] = $colWidth * 1.5; } // compute total length of columns $fullLine = array_sum($this->_colsWidth); // attribute width in percent of total width foreach ($this->_colsWidth as $key => $colWidth) { $this->_colsWidth[$key] = round($width * ($colWidth / $fullLine)); } /* number of columns, useful to know when to terminate a row */ $this->_cols = $cols = count($this->_colsWidth); /* draw header row */ $this->_drawHeaderRow($pdf); /* number of data columns, useful to retrieve extra ones */ $dcols = count($this->_obj->getColumns()); /* calculate the value of the necessary space to draw a new cell */ $increment = $this->_cellHeight + $this->_headerHeight; //if (! is_null($this->_groups)) $increment += $this->_headerHeight; /* print data */ foreach ($this->_obj->getCollection()->getMembers(ObjectModel::DATA) as $this->_do) { /* test if a new page is necessary */ if ($pdf->getY() + $increment > $pdf->getPageHeight() - 20) { $pdf->AddPage(); $this->_drawHeaderRow($pdf); } $index = 0; foreach ($this->_obj->getColumns() as $key => $column) { if ($index + 1 == $cols) { $index = 0; $nextPos = 1; } else { $nextPos = 0; $index++; } if ($column instanceof Element\IdentifierElement) { $value = $this->_do->getUri()->getIdentifier(); } else { if ($column instanceof Element\MetaElement) { $attrib = $column->getParameter('type') == 'currency' ? ' class="cellcurrency"' : null; $p .= "<td{$attrib}>" . $column->getDisplayValue($this->_do) . '</td>'; } else { $property = $this->_do->getProperty($column->getParameter('property')); if (!$property) { $pdf->Multicell($this->_colsWidth[$key], $this->_cellHeight, '??', 1, $this->_colsAlignment[$key], 0, $nextPos); continue; } $column->setValue($property->getValue()); if ($column->getParameter('recursion')) { foreach ($column->getParameter('recursion') as $recursion) { if ($property instanceof AbstractProperty) { $property = $property->getValue(ObjectModel::DATA); } if ($property instanceof ObjectModel || $property instanceof DataObject) { $property = $property->getProperty($recursion); } } } if ($property instanceof Property\MediaProperty) { $column->setValue($property->getDisplayValue()); $deco = Decorator::factory($column); $value = $deco->render(); } else { $value = $property instanceof Property\AbstractProperty ? $property->getDisplayValue() : null; } } } // put value in cell $pdf->Multicell($this->_colsWidth[$key], $this->_cellHeight, $value, 1, $this->_colsAlignment[$key], 0, $nextPos); } /* display optional extra cols */ if ($this->getParameter('extra_cols') > 0) { for ($i = 0; $i < $this->getParameter('extra_cols'); $i++) { $pdf->Cell($this->_colsWidth[$dcols + $i], $this->_cellHeight, null, 1, (int) ($i + $index + 1 == $cols)); } } } }
protected function _contentRendering() { $i = 0; $p = ''; $aliases = $this->_obj->getAliases(); // print out rows foreach ($this->_obj->getCollection()->getMembers(ObjectModel::DATA) as $this->_key => $this->_do) { $css = $i % 2 == 0 ? 'odd' : 'even'; // \Zend_Debug::dump($this->_do->getProperty('marche')->getValue(ObjectModel::MODEL)); die; // @todo handle objects coming from different backends $p .= sprintf('<tr data-member="%s" data-alias="%s" class="%s">', $this->_key, $this->_do->getUri() ? $aliases[$this->_do->getUri()->getIdentifier()] : null, $css); $i++; if ($this->_obj->getParameter('selectable') === true) { // make list items selectable $p .= sprintf('<td><input type="checkbox" name="t41_selection[]" value="%s"/></td>', $this->_do->getUri()->getIdentifier()); } $altDec = (array) $this->_obj->getParameter('decorators'); foreach ($this->_obj->getColumns() as $column) { if ($column instanceof Element\IdentifierElement) { $p .= sprintf('<td>%s</td>', $this->_do->getUri()->getIdentifier()); continue; } if ($column instanceof Element\MetaElement) { $attrib = $column->getParameter('type') == 'currency' ? ' class="cellcurrency"' : null; $p .= "<td{$attrib}>" . $column->getDisplayValue($this->_do) . '</td>'; continue; } $property = $this->_do->getProperty($column->getParameter('property')); if (!$property) { $p .= '<td>??</td>'; continue; } $column->setValue($property->getValue()); /* if a decorator has been declared for property/element, use it */ if (isset($altDec[$column->getId()])) { $column->setDecorator($altDec[$column->getId()]); $deco = Decorator::factory($column); $p .= sprintf('<td>%s</td>', $deco->render()); continue; } $attrib = sprintf(' class="tb-%s', $column->getId()); $attrib .= $property instanceof Property\CurrencyProperty ? ' cellcurrency"' : '"'; if ($column->getParameter('recursion')) { $parts = $column->getParameter('recursion'); foreach ($parts as $rkey => $recursion) { if ($property instanceof ArrayProperty) { // property won't be a property here ! $property = $property->getValue(); $property = $property[$recursion]; if ($property instanceof BaseObject && isset($parts[$rkey + 1])) { $property = $property->{$parts[$rkey + 1]}; } break; } // property is an object property if ($property instanceof AbstractProperty && $property->getValue()) { $property = $property->getValue(ObjectModel::DATA)->getProperty($recursion); } if ($property instanceof ObjectModel || $property instanceof DataObject) { $property = $property->getProperty($recursion); } else { if ($property instanceof ObjectUri) { $property = ObjectModel::factory($property)->getProperty($recursion); } } } } if ($property instanceof Property\MediaProperty) { $column->setValue($property->getDisplayValue()); $deco = Decorator::factory($column); $value = $deco->render(); } else { $value = $property instanceof Property\AbstractProperty ? $property->getDisplayValue() : $property; } //$p .= "<td$attrib>" . $this->_escape($value) . '</td>'; $p .= "<td{$attrib}>" . $value . '</td>'; } $p .= '<td class="tb-actions">'; foreach ($this->_obj->getEvents('row') as $button) { $button->setParameter('uri', $this->_do->getUri()); $p .= $this->_renderButton($button, $aliases[$this->_do->getUri()->getIdentifier()]); } $p .= '</td></tr>' . "\n"; } return $p; }