Exemple #1
0
 /**
  * Returns an list with the parent hierarchy until root with:
  *   * id: key of the item
  *   * name: form name for the component (selected value will be overriden with $this->name)
  *   * value: item value
  * Example:
  * getHierarchy(100) => array(
  *   array(id=>0,   [name=n0,] value=ROOT),
  *   array(id=>1,   [name=n1,] value=Spain),
  *   array(id=>20,  [name=n2,] value=Galicia),
  *   array(id=>100, [name=n3,] value=A Coruña),
  * )
  */
 public static function getHierarchy($id = null)
 {
     $cat_hierarchy = CategoryUtils::getCategoryHierarchy($id);
     $h = array();
     foreach ($cat_hierarchy as $key => $value) {
         $category = self::getCategory($value);
         array_push($h, array('id' => $category->cid, 'name' => 'category[' . $category->level . ']', 'value' => $category->name));
     }
     // Add root
     array_unshift($h, array('id' => 0, 'name' => 'category[0]', 'value' => 'ROOT'));
     return $h;
 }
 public function run()
 {
     // Parameters
     $cid = $_REQUEST['q'];
     if (isset($cid)) {
         $categoryHierarchy = CategoryUtils::getCategoryHierarchy($cid);
         $result["result"] = 0;
         $result["categories"] = $categoryHierarchy;
     } else {
         $result["result"] = -1;
         $result["message"] = Yii::t('category', 'No cid set');
     }
     echo CJSON::encode($result);
     exit(0);
     // To avoid loggers append things to request
 }
Exemple #3
0
////foreach($category->useres as $v) {
////    print_r("<br/>".$v);
////}
//echo "</p>";
?>

<?php 
//$location = Location::model()->findByPk(1);
SampleHierarchyWidget::$view = 'application.components.widgets.hierarchy.views.nestedSelects';
$this->widget('SampleHierarchyWidget', array('name' => 'Juanito', 'selectedId' => 10));
$location = Location::model()->findByPk(1);
$this->widget('SampleHierarchyWidget', array('id' => 'juan', 'model' => $location, 'attribute' => 'zid'));
?>

<hr/>

<pre>
<?php 
print_r(CategoryUtils::getCategoryHierarchy(20));
?>
</pre>

asdfasdffsd
<?php 
$this->widget('application.components.widgets.popup.Popup', array());
?>
pepepasdfasdf
<?php 
$this->widget('application.components.widgets.popup.Popup', array('id' => 'Manolo'));
?>
asdfasdfasddfsfd