energine
[ class tree: energine ] [ index: energine ] [ all elements ]

Source for file ChildDivisions.class.php

Documentation is available at ChildDivisions.class.php

  1. <?php
  2. /**
  3.  * Содержит класс ChildDivisions
  4.  *
  5.  * @package energine
  6.  * @subpackage share
  7.  * @author dr.Pavka
  8.  * @copyright Energine 2006
  9.  * @version $Id$
  10.  */
  11.  
  12.  
  13.  
  14. /**
  15.  * Класс передназначен для вівода дочерних разделов текущего раздела
  16.  *
  17.  * @package energine
  18.  * @subpackage share
  19.  * @author dr.Pavka
  20.  * @todo класс необходимо переписать поскольку используется разный принцип получения данных для страниц и разделов
  21.  *
  22.  */
  23. class ChildDivisions extends DataSet  {
  24.     /**
  25.      * Переменная содержащая идентификатор раздела для которого нужно выводить потомков
  26.      *
  27.      * @var int 
  28.      * @access private
  29.      */
  30.     private $id;
  31.  
  32.     /**
  33.      * Идентификатор указывающий на то что нужно исепользовать в качестве идентфикатора id родительской страниц
  34.      *
  35.      */
  36.     const PARENT_ID = 'parent';
  37.  
  38.     /**
  39.      * Конструктор класса
  40.      *
  41.      * @return void 
  42.      */
  43.     public function __construct($name$moduleDocument $document,  array $params null{
  44.         parent::__construct($name$module$document,  $params);
  45.         $this->setType(self::COMPONENT_TYPE_LIST);
  46.         if ($this->getParam('id')) {
  47.             $this->setParam('active'false);
  48.             //$this->setParam('recordsPerPage', false);
  49.         }
  50.  
  51.         if($this->getParam('id'== self::PARENT_ID){
  52.             $this->id Sitemap::getInstance()->getParent($this->document->getID());
  53.         }
  54.         elseif (!$this->getParam('id')) {
  55.             $this->id $this->document->getID();
  56.         }
  57.         else {
  58.             $this->id $this->getParam('id');
  59.         }
  60.     }
  61.  
  62.     /**
  63.      * Возвращает значение id
  64.      *
  65.      * @return int 
  66.      * @access protected
  67.      * @final
  68.      */
  69.     final protected function getID({
  70.         return $this->id;
  71.     }
  72.  
  73.     /**
  74.      * Устанавливает id
  75.      *
  76.      * @return void 
  77.      * @access protected
  78.      * @final
  79.      */
  80.     final protected function setID($id{
  81.         $this->id $id;
  82.     }
  83.  
  84.     /**
  85.      * Добавлен параметр id - идентификатор страницы
  86.      *
  87.      * @return int 
  88.      * @access protected
  89.      */
  90.  
  91.     protected function defineParams({
  92.         $result array_merge(parent::defineParams(),
  93.         array(
  94.         'id'=>false,
  95.         'showFinal' => false,
  96.         'active' => true
  97.         ));
  98.         return $result;
  99.     }
  100.  
  101.     /**
  102.      * Устанавливаем перечень полей
  103.      *
  104.      * @return DataDescription 
  105.      * @access protected
  106.      */
  107.  
  108.     protected function createDataDescription({
  109.         $result new DataDescription();
  110.  
  111.         $field new FieldDescription('Id');
  112.         $field->setType(FieldDescription::FIELD_TYPE_INT);
  113.         $field->setProperty('key'true);
  114.         $result->addFieldDescription($field);
  115.  
  116.         $field new FieldDescription('Name');
  117.         $field->setType(FieldDescription::FIELD_TYPE_STRING);
  118.         $result->addFieldDescription($field);
  119.  
  120.         $field new FieldDescription('Segment');
  121.         $field->setType(FieldDescription::FIELD_TYPE_STRING);
  122.         $result->addFieldDescription($field);
  123.  
  124.         $field new FieldDescription('DescriptionRtf');
  125.         $field->setType(FieldDescription::FIELD_TYPE_TEXT);
  126.         $result->addFieldDescription($field);
  127.  
  128.         $field new FieldDescription('AttachedFiles');
  129.         $field->setType(FieldDescription::FIELD_TYPE_CUSTOM);
  130.         $result->addFieldDescription($field);
  131.  
  132.         return $result;
  133.     }
  134.  
  135.     protected function createData(){
  136.         $result parent::createData();
  137.         $field new Field('AttachedFiles');
  138.         $result->addField($field);
  139.         
  140.         //Делаем выборку из таблицы дополнительных файлов
  141.         if($result->getFieldByName('Id')){
  142.             $res $this->dbh->selectRequest('
  143.                     SELECT smap_id, upl.*
  144.                     FROM `share_uploads` upl
  145.                     LEFT JOIN share_sitemap_uploads ssu on ssu.upl_id = upl.upl_id
  146.                     WHERE smap_id IN ('.implode(','$result->getFieldByName('Id')->getData()).')
  147.                 ');
  148.             if(is_array($res)){
  149.                 //конвертируем результат запроса в удобный формат
  150.                 foreach($res as $row){
  151.                     $smapID $row['smap_id'];
  152.                     unset($row['smap_id']);
  153.                     if(!isset($uplData[$smapID])){
  154.                         $uplData[$smapIDarray();
  155.                     }
  156.                     array_push($uplData[$smapID]$row);
  157.                 }
  158.                 
  159.                 foreach ($result->getFieldByName('Id'as $index => $smapID{
  160.                     if(!empty($uplData[$smapID])){
  161.                         $result->getFieldByName('AttachedFiles')->setRowData($index$this->buildAttachedFilesField($uplData[$smapID]));
  162.                     }
  163.                 }
  164.             }
  165.         }
  166.  
  167.         return $result;
  168.     }
  169.  
  170.     private function buildAttachedFilesField($attachedFilesData){
  171.         $builder new SimpleBuilder();
  172.  
  173.         $data new Data();
  174.         $data->load($attachedFilesData);
  175.  
  176.         $dataDescription new DataDescription();
  177.         $dataDescription->load($this->dbh->getColumnsInfo('share_uploads'));
  178.  
  179.         $builder->setData($data);
  180.         foreach ($data->getFieldByName('upl_path'as $key => $row{
  181.             if(file_exists($row)){
  182.                 list($width$height@getimagesize($row);
  183.                 $data->getFieldByName('upl_path')->setRowProperty($key'width'$width);
  184.                 $data->getFieldByName('upl_path')->setRowProperty($key'height'$height);
  185.             }
  186.         }
  187.         $builder->setDataDescription($dataDescription);
  188.         $builder->build();
  189.  
  190.         return $builder->getResult();
  191.     }
  192.  
  193.     /**
  194.      * Переопределенный метод загрузки данных
  195.      *
  196.      * @return mixed 
  197.      * @access protected
  198.      */
  199.  
  200.     protected function loadData({
  201.         $data Sitemap::getInstance()->getChilds($this->getID());
  202.         if(!$this->getParam('showFinal')){
  203.             $data array_filter(
  204.                  $datacreate_function('$element''return !$element["isFinal"];')
  205.             );
  206.         }
  207.         else{
  208.             $data array_filter(
  209.                  $datacreate_function('$element''return $element["isFinal"];')
  210.             );
  211.         }
  212.         $data (empty($data))?false:$data;
  213.         if(is_array($data)) {
  214.             if ($this->getParam('recordsPerPage')) {
  215.                 if ($this->pager->getCurrentPage()>1{
  216.                     $this->document->componentManager->getComponentByName('breadCrumbs')->addCrumb();
  217.                 }
  218.                 $this->pager->setRecordsCount(sizeof($data));
  219.                 $limit $this->pager->getLimit();
  220.                 $data array_slice($data$limit[0]$limit[1]true);
  221.             }
  222.             foreach ($data as $id => $current{
  223.                 $data[$idarray(
  224.                 'Id' => (isset($current['Id']))?$current['Id']:$id,
  225.                 'Segment' => $current['Segment'],
  226.                 'Name' => $current['Name'],
  227.                 'DescriptionRtf' => $current['DescriptionRtf']
  228.                 );
  229.             }
  230.  
  231.         }
  232.  
  233.         return $data;
  234.     }
  235.  
  236.     /**
  237.      * Callback функция для фильтрации массива данных о дочерних страницах(не разделах) по правам
  238.      *
  239.      * @param $row 
  240.      * @return bool 
  241.      */
  242.     private function filterDataByRights($row){
  243.         return (Sitemap::getInstance()->getDocumentRights($row['Id']!= ACCESS_NONE);
  244.     }
  245.  
  246.     /**
  247.      * Callback функция для генерации полного URL дл страниц
  248.      *
  249.      * @param $row 
  250.      * @return array 
  251.      */
  252.     private function prepareSegment($row){
  253.         $row['Segment'Sitemap::getInstance()->getURLByID($row['Pid']).$row['Segment'].'/';
  254.  
  255.         return $row;
  256.     }
  257. }
В создании документации нам помог: phpDocumentor