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 parse dynamic list data
  */
 function __dynamicListHandler($arr, $block_name, &$tpl)
 {
     global $app;
     $this->buffer = 'dynamic_view';
     $list_name = $block_name;
     $row_name = $block_name . '_row';
     $element_name = $block_name . '_element';
     $caption_row_name = $block_name . '_caption_row';
     $caption_element_name = $block_name . '_caption_element';
     $add = $this->__getAddVariables();
     // make captions line
     if (arrayIsOk($this->list_columns)) {
         foreach ($this->list_columns as $key => $value) {
             if (arrayIsOk($value)) {
                 foreach ($value as $key2 => $value2) {
                     $cap_arr[$key2] = $value2;
                 }
                 $cap_arr['ELEMENT_NAME'] = $key;
             } else {
                 $cap_arr = array('ELEMENT' => $value, 'ELEMENT_NAME' => $key);
             }
             $tpl->parseVariable($cap_arr, $caption_element_name);
         }
         $tpl->setCurrentBlock($caption_row_name);
         if (arrayIsOk($this->list_columns_add_variables)) {
             $tpl->setVariable($this->list_columns_add_variables);
             unset($this->list_columns_add_variables);
         }
         $tpl->parseCurrentBlock();
     }
     if (arrayIsOk($this->fields)) {
         $i = 1;
         foreach ($arr as $row) {
             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);
                     }
                 }
                 if ($this->fields[$key] != '') {
                     // DATA field
                     if ($this->fields[$key] != 'hidden' && $key != 'id') {
                         $this->setElement($key, $this->fields[$key]);
                         $value = $this->makeElementView($value, $row['id']);
                         $insert_array = array('ELEMENT' => $value, 'ID' => $row['id']);
                         $tpl->parseVariable($insert_array, $element_name);
                     }
                 } else {
                     // not DATA field
                     if ($key != 'id') {
                         $tpl->parseVariable(array('ELEMENT' => $value), $element_name);
                     }
                 }
             }
             $row = array_merge($row, $add);
             $tpl->parseVariable($row, $row_name);
             $i++;
         }
     } else {
         $i = 1;
         foreach ($arr as $row) {
             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);
                     }
                 }
                 $tpl->parseVariable(array('ELEMENT' => $value), $element_name);
             }
             $row = array_merge($row, $add);
             $tpl->parseVariable($row, $row_name);
             $i++;
         }
     }
     $tpl->setCurrentBlock($list_name);
     if (isset($this->caption_variables)) {
         $tpl->setVariable($this->caption_variables);
     }
     // Paging
     if ($app->paging) {
         $tpl->setVariable(array('PAGING' => $this->makePaging()));
     }
     $tpl->parseCurrentBlock();
     $this->__clearAddVariables();
     $this->__clearListDecoration();
     $this->buffer = '';
 }