Advertisement
manchumahara

Joomla Com_Zoo Category listing custom FormField/Parameter

May 6th, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.17 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @version Id: zoocat.php $
  4.  * @package Joomla
  5.  * @subpackage  Content
  6.  * @copyright   Copyright (C)2010-2013 codeboxr.com. All rights reserved.
  7.  * @license GNU/GPL, http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  8.  * @Support Forum  http://codeboxr.com/product/all-in-one-social-comment-embed-system-content-plugin-for-joomla
  9.  */
  10.  
  11. // no direct access
  12. defined('_JEXEC') or die('Restricted access');
  13.  
  14. if(version_compare(JVERSION,'3.0.0','ge')):
  15.     jimport('joomla.form.formfield');
  16.     class JFormFieldZoocat extends JFormField {
  17.  
  18.             var $type = 'k2cat';
  19.  
  20.             public function getInput(){
  21.                
  22.                 $db = JFactory::getDBO();
  23.                 if(JFile::exists(JPATH_ROOT.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_zoo'.DIRECTORY_SEPARATOR.'zoo.php')):
  24.                     $query = 'SELECT m.* FROM #__zoo_category m WHERE published=1  ORDER BY parent, ordering';
  25.                     $db->setQuery( $query );
  26.                     $mitems = $db->loadObjectList();
  27.                     //var_dump($mitems);
  28.                     $children = array();
  29.                     if ($mitems){
  30.                         foreach ( $mitems as $v ){
  31.                             if(K2_JVERSION != '16'){
  32.                                     $v->title = $v->name;
  33.                                     $v->parent_id = $v->parent;
  34.                             }
  35.                             $pt = $v->parent;
  36.                             $list = @$children[$pt] ? $children[$pt] : array();
  37.                             array_push( $list, $v );
  38.                             $children[$pt] = $list;
  39.                         }
  40.                     }
  41.                     $list = JHTML::_('menu.treerecurse', 0, '', array(), $children, 9999, 0, 0 );
  42.                     $mitems = array();
  43.  
  44.                     foreach ( $list as $item ) {
  45.                         $item->treename = JString::str_ireplace('&#160;', '- ', $item->treename);
  46.                         $mitems[] = JHTML::_('select.option',  $item->id, '   '.$item->treename );
  47.                     }                
  48.                
  49.                 endif;
  50.  
  51.                 $fieldName = $this->name.'[]';
  52.                
  53.                 $output = JHTML::_('select.genericlist',  $mitems, $fieldName, 'class="inputbox" style="width:90%;" multiple="multiple" size="10"', 'value', 'text', $this->value );
  54.                 return $output;
  55.             }
  56.     }
  57. else:    
  58.     if(version_compare(JVERSION,'1.6.0','ge')) {
  59.         jimport('joomla.form.formfield');
  60.         class JFormFieldZoocat extends JFormField {
  61.            
  62.             var $type = 'k2cat';
  63.            
  64.             public function getInput(){
  65.                     return JElementZoocat::fetchElement($this->name, $this->value, $this->element, $this->options['control']);
  66.             }
  67.         }
  68.     }
  69.  
  70.     jimport('joomla.html.parameter.element');
  71.  
  72.     class JElementZoocat extends JElement
  73.     {
  74.  
  75.             var $_name = 'zoocat';
  76.  
  77.             public function fetchElement($name, $value, &$node, $control_name){
  78.  
  79.                     $db = JFactory::getDBO();
  80.                     if(JFile::exists(JPATH_ROOT.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_zoo'.DIRECTORY_SEPARATOR.'zoo.php')):
  81.                         $query = 'SELECT m.* FROM #__zoo_category m WHERE published=1  ORDER BY parent, ordering';
  82.                         $db->setQuery( $query );
  83.                         $mitems = $db->loadObjectList();
  84.                         $children = array();
  85.                         if ($mitems){
  86.                             foreach ( $mitems as $v ){
  87.                                 if(K2_JVERSION != '16'){
  88.                                         $v->title = $v->name;
  89.                                         $v->parent_id = $v->parent;
  90.                                 }
  91.                                 $pt = $v->parent;
  92.                                 $list = @$children[$pt] ? $children[$pt] : array();
  93.                                 array_push( $list, $v );
  94.                                 $children[$pt] = $list;
  95.                             }
  96.                         }
  97.                         $list = JHTML::_('menu.treerecurse', 0, '', array(), $children, 9999, 0, 0 );
  98.                         $mitems = array();
  99.  
  100.                         foreach ( $list as $item ) {
  101.                             $item->treename = JString::str_ireplace('&#160;', '- ', $item->treename);
  102.                             $mitems[] = JHTML::_('select.option',  $item->id, '   '.$item->treename );
  103.                         }                
  104.                     endif;
  105.                    
  106.                     if(version_compare(JVERSION,'1.6.0','ge')) {
  107.                         $fieldName = $name.'[]';
  108.                     }
  109.                     else {
  110.                         $fieldName = $control_name.'['.$name.'][]';
  111.                     }
  112.  
  113.                     //$doc->addScriptDeclaration($js);
  114.                     $output= JHTML::_('select.genericlist',  $mitems, $fieldName, 'class="inputbox" style="width:90%;" multiple="multiple" size="10"', 'value', 'text', $value );
  115.                     return $output;
  116.             }
  117.     }
  118.  
  119. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement