Example #1
0
 /**
  * @return void
  * @param array  $arr - hash^2 of values
  * @param string $block_name - block name
  * @param Template $tpl - link to TPL object ($app->tpl OR $parser->tpl) that will be used for parsing
  * @desc List handler
  */
 function __listHandler($arr, $block_name, &$tpl)
 {
     global $app;
     // setup template defenitions
     $list_name = $block_name;
     $row_name = $block_name . '_row';
     $empty_name = $block_name . '_empty';
     $separator_name = $block_name . '_separator';
     $add = $this->__getAddVariables();
     if (isset($arr) && is_array($arr) && sizeof($arr) > 0) {
         $list_size = sizeof($arr);
         $i = 1;
         foreach ($arr as $row) {
             // make separator
             if ($i < $list_size) {
                 $tpl->touchBlock($separator_name);
             }
             $tpl->setCurrentBlock($row_name);
             // add $this->add_variables
             $row = array_merge($row, $add);
             // add images fields if needs
             if (arrayIsOk($this->fields)) {
                 foreach ($this->fields as $name => $type) {
                     if (substr($type, 0, 5) == 'image' && $row['id'] != '') {
                         $row[$name] = $row['id'];
                     }
                     if (substr($type, 0, 4) == 'file' && $row['id'] != '') {
                         $row[$name] = $row['id'] . '_' . $row[$name];
                     }
                 }
             }
             foreach ($row as $key => $value) {
                 // make decoration
                 if ($this->list_decoration1 != '' && $this->list_decoration2 != '') {
                     if ($i % 2 == 1) {
                         $tpl->setVariable('decoration', $this->list_decoration1);
                     } else {
                         $tpl->setVariable('decoration', $this->list_decoration2);
                     }
                 }
                 // preobrazovanie
                 if (isset($this->fields[$key]) && $this->fields[$key] != '') {
                     $this->setElement($key, $this->fields[$key]);
                     $value = $this->makeElementView($value, $row['id']);
                 }
                 if (!arrayIsOk($value)) {
                     $tpl->setVariable(array(strtoupper($key) => $value));
                 } else {
                     $tpl->setVariable($value);
                 }
             }
             $tpl->parseCurrentBlock();
             $i++;
         }
     } else {
         $tpl->touchBlock($empty_name);
     }
     $tpl->setCurrentBlock($list_name);
     if (isset($this->caption_variables)) {
         $tpl->setVariable($this->caption_variables);
     }
     if ($app->paging && $app->paging['pages'] > 1) {
         $tpl->setVariable(array('PAGING' => $this->makePaging()));
     }
     $tpl->parseCurrentBlock();
     // remove caption & add variables
     $this->__clearAddVariables();
     $this->__clearListDecoration();
 }