update
This commit is contained in:
18
inc/Hura8/Traits/AdminEntityBaseControllerTraits.php
Normal file
18
inc/Hura8/Traits/AdminEntityBaseControllerTraits.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Traits;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
|
||||
/**
|
||||
* @description shared admin traits for all entities
|
||||
*/
|
||||
trait AdminEntityBaseControllerTraits
|
||||
{
|
||||
|
||||
public function getEmptyInfo(array $additional_fields = []) : array
|
||||
{
|
||||
return $this->iEntityModel->getEmptyInfo($additional_fields);
|
||||
}
|
||||
|
||||
}
|
||||
74
inc/Hura8/Traits/AdminEntityCategoryControllerTraits.php
Normal file
74
inc/Hura8/Traits/AdminEntityCategoryControllerTraits.php
Normal 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 .= " ";
|
||||
}
|
||||
|
||||
$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 .= " ";
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
33
inc/Hura8/Traits/ClassCacheTrait.php
Normal file
33
inc/Hura8/Traits/ClassCacheTrait.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
// 04-Mar-2023 simple array-cache for class
|
||||
namespace Hura8\Traits;
|
||||
|
||||
trait ClassCacheTrait
|
||||
{
|
||||
|
||||
protected static $_cache = [];
|
||||
|
||||
protected static function clearCache() {
|
||||
self::$_cache = [];
|
||||
}
|
||||
|
||||
protected static function deleteCacheKey($key) {
|
||||
if (array_key_exists($key, self::$_cache)) {
|
||||
unset(self::$_cache[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getCache($key, callable $fn_create_value) {
|
||||
|
||||
if (!array_key_exists($key, self::$_cache)) {
|
||||
//echo 'cached --- ';
|
||||
$value = call_user_func($fn_create_value);
|
||||
self::$_cache[$key] = $value;
|
||||
}
|
||||
|
||||
// echo "from-cached-".$key."<br>";
|
||||
return self::$_cache[$key];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user