Skip to content

Instantly share code, notes, and snippets.

@arungpisyadi
Created December 16, 2016 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arungpisyadi/04a8b6ed38b83dc01395a14b5fe7b799 to your computer and use it in GitHub Desktop.
Save arungpisyadi/04a8b6ed38b83dc01395a14b5fe7b799 to your computer and use it in GitHub Desktop.
Code archive for MyLibrary/Functions.php
/*
public static function leafNode() {
$allCats = Categories::all()->toArray();
for ( $i = 0; $i < count($allCats); $i++) {
$children = DB::table('categoryOrganisations')->where('categoryId', $allCats[$i]['id'])->count();
if($children === 0) {
DB::table('categories')->where('id', $allCats[$i]['id'])->update(['leaf' => 1]);
} else {
DB::table('categories')->where('id', $allCats[$i]['id'])->update(['leaf' => 0]);
}
}
}
public static function build_hierarchy() {
$allCats = Categories::all()->toArray();
for($i = 0; $i < count($allCats); $i++) {
$hier = '';
if ($allCats[$i]['hierarchy'] === NULL && $allCats[$i]['ParentId'] === NULL) {
DB::table('categories')->where('id', $allCats[$i]['id'])->update(['hierarchy' => $allCats[$i]['title']]);
$hier = $allCats[$i]['title'];
} else {
$hier = $allCats[$i]['hierarchy'];
}
$children = DB::table('categoryOrganisations')->where('categoryId', $allCats[$i]['id'])->get();
for ($h = 0; $h < count($children); $h++) {
$subCat = DB::table('categories')->where('id', $children[$h]->SubCategoryId)->first();
DB::table('categories')->where('id', $children[$h]->SubCategoryId)->update(['hierarchy' => $hier .' / '. $subCat->title]);
}
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment