[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/src/tags/list/ -> list_fill.tag.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  /**

  11   * Compile time component for output finalizers in a list

  12   * Allows to generate valid layout while output multicolumb lists

  13   * Default ratio attribute is 1

  14   *

  15   * @tag list:FILL

  16   * @restrict_self_nesting

  17   * @req_const_attributes upto

  18   * @parent_tag_class WactListListTag

  19   * @package wact
  20   * @version $Id$
  21   */
  22  class WactListFillTag extends WactCompilerTag
  23  {
  24    protected $ratio;
  25    protected $var_name;
  26  
  27    function preParse($compiler)
  28    {
  29      if (!$ratio = $this->getAttribute('upto'))
  30        $this->ratio = 1;
  31      else
  32        $this->ratio = $ratio;
  33  
  34      if($var_name = $this->getAttribute('var'))
  35        $this->var_name = $var_name;
  36      else
  37        $this->var_name = 'items_left';
  38  
  39      if ($this->getBoolAttribute('literal'))
  40        return WACT_PARSER_FORBID_PARSING;
  41    }
  42  
  43    function generateTagContent($code)
  44    {
  45      $ListList = $this->findParentByClass('WactListListTag');
  46  
  47      $code->writePhp('if (!' . $ListList->getComponentRefCode($code) . '->valid()){' . "\n");
  48  
  49      $count_var = $code->getTempVarRef();
  50      $items_left_var = $code->getTempVarRef();
  51      $code->writePhp($count_var .' = '. $ListList->getComponentRefCode($code) . '->countPaginated();');
  52  
  53      $code->writePhp("if ({$count_var}/{$this->ratio} > 1) \n");
  54      $code->writePhp($items_left_var . " = ceil({$count_var}/{$this->ratio})*{$this->ratio} - {$count_var}; \n");
  55      $code->writePhp("else \n");
  56      $code->writePhp($items_left_var . " = 0;\n");
  57  
  58      $code->writePhp("if ({$items_left_var}){\n");
  59  
  60      $code->writePhp($this->getDataSource()->getComponentRefCode() . "['" . $this->var_name . "'] = {$items_left_var};");
  61  
  62      parent :: generateTagContent($code);
  63  
  64      $code->writePhp('}'. "\n");
  65      $code->writePhp('}'. "\n");
  66    }
  67  }
  68  ?>


Generated: Mon Dec 1 03:56:46 2008 Cross-referenced by PHPXref 0.7