Source for file class.acBlockType_select_multiple.php

Documentation is available at class.acBlockType_select_multiple.php

  1. <?php
  2. {
  3.     function __construct(&$content_obj$params array())
  4.     {
  5.         $params['block_type''select_multiple';
  6.         parent::__construct($content_obj$params);
  7.         $AC &ac_utils::get_module('AdvancedContent');
  8.         #$AC->SetAllowedParam(CLEAN_REGEXP.'/.*_AdvancedContentSortableItem_.*/',CLEAN_STRING);
  9.         
  10.         $this->SetProperty('sortable'isset($params['sortable_items']&& ac_utils::IsTrue($params['sortable_items']))# deprecated
  11.         $this->SetProperty('sortable'isset($params['sortable']&& ac_utils::IsTrue($params['sortable']));
  12.         $this->SetProperty('delimiter'isset($params['delimiter']$params['delimiter''|');
  13.         $this->SetProperty('items'isset($params['items']$params['items''');
  14.         $this->SetProperty('values'isset($params['values']$params['values''');
  15.     }
  16.     
  17.     public function GetInput()
  18.     {
  19.         $selItems explode($this->GetProperty('delimiter')$this->GetContent());
  20.         $items    $this->_get_items_array($selItems);
  21.         
  22.         if(!$this->GetProperty('sortable'))
  23.         {
  24.             $input '<select name="' $this->GetProperty('id''[]" ' 
  25.                 ($this->GetProperty('style'!= '' 'style="' $this->GetProperty('style'' "' ''
  26.                 'multiple="multiple" size="' ($this->GetProperty('size'$this->GetProperty('size'count($items)) '">';
  27.                 
  28.             foreach($items as $oneItem)
  29.             {
  30.                 $input .= '<option value="' $oneItem['value''"';
  31.                 if($oneItem['selected'])
  32.                     $input .= ' selected="selected"';
  33.                 
  34.                 $input .= '>' $oneItem['label''</option>';
  35.             }
  36.             $input .= '</select>';
  37.         }
  38.         else
  39.         {
  40.             $items $this->_sort_items($items$selItems);
  41.             $input '<div class="sortable_wrapper">';
  42.             foreach($items as $item)
  43.             {
  44.                 $input .=
  45.                 '<div class="sortable">
  46.                     <img class="sortable_handler" src="../modules/AdvancedContent/images/sort.png" />
  47.                     <input class="pagecheckbox"' ($this->GetProperty('style'!= ''?' style="' $this->GetProperty('style'' "':''' type="checkbox" value="'.$item['value'].'" name="' $this->GetProperty('id''[]"' ($item['selected']' checked="checked"':''' />
  48.                     '.$item['label'].'
  49.                 </div>';
  50.             }
  51.             $input .= '</div>';
  52.         }
  53.         return $input;
  54.     }
  55.     
  56.     public function GetHeaderHTML()
  57.     {
  58.         if($this->_header_html_called)
  59.             return;
  60.         
  61.         $this->_header_html_called true;
  62.         
  63.         return '
  64. <script language="javascript" type="text/javascript">
  65. /* <![CDATA[ */
  66. ac_onload.push(function(){
  67.     (function($){
  68.         $(".sortable_wrapper").sortable({
  69.             items: ".sortable",
  70.             handle: ".sortable_handler",
  71.             axis: "y"
  72.         });
  73.         $(".sortable_handler").disableSelection();
  74.     })(jQuery);
  75. });
  76. /* ]]> */
  77. </script>';
  78.     }
  79.     
  80.     public function FillParams(&$params$editing false)
  81.     {
  82.         $blockId $this->GetProperty('id');
  83.         if(!isset($params[$blockId]|| !is_array($params[$blockId]))
  84.             return;
  85.         
  86.         return implode($this->GetProperty('delimiter')$params[$blockId]);
  87.     }
  88.     
  89.     /**
  90.      * Not part of the api
  91.      */
  92.     private function _get_items_array($selItems array())
  93.     {
  94.         $AC &ac_utils::get_module('AdvancedContent');
  95.         $items array();
  96.         if($this->GetProperty('items'!= '')
  97.         {
  98.             foreach(explode($this->GetProperty('delimiter')$this->GetProperty('items')) as $key => $val)
  99.             {
  100.                 $items[$key]['id']    munge_string_to_url(trim($val));
  101.                 $items[$key]['label'trim($val);
  102.                 if($this->GetProperty('translate_labels'))
  103.                     $items[$key]['label'$AC->lang($items[$key]['label']);
  104.                 
  105.                 $items[$key]['value']    $items[$key]['label'];
  106.                 $items[$key]['selected'in_array($items[$key]['label'],$selItems);
  107.             }
  108.         }
  109.         if($this->GetProperty('values'!= '')
  110.         {
  111.             foreach(explode($this->GetProperty('delimiter')$this->GetProperty('values')) as $key => $val)
  112.             {
  113.                 $items[$key]['value'trim($val);
  114.                 if($this->GetProperty('translate_values'))
  115.                     $items[$key]['value'$AC->lang($items[$key]['value']);
  116.                 
  117.                 $items[$key]['selected'in_array($items[$key]['value'],$selItems);
  118.                 if(!isset($items[$key]['label']))
  119.                     $items[$key]['label'$items[$key]['value'];
  120.             }
  121.         }
  122.         return $items;
  123.     }
  124.     
  125.     /**
  126.      * Not part of the api
  127.      */
  128.     private function _sort_items($items array()$selItems array())
  129.     {
  130.         $_items array();
  131.         foreach($selItems as $selKey => $selItem)
  132.         {
  133.             reset($items);
  134.             foreach($items as $itemKey => $item)
  135.             {
  136.                 if($item['value'=== $selItem)
  137.                 {
  138.                     $_items[$item;
  139.                     unset($items[$itemKey]);
  140.                     unset($selItems[$selKey]);
  141.                     break;
  142.                 }
  143.             }
  144.         }
  145.         $items array_merge($_items,$items);
  146.         return $items;
  147.     }
  148. }
  149. ?>

Documentation generated on Tue, 09 Oct 2012 16:57:04 +0200 by phpDocumentor 1.4.1