[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/Smarty/libs/plugins/ -> function.counter.php (source)

   1  <?php
   2  /**
   3   * Smarty plugin
   4   * @package Smarty
   5   * @subpackage PluginsFunction
   6   */
   7  
   8  /**
   9   * Smarty {counter} function plugin
  10   *
  11   * Type:     function<br>
  12   * Name:     counter<br>
  13   * Purpose:  print out a counter value
  14   *
  15   * @author Monte Ohrt <monte at ohrt dot com>
  16   * @link http://www.smarty.net/manual/en/language.function.counter.php {counter}
  17   *       (Smarty online manual)
  18   * @param array                    $params   parameters
  19   * @param Smarty_Internal_Template $template template object
  20   * @return string|null
  21   */
  22  function smarty_function_counter($params, $template)
  23  {
  24      static $counters = array();
  25  
  26      $name = (isset($params['name'])) ? $params['name'] : 'default';
  27      if (!isset($counters[$name])) {
  28          $counters[$name] = array(
  29              'start'=>1,
  30              'skip'=>1,
  31              'direction'=>'up',
  32              'count'=>1
  33              );
  34      }
  35      $counter =& $counters[$name];
  36  
  37      if (isset($params['start'])) {
  38          $counter['start'] = $counter['count'] = (int)$params['start'];
  39      }
  40  
  41      if (!empty($params['assign'])) {
  42          $counter['assign'] = $params['assign'];
  43      }
  44  
  45      if (isset($counter['assign'])) {
  46          $template->assign($counter['assign'], $counter['count']);
  47      }
  48      
  49      if (isset($params['print'])) {
  50          $print = (bool)$params['print'];
  51      } else {
  52          $print = empty($counter['assign']);
  53      }
  54  
  55      if ($print) {
  56          $retval = $counter['count'];
  57      } else {
  58          $retval = null;
  59      }
  60  
  61      if (isset($params['skip'])) {
  62          $counter['skip'] = $params['skip'];
  63      }
  64      
  65      if (isset($params['direction'])) {
  66          $counter['direction'] = $params['direction'];
  67      }
  68  
  69      if ($counter['direction'] == "down")
  70          $counter['count'] -= $counter['skip'];
  71      else
  72          $counter['count'] += $counter['skip'];
  73      
  74      return $retval;
  75      
  76  }
  77  
  78  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1