function buildTree($graph, $nodeId, $array, $namespace) { if (!isset($nodeId)) { $nodeId = $graph->newBNode(); } $me = $graph->resource($nodeId); foreach ($array as $key => $value) { $type = gettype($value); if ($type != "array") { if (substr($value, 0, 7) === "http://") { $me->addResource($namespace . ":" . $key, $value); } elseif (substr($value, 0, 8) === "https://") { $me->addResource($namespace . ":" . $key, $value); } elseif (is_numeric($value)) { $me->add($namespace . ":" . $key, intval($value)); } elseif ($value != "") { $me->add($namespace . ":" . $key, $value); } } else { $bn = $graph->newBNode(); $me->add($namespace . ":" . $key, $bn); buildTree($graph, $bn, $value, $namespace); } } }
function buildTree($dir) { $list = ''; foreach (new RecursiveDirectoryIterator($dir) as $filename => $file) { $list .= '<li>' . (!$file->isDir() ? '<a href="javascript:loadFile(\'' . $filename . '\');">' : '') . str_replace('.let', '', $file->getFilename()) . ($file->isDir() ? buildTree($file) : '</a>') . '</li>'; } return "<ul>{$list}</ul>"; }
function buildTree($tree, $q) { $test = snag_sql_query($tree, $q); if (!empty($test)) { foreach ($test as $nid => $testy) { $test[$nid]["children"] = buildTree($tree, $testy["id"]); } } return $test; }
function smGetCat() { global $cats; if (!empty($cats)) { $tree = buildTree($cats); $result = smGetCatItm($tree); } // debug($result); return $result; }
function buildTree(array $source, $search) { $out = array(); foreach ($source[$search] as $key => $node) { if (isset($source[$node])) { $out[$key] = buildTree($source, $node); unset($source[$node]); } else { $out[$key] = $node; } } return $out; }
protected function preparedMenuLinks($menus) { if (!empty($menus)) { $menuItems = array(); //fetch all parents & childrens foreach ($menus as $menu) { $menuData = array('label' => $menu->label, 'link' => $this->makeContentLink($menu), 'parent_id' => $menu->parent_id); $id = $menu->id; $menuItems[$id] = $menuData; } return buildTree($menuItems); } return array(); }
function buildTree(array $data, $parent = 0) { $tree = array(); foreach ($data as $d) { if ($d->parent_id == $parent) { $children = buildTree($data, $d->id); if (!empty($children)) { $d->_children = $children; } $tree[] = $d; } } return $tree; }
function buildTree(array $data, $parent = 6) { $tree = array(); foreach ($data as $d) { if ($d['id'] == $parent) { $children = buildTree($data, $d['parent']); // set a trivial key if (!empty($children)) { $d['_children'] = $children; } $tree[] = $d; } } return $tree; }
function buildTree(array &$elements, $parentId = 0, $shift = 0) { $branch = array(); foreach ($elements as &$element) { if ($element['parent_id'] == $parentId) { $children = buildTree($elements, $element['id'], $shift + 3); if ($children) { $element['children'] = $children; } $element['shift'] = $shift; $branch[$element['id']] = $element; unset($element); } } return $branch; }
function buildTree(array $elements, $parentId = 0) { $branch = array(); foreach ($elements as $element) { if ($element['mdl_parent'] == $parentId) { $children = buildTree($elements, $element['id']); if ($children) { $element['children'] = $children; } else { $element['children'] = 0; } $branch[] = $element; } } return $branch; }
function buildTree(array &$elements, $parentId = 0) { $branch = array(); foreach ($elements as $element) { if ($element['parent_id'] == $parentId) { $children = buildTree($elements, $element['id']); if ($children) { $element['children'] = $children; } $branch[] = $element; // $branch[$element['id']] = $element; unset($elements[$element['id']]); } } return $branch; }
function getBranch($tree, $parentId = 1) { $branch = array(); foreach ($tree as $element) { if ($element['parent'] == $parentId) { $children = buildTree($tree, $element['categoryID']); if (!empty($children)) { foreach ($children as $k => $v) { $branch[] = $v['categoryID']; } } $branch[] = $element['categoryID']; } } return $branch; }
private function load() { $last = array(-1 => -1); $beforeType = 0; $data = array(); $keys = array(); $file = fopen($this->fileName, 'r'); $key = 0; while (!feof($file)) { $value = fgets($file); $type = substr($value, 0, 1) * 1; $data = substr($value, 1, strlen($value) - 2); $this->types[] = $type; $this->data[] = $data; $this->parents[$key] = $last[$type - 1]; $this->linesBytes[] = fTell($file); if ($type - 1 > $beforeType) { $line = $key + 1; $excMsg = "Incorrect declaration of type in '" . $this->database . "' line " . $line; throw new StormDBException($excMsg, 0); } if ($type == 0) { $this->collections[] = $data; } $last[$type] = $key; $beforeType = $type; $key++; } $parentsBuild = array('BASE' => array()); for ($depth = 0; $depth < 10; $depth++) { foreach ($this->types as $key => $type) { if ($type == $depth) { if ($this->parents[$key] >= 0) { if (!isset($parentsBuild[$this->parents[$key]])) { $parentsBuild[$this->parents[$key]] = array(); } $parentsBuild[$this->parents[$key]][$key] = $key; } else { $parentsBuild['BASE'][$key] = $key; } } } } $this->build = assignNames(buildTree($parentsBuild, 'BASE'), $this->data); }
/** * Construct a tree based on table entries * @param array current node, (current parent) * @param mixed a set of parents, where each parents is in the format of [parent]=>children * should remain the same throughout the recursion. * @return A tree structure representation of the content entries. * @author Harris Wong */ function buildTree($current, $content_array) { $folder = array(); foreach ($current as $order => $content_id) { //if has children if (isset($content_array[$content_id])) { $wrapper[$content_id] = buildTree($content_array[$content_id], $content_array); } //no children. if ($wrapper) { $folder['order_' . $order] = $wrapper; unset($wrapper); } else { $folder['order_' . $order] = $content_id; } } return $folder; }
function buildTree($data, $parent = 0) { $tree = array(); foreach ($data as $d) { if ($d['parent'] == $parent) { $children = buildTree($data, $d['id']); // set a trivial key if (!empty($children)) { $d['categories'] = $children; $d = push_posts($d); } else { $d = push_posts($d); } $tree[] = $d; } } return $tree; }
function buildTree($elements, $parentId = 0) { $branch = array(); foreach ($elements as $element) { if ($element['parent_id'] == $parentId) { $children = buildTree($elements, $element['id']); if ($children) { $element['sub'] = $children; } $branch[] = $element; } } return $branch; }
function fddbSuche($gtin) { //$gtin = "4388844009943"; $gtin = preg_replace('/[^0-9]+/', '', $gtin); $data = curlData("http://fddb.mobi/search/?lang=de&cat=mobile-de&search=" . $gtin); $resultblock = between("<!-- %sresultblock% //-->", "<!-- %eresultblock% //-->", $data); $link = between("window.location.href = '", "';", $data); $area = between("<b>100 g:</b>", "<b>1 Packung:</b>", $data); if ($link != false && strlen($gtin) >= 13) { $werte = array("energy" => preg_replace('/[^0-9,.]+/', '', before("(", $area)), "calories" => preg_replace('/[^0-9,.]+/', '', between("(", ")", $area)), "fat" => preg_replace('/[^0-9,.]+/', '', between("Fett: ", "KH:", $area)), "carbonhydrate" => preg_replace('/[^0-9,.]+/', '', between("KH: ", "<br>", $area))); //$werte = array("Energie", "Energie1", "Fett", "Kohlenhydrate"); $naerhwerte = ""; foreach ($werte as $key => $value) { $naerhwerte[$key]["value"] = preg_replace('/[^0-9]+/', '', $werte[$key]); $naerhwerte[$key]["currencie"] = preg_replace('/[^a-zA-Z]+/', '', $werte[$key]); } $result = array("sourecName" => "fddb", "link" => $link, "gtin" => $gtin, "nutriTable" => $werte, "titel" => between("<a href='" . $link . "'><b>", '</b></a>', $resultblock)); $graph = new EasyRdf_Graph(); $namespace = new EasyRdf_Namespace(); $namespace->set('rezept', "http://manke-hosting.de/ns-syntax#"); buildTree($graph, $result["link"], $result, 'rezept'); echo $graph->serialise("turtle"); } }
function buildTree($ar, $pid = null) { $op = array(); foreach ($ar as $item) { if ($item['parentId'] == $pid) { $op[$item['id']] = array('id' => $item['id'], 'catName' => $item['catName'], 'parentId' => $item['parentId'], 'anzahl' => $item['anzahl']); // using recursion $children = buildTree($ar, $item['id']); if ($children) { $op[$item['id']]['children'] = $children; } } } return $op; }
function buildTree($word, &$words, $lastWord, $parent = null) { $tree = new Tree($word); if ($parent) { $tree->parent = $parent; } $children = getNeighbors($tree, $words); if (count($children)) { if (array_search($lastWord, $children) !== false) { echo $tree->getPath() . ' -> ' . $lastWord . PHP_EOL; } $tree->setChildren($children); foreach ($children as $child) { buildTree($child, $words, $lastWord, $tree); } } }
$s->createMenu('2', $s->textLink('Excel', 'bidang.l.u', 'Daftar-File-Terupload'), [$s->subMenu('1', $s->textLink('Excel', 'bidang.f.u', 'File-1'))]); $s->createMenu('3', $s->textLink('ResultDB ', 'bidang.f.u', 'Daftar DB'), [$s->subMenu('1', $s->textLink('Import 1', 'bidang.f.u')), $s->subMenu('1', $s->textLink('Import2', 'bidang.f.u'))]); echo $s->render(); }]); Route::get('json', ['as' => 'json', function () { // $s=new MenuManager(); // $s->createMenu('1',$s->textLink('Upload','bidang.f.u','Form-Upload-Excel')); // $s->createMenu('2',$s->textLink('Excel','bidang.f.u', 'Daftar-File-Terupload'),[$s->subMenu('1',$s->textLink('Excel','bidang.f.u', 'File-1'))]); // $s->createMenu('3',$s->textLink('ResultDB ','bidang.f.u','Daftar DB'),[$s->subMenu('1',$s->textLink('Import 1','bidang.f.u')),$s->subMenu('1',$s->textLink('Import2','bidang.f.u'))]); // // $s->createMenu('1','Excel',[$s->createMenu('1','excel1'),$s->createMenu('3','excel2')]); // // $s->createMenu('1','DB',[$s->createMenu('1','DB1 '),$s->createMenu('3','DB2')]); // echo $s->render(); // exit(); // dd( json_decode($s->render())); $arr = Treemenu::all(); $tree = buildTree($arr, 'parentid', 'id'); // print_r($tree); echo json_encode(json_decode(json_encode($tree))); exit; $h = '<a href="#" data-url="{{ route("bidang.f.u")}}">Upload</a>'; $j = '[{ "id":1, "text":"Upload", "attributes":{ "url":"/demo/book/abc", "price":100 }, "children":[] },{ "id":2, "text":"Excel ",
{ foreach ($tree['tree'] as $name => $node) { $name = explode("#", $name)[0]; $newNode = $xml->createElement($name, $node['data']); if (!empty($node['atributes'])) { foreach ($node['atributes'] as $attribute => $value) { $newAttribute = $xml->createAttribute($attribute); $newAttribute->value = $value; $newNode->appendChild($newAttribute); } } $newXmlNode = $xmlNode->appendChild($newNode); if (!empty($node['tree'])) { buildXmlFromTree($xml, $newXmlNode, $node); } } } function buildXml(&$tree) { $domtree = new DOMDocument('1.0', 'UTF-8'); $domtree->preserveWhiteSpace = false; $domtree->formatOutput = true; if (!empty($tree)) { buildXmlFromTree($domtree, $domtree, $tree); } return $domtree->saveXML(); } $tree = buildTree($schema); //echo json_encode($tree, JSON_PRETTY_PRINT); //echo buildXml($tree); file_put_contents("out.diagram", buildXml($tree));
function dimension_tree_for_permissions() { $dimension_id = array_var($_REQUEST, 'dimension_id'); $checkedField = array_var($_REQUEST, 'checkboxes') ? "checked" : "_checked"; $objectTypeId = array_var($_REQUEST, 'object_type_id', null); $allowedMemberTypes = json_decode(array_var($_REQUEST, 'allowedMemberTypes', null)); if (!is_array($allowedMemberTypes)) { $allowedMemberTypes = null; } $only_names = array_var($_REQUEST, 'onlyname', false); $name = trim(array_var($_REQUEST, 'query', '')); $extra_cond = $name == "" ? "" : " AND name LIKE '%" . $name . "%'"; if (array_var($_REQUEST, 'new_user')) { if (isset($_REQUEST['forced_members'])) { $forced_members = json_decode(array_var($_REQUEST, 'forced_members', '')); $fms = array(0); if (is_array($forced_members) && count($forced_members) > 0) { foreach ($forced_members as $fm) { if (is_numeric($fm)) { $fms[] = $fm; } } } if (count($fms) > 0) { $extra_cond .= " AND id IN (" . implode(',', $fms) . ")"; } } if (isset($_REQUEST['excluded_members'])) { $excluded_members = json_decode(array_var($_REQUEST, 'excluded_members', '')); $ems = array(0); if (is_array($excluded_members) && count($excluded_members) > 0) { foreach ($excluded_members as $em) { if (is_numeric($em)) { $ems[] = $em; } } } if (count($ems) > 0) { $extra_cond .= " AND id NOT IN (" . implode(',', $ems) . ")"; } } } else { // only use available object types $ots = ObjectTypes::getAvailableObjectTypes(); $available_ots_csv = ""; foreach ($ots as $ot) { $available_ots_csv .= ($available_ots_csv == "" ? "" : ",") . $ot->getId(); } if (trim($available_ots_csv) != "") { $ot_cond = " AND cmp.object_type_id IN ({$available_ots_csv})"; } else { $ot_cond = ""; } if (array_var($_REQUEST, 'only_with_perm')) { $extra_cond .= " AND EXISTS (SELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp WHERE cmp.member_id=id AND cmp.permission_group_id=" . array_var($_REQUEST, 'pg', '-1') . " {$ot_cond})"; } else { if (array_var($_REQUEST, 'only_without_perm')) { $extra_cond .= " AND NOT EXISTS (SELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp WHERE cmp.member_id=id AND cmp.permission_group_id=" . array_var($_REQUEST, 'pg', '-1') . " {$ot_cond})"; } } } $return_all_members = false; $selected_member_ids = json_decode(array_var($_REQUEST, 'selected_ids', "[0]")); $selected_members = Members::findAll(array('conditions' => 'id IN (' . implode(',', $selected_member_ids) . ')')); $memberList = $this->initial_list_dimension_members($dimension_id, $objectTypeId, $allowedMemberTypes, $return_all_members, $extra_cond, null, false, null, $only_names, $selected_members); // add missing parents $missing_parent_ids = array(); $all_members = array(); foreach ($memberList as $m) { $all_members[$m['id']] = $m['id']; } foreach ($memberList as $m) { if ($m['parent'] > 0 && !isset($all_members[$m['parent']])) { $missing_parent_ids[$m['parent']] = $m['parent']; } } while (count($missing_parent_ids) > 0) { $missing_members = DB::executeAll("SELECT m.*, ot.icon FROM " . TABLE_PREFIX . "members m INNER JOIN " . TABLE_PREFIX . "object_types ot ON ot.id=m.object_type_id WHERE m.id IN (" . implode(',', $missing_parent_ids) . ")"); $missing_parent_ids = array(); $new_missing = array(); foreach ($missing_members as $mem) { $m = array("id" => $mem['id'], "name" => clean($mem['name']), "parent" => $mem['parent_member_id'], "realParent" => $mem['parent_member_id'], "object_id" => $mem['object_id'], "depth" => $mem['depth'], "iconCls" => 'ico-' . $mem['icon'], "dimension_id" => $mem['dimension_id'], "object_type_id" => $mem['object_type_id'], "expandable" => true); $memberList[str_pad(array_var($m, 'parent'), 20, "0", STR_PAD_LEFT) . strtolower(array_var($m, 'name')) . array_var($m, 'id')] = $m; $new_missing[] = $m; $all_members[$m['id']] = $m; } foreach ($new_missing as $m) { if ($m['parent'] > 0 && !isset($all_members[$m['parent']])) { $missing_parent_ids[$m['parent']] = $m['parent']; } } } // -- $tree = buildTree($memberList, "parent", "children", "id", "name", $checkedField); ajx_current("empty"); ajx_extra_data(array('dimension_members' => $tree, 'dimension_id' => $dimension_id)); }
public function getTreeMenu() { $cats = Category::where('status', '=', '1')->get()->toArray(); $tree = buildTree($cats); return $tree; }
function buildTree(array $elements, $parentId = 0, $parentKey = 'parent_id', $childKey = 'children') { $branch = array(); foreach ($elements as $menu_id => $element) { if ($element[$parentKey] == $parentId) { $children = buildTree($elements, $menu_id, $parentKey, $childKey); if ($children) { $element[$childKey] = $children; } $branch[] = $element; } } return $branch; }
function buildTree(array $elements, $parentId = 0) { $branch = array(); foreach ($elements as $element) { if ($element["parent_id"] == $parentId) { $children = buildTree($elements, $element["Account_id"]); if ($children) { $element['children'] = $children; } unset($element["Account_id"]); unset($element["parent_id"]); $branch[] = $element; } } return $branch; }
function outputRecords($result) { global $OUTPUT_STUBS; $reverse_pointers = array(); $relationships = array(); $rec_ids = array(); foreach ($result['records'] as $record) { // get all the result recIDs array_push($rec_ids, $record['rec_ID']); } buildTree($rec_ids, $reverse_pointers, $relationships); foreach ($result['records'] as $record) { outputRecord($record, $reverse_pointers, $relationships, 0, $OUTPUT_STUBS); } }
/** * Erzeugt einen Graph aus dem JSON Dokument der spezifischen Rezeptsuche. * * @param Array $jsonObject * @return EasyRdf_Graph */ function buildGraphFromJsonRecipeResult($jsonObject) { $baseURL = 'http://chefkoch.de/rezept/'; //$wrapperURL = "http://chefkoch:8888/index.php/lookup/"; $graph = new EasyRdf_Graph(); $rezeptNamespace = new EasyRdf_Namespace(); $rezeptNamespace->set('arecipe', "http://purl.org/amicroformat/arecipe/"); $rezeptNamespace->set('rezept', "http://manke-hosting.de/ns-syntax#"); $rezeptNamespace->set('wrapper', HOST . "index.php/lookup/"); $rezeptNamespace->set('owl', "http://www.w3.org/2002/07/owl#"); $rezeptNamespace->set('reweSuche', HOST . "index.php/reweSuche/"); //$rezeptNamespace->set('reweSuche', "http://manke-hosting.de/wrapper/index.php/reweSuche/"); //$rezeptNamespace->set('reweSuche', "http://localhost/wrapper/index.php/reweSuche/"); $url = $baseURL . $jsonObject['rezept_show_id']; $me = $graph->resource($url, 'arecipe:Recipe'); foreach ($jsonObject as $key => $value) { $type = gettype($value); $namespace = "rezept"; if ($type == "string") { $me->set($namespace . ':' . $key, $value); } elseif ($type == "array" && !empty($value)) { switch ($key) { case 'rezept_videos': // TODO break; case 'rezept_bilder': $bn = $graph->newBNode(); $me->set($namespace . ':' . $key, $bn); buildTree($graph, $bn, $value, 'rezept'); break; case 'rezept_zutaten': foreach ($value as $rezept_zutaten => $zutat) { $bn = $graph->newBNode(); $me->add($namespace . ":" . $key, $bn); foreach ($zutat as $attribut => $attributWert) { if ($attribut == "name" && $zutat["id"] != "") { $attributWert = $str = str_replace(array('ä', 'ö', 'ü', 'ß', 'Ä', 'Ö', 'Ü'), array('ae', 'oe', 'ue', 'ss', 'Ae', 'Oe', 'Ue'), $attributWert); $attributWert = preg_replace('/[^a-zA-Z0-9]+/', '', $attributWert); $bn->addResource('rezept:reweSuche', 'reweSuche:' . $attributWert); $bn->addLiteral($namespace . ":" . $attribut, $attributWert); } elseif ($attribut == "menge") { $attributWert = str_replace(".", ",", $attributWert); $bn->addLiteral($namespace . ":" . $attribut, $attributWert); } else { $bn->addLiteral($namespace . ":" . $attribut, $attributWert); } } } break; default: break; } } } return $graph; }
public function getTreeArray($parent_id = 0, $active = 0) { $pagesArr = $active ? $this->where('active', 1)->get() : $this->get(); $pages = $pagesArr->toArray(); return buildTree($pages); }
function buildTree(array &$elements, $parentId = 0) { $branch = array(); foreach ($elements as $element) { if ($element['parent_id'] == $parentId) { $children = buildTree($elements, $element['id']); if ($children) { $element['children'] = $children; } if ($element['published'] == 1) { $element['checked'] = isset($element['active']) ? (bool) $element['active'] : true; } $branch[] = $element; } } return $branch; }
function initial_list_dimension_members_tree() { $dimension_id = array_var($_REQUEST, 'dimension_id'); $checkedField = (array_var($_REQUEST, 'checkboxes'))?"checked":"_checked"; $objectTypeId = array_var($_REQUEST, 'object_type_id', null ); $allowedMemberTypes = json_decode(array_var($_REQUEST, 'allowedMemberTypes', null )); if (!is_array($allowedMemberTypes)) { $allowedMemberTypes = null; } $only_names = array_var($_REQUEST, 'onlyname', false); $name = trim(array_var($_REQUEST, 'query', '')); $extra_cond = $name == "" ? "" : " AND name LIKE '".$name."%'"; $selected_member_ids = json_decode(array_var($_REQUEST, 'selected_ids', "[0]")); $selected_members = Members::findAll(array('conditions' => 'id IN ('.implode(',',$selected_member_ids).')')); $memberList = $this->initial_list_dimension_members($dimension_id, $objectTypeId, $allowedMemberTypes, false, $extra_cond, null, false, null, $only_names, $selected_members); $tree = buildTree($memberList, "parent", "children", "id", "name", $checkedField); ajx_current("empty"); ajx_extra_data(array('dimension_members' => $tree, 'dimension_id' => $dimension_id)); }