/**
  * Renders data grid body.
  * @return string
  */
 public function renderBody()
 {
     $container = $this->getWrapper('datagrid container');
     // headers
     $header = Html::el($container->getName() == 'table' ? 'thead' : NULL);
     $header->add($this->generateHeaderRow());
     if ($this->dataGrid->hasFilters()) {
         $header->add($this->generateFilterRow());
     }
     // footer
     $footer = Html::el($container->getName() == 'table' ? 'tfoot' : NULL);
     $footer->add($this->generateFooterRow());
     // body
     $body = Html::el($container->getName() == 'table' ? 'tbody' : NULL);
     $iterator = new SmartCachingIterator($this->dataGrid->getRows());
     foreach ($iterator as $data) {
         $row = $this->generateContentRow($data);
         $row->addClass($iterator->isEven() ? $this->getValue('row.content .even') : NULL);
         $body->add($row);
     }
     if ($container->getName() == 'table') {
         $container->add($header);
         $container->add($footer);
         $container->add($body);
     } else {
         $container->add($header);
         $container->add($body);
         $container->add($footer);
     }
     return $container->render(0);
 }
示例#2
0
 /**
  * Removes unnecessary blocks of PHP code.
  * @param  string
  * @return string
  */
 private static function optimizePhp($source)
 {
     $res = $php = '';
     $tokens = token_get_all($source);
     $iterator = new SmartCachingIterator(token_get_all($source));
     foreach ($iterator as $token) {
         if (is_array($token)) {
             if ($token[0] === T_INLINE_HTML) {
                 $res .= $token[1];
             } elseif ($token[0] === T_CLOSE_TAG) {
                 $next = $iterator->getNextValue();
                 if (substr($res, -1) !== '<' && preg_match('#^<\\?php\\s*$#', $php)) {
                     $php = '';
                     // removes empty (?php ?), but retains ((?php ?)?php
                 } elseif (is_array($next) && $next[0] === T_OPEN_TAG) {
                     // remove ?)(?php
                     $ch = substr(rtrim($php), -1);
                     if ($ch !== ';' && $ch !== '{' && $ch !== '}' && $ch !== ':' && $ch !== '/') {
                         $php .= ';';
                     }
                     if (substr($next[1], -1) === "\n") {
                         $php .= "\n";
                     }
                     $iterator->next();
                 } else {
                     $res .= preg_replace('#;?(\\s)*$#', '$1', $php) . $token[1];
                     // remove last semicolon before ?)
                     $php = '';
                 }
             } else {
                 $php .= $token[1];
             }
         } else {
             $php .= $token;
         }
     }
     return $res . $php;
 }
示例#3
0
    echo "\n";
    echo "first: ";
    Debug::dump($iterator->isFirst());
    echo "last: ";
    Debug::dump($iterator->isLast());
    echo "counter: ";
    Debug::dump($iterator->getCounter());
}
$iterator->rewind();
echo "rewinding...\n";
echo "first: ";
Debug::dump($iterator->isFirst());
echo "last: ";
Debug::dump($iterator->isLast());
echo "counter: ";
Debug::dump($iterator->getCounter());
echo "empty: ";
Debug::dump($iterator->isEmpty());
echo "\n<h2>Zero item in array</h2>\n";
$arr = array();
$iterator = new SmartCachingIterator($arr);
$iterator->next();
$iterator->next();
echo "first: ";
Debug::dump($iterator->isFirst());
echo "last: ";
Debug::dump($iterator->isLast());
echo "counter: ";
Debug::dump($iterator->getCounter());
echo "empty: ";
Debug::dump($iterator->isEmpty());