This commit is contained in:
2024-01-31 11:36:25 +07:00
parent caef156a05
commit 4561bd68d1
125 changed files with 9117 additions and 58 deletions

View File

@@ -0,0 +1,74 @@
<?php
namespace Hura8\Traits;
trait AdminEntityCategoryControllerTraits
{
public function getDropBox($selectedId, $categoryParentId, $level=1){
$all_categories = $this->getAllParent([]);
$extra_space = "";
for($i = 1; $i < $level; $i++){
$extra_space .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
$result = "";
if(isset($all_categories[$categoryParentId])) {
foreach($all_categories[$categoryParentId] as $cat_info){
$cat_id = $cat_info['id'];
if($selectedId == $cat_id) {
$result .= "<option value='".$cat_id."' selected>". $extra_space ." - ".$cat_info['title']."</option>";
}
else {
$result .= "<option value='".$cat_id."'>". $extra_space ." - ".$cat_info['title']."</option>";
}
if($cat_info['is_parent']) {
$result .= $this->getDropBox($selectedId, $cat_id, $level+1);
}
}
}
return $result;
}
public function categorySelectBox(array $array_selected, $categoryParentId, $level=1){
$all_categories = $this->getAllParent([]);
if(!isset($all_categories[$categoryParentId])) return '';
$extra_space = "";
for($i = 1; $i < $level; $i++){
$extra_space .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
$result = '';
foreach ( $all_categories[$categoryParentId] as $item ) {
$checked = (in_array($item['id'], $array_selected)) ? "checked" : "";
if($item['is_parent']) {
$result .= $extra_space ." <strong>". $item['title']."</strong><br/>";
$result .= $this->categorySelectBox( $array_selected, $item['id'], $level+1);
}else{
if(!$checked) {
$result .= $extra_space . " <input type='checkbox' id='cat_" . $item['id'] . "' value=\"" . $item['id'] . "\" onchange=\"select_cat('cat_" . $item['id'] . "', " . $item['id'] . ")\" " . $checked . " /> <label for='cat_" . $item['id'] . "'>" . $item['title'] . "</label><br/>";
}else{
$result .= $extra_space . " <input type='checkbox' id='cat_" . $item['id'] . "' value=\"" . $item['id'] . "\" onchange=\"select_cat('cat_" . $item['id'] . "', " . $item['id'] . ")\" " . $checked . " /> <label for='cat_" . $item['id'] . "' style='background-color:#FC0'>" . $item['title'] . "</label><br/>";
}
}
}
return $result;
}
}