/** * Ajax CTreeView backend for zones * @param $_GET['root'] * @param $_GET['selected'] */ public function actionTreeFill() { $rootZone = $this->getRootZone($_GET['root']); $tree_array = $this->getChildrenAsTreeArray($rootZone, $_GET['selected']); echo CTreeView::saveDataAsJson($tree_array); exit(0); }
/** * Fills treeview based on the current user input. */ public function run() { if (!isset($_GET['root']) || $_GET['root'] == 'source') { $rootId = $this->rootId; $showRoot = $this->showRoot; } else { $rootId = $_GET['root']; $showRoot = false; } $dataTree = $this->getModel()->{$this->methodName}($rootId, $showRoot); echo CTreeView::saveDataAsJson($dataTree); }
public function actionTreeFill() { $id = !isset($_GET['root']) ? 'source' : $_GET['root']; $dataTree = array(); if ($id == 'source') { $root = Zone::model()->findByPk(0); } else { $root = Zone::model()->findByPk($id); } foreach ($root->children as $child) { $dataTree[] = array('id' => $child->zid, 'text' => CHtml::link($child->name, array('/zone/view/id/' . $child->zid)), 'collapsed' => $child->zid != 0, 'hasChildren' => true); } echo CTreeView::saveDataAsJson($dataTree); }
public function init() { // Add ordering $criteria = new CDbCriteria(); $criteria->order = "SCHEMA_NAME ASC"; $schemata = Schema::model()->findAll($criteria); $dbSeperator = "_"; $items = $root = $children = $items = array(); foreach ($schemata as $schema) { // Find prefix in name if ($position = strpos($schema->SCHEMA_NAME, $dbSeperator)) { $prefix = substr($schema->SCHEMA_NAME, 0, $position); $root[$prefix] = $prefix; $children[$prefix][] = substr($schema->SCHEMA_NAME, $position + 1); } else { $root[] = $schema->SCHEMA_NAME; } } $i = 0; foreach ($root as $key => $item) { $childs = array(); $childrenCount = count($children[$item]); if ($childrenCount > 1) { foreach ($children[$item] as $child) { $childs[] = array('text' => CHtml::link($child, SchemaController::createUrl("/schema/" . $item . $dbSeperator . $child))); } } else { if ($childrenCount == 1) { $name = $item . $dbSeperator . $children[$item][0]; } else { $name = $item; } $items[] = array('text' => CHtml::link($name, SchemaController::createUrl("/schema/" . $name))); $i++; continue; } $items[] = array('text' => $childrenCount == 0 ? CHtml::link($item, SchemaController::createUrl("/schema/" . $item)) : $item, 'expanded' => $i == 0 ? true : false, 'children' => $childs); $i++; } $this->data = $items; parent::init(); }
public function actionAjaxFillTree() { if (!Yii::app()->request->isAjaxRequest) { exit; } $parentId = 0; if (isset($_GET['root']) && $_GET['root'] !== 'source') { $parentId = (int) $_GET['root']; } $req = Yii::app()->db->createCommand("SELECT m1.id, m1.name AS text, m2.id IS NOT NULL AS hasChildren " . "FROM a_organization AS m1 LEFT JOIN a_organization AS m2 ON m1.id=m2.parent_id " . "WHERE m1.parent_id <=> {$parentId} " . "GROUP BY m1.id ORDER BY m1.id ASC"); $children = $req->queryAll(); $treedata = array(); foreach ($children as $child) { $options = array('href' => Yii::app()->createUrl('aOrganization/view', array('id' => $child['id'])), 'id' => $child['id'], 'class' => 'treenode'); $nodeText = CHtml::openTag('a', $options); $nodeText .= $child['text']; $nodeText .= CHtml::closeTag('a') . "\n"; $child['text'] = $nodeText; $treedata[] = $child; } //$children = $this->createLinks($children); echo str_replace('"hasChildren":"0"', '"hasChildren":false', CTreeView::saveDataAsJson($treedata)); exit; }
/** * Fills the JS tree on an AJAX request. * Should receive parent node ID in $_GET['root'], * with 'source' when there is no parent. */ public function actionAjaxFillTree() { if (!Yii::app()->request->isAjaxRequest) { exit; } $parentId = "NULL"; if (isset($_GET['root']) && $_GET['root'] !== 'source') { $parentId = (int) $_GET['root']; } $req = Yii::app()->db->createCommand("SELECT m1.category_id, m1.name AS text, m2.category_id IS NOT NULL AS hasChildren " . "FROM cart_content_category AS m1 LEFT JOIN cart_content_category AS m2 ON m1.category_id=m2.parent_id " . "WHERE m1.parent_id <=> {$parentId} " . "GROUP BY m1.category_id ORDER BY m1.name ASC"); $children = $req->queryAll(); echo str_replace('"hasChildren":"0"', '"hasChildren":false', CTreeView::saveDataAsJson($children)); exit; }
<?php $this->endWidget(); ?> </div><!-- form --> <script> function updateTree(data) { jQuery.ajax({ 'type':'POST', 'url':'/scuko/index.php?r=company/getdepartments', 'cache':false, 'data':data, 'success':function(json){ $("#yw0").("<?php CTreeView::saveDataAsHtml($data); ?> "); var arr=JSON.parse(json); var i = 0; for(i=0;i<arr.length;i++) { $( "#"+arr[i] ).remove(); } } }); return false; } jQuery('body').on('change','#Department_company_id',function(){ var data = jQuery(this).parents("form").serialize(); jQuery.ajax({
public function actionAjaxFillTree() { if (!Yii::app()->request->isAjaxRequest) { exit; } $data = MemberService::Getmenu(); echo str_replace('"hasChildren":"0"', '"hasChildren":true', CTreeView::saveDataAsJson($data)); exit; }
public function actionAjaxFillTree() { $data = $this->actionGetmenu(); echo str_replace('"hasChildren":"0"', '"hasChildren":false', CTreeView::saveDataAsJson($data)); exit; }
public function actionGetDeviceTree() { if (isset($_POST)) { $person_id = $_POST['Device']['person_id']; $data = Device::createTreeByPersonID($person_id); $html = CTreeView::saveDataAsHtml($data); echo $html; } }