Created
December 16, 2016 07:01
-
-
Save arungpisyadi/04a8b6ed38b83dc01395a14b5fe7b799 to your computer and use it in GitHub Desktop.
Code archive for MyLibrary/Functions.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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