54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
||
|
||
// Работа с типами данных
|
||
|
||
defined('ROOT_DIR') || exit;
|
||
|
||
trait Datatypes {
|
||
public array $datatypes = array();
|
||
|
||
// Загрузка типов данных
|
||
public function datatype_load(): bool
|
||
{
|
||
$datatypes_dir = PLAYAREA_DIR_NAME . SLASH . "datatypes";
|
||
$datatypes = scandir($datatypes_dir, SCANDIR_SORT_DESCENDING);
|
||
if(!count($datatypes)) return false;
|
||
foreach ($datatypes as $key => $value) {
|
||
$name = $this->datatype_convert_name($value);
|
||
if(!$name) continue;
|
||
require_once $datatypes_dir . SLASH . $value;
|
||
$classes = get_declared_classes();
|
||
$class_name = end($classes);
|
||
$this->datatypes[] = $class_name;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
private function datatype_convert_name($name): string
|
||
{
|
||
$parts = explode('.', $name);
|
||
if($parts[0] != "datatype" || !isset($parts[1])) return false;
|
||
return trim($parts[1]);
|
||
}
|
||
|
||
// Получить Объект по ID
|
||
public function get_item_by_id($item_id)
|
||
{
|
||
$search = new Search(array(
|
||
"limit" => 1,
|
||
"terms" => array("item_id" => $item_id)
|
||
));
|
||
$items = $search->collect();
|
||
if(!count($items)) return false;
|
||
list($item) = $items;
|
||
return $item;
|
||
}
|
||
|
||
// Получить Class объекта по ID
|
||
public function get_item_class_by_id($item_id)
|
||
{
|
||
$item = $this->get_item_by_id($item_id);
|
||
if($item === false) return false;
|
||
return $item->get_class_name();
|
||
}
|
||
} |