164 lines
4.9 KiB
PHP
164 lines
4.9 KiB
PHP
|
|
<?
|
||
|
|
namespace core;
|
||
|
|
|
||
|
|
use \Core\db\structure\Column as C;
|
||
|
|
use \Core\db\structure\eColumnType;
|
||
|
|
|
||
|
|
new Columns();
|
||
|
|
class Columns extends \ModuleTable {
|
||
|
|
static $self;
|
||
|
|
static $table_name = 'accColumns';
|
||
|
|
|
||
|
|
static $ID = 'id';
|
||
|
|
static $ACC = 'acc';
|
||
|
|
static $COLUMNS = 'columns';
|
||
|
|
static $MODULE = 'module';
|
||
|
|
static $WIDTH = 'width';
|
||
|
|
|
||
|
|
|
||
|
|
static function getUserId(){
|
||
|
|
return UID;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
static $translates = [];
|
||
|
|
static function add($values){
|
||
|
|
$values[static::$MODULE] = \Core::prepareModuleName($values[static::$MODULE]);
|
||
|
|
static::insert($values,[\Query::ON_DUPLICATE_KEY_UPDATE=>[
|
||
|
|
static::$COLUMNS=>$values[static::$COLUMNS]
|
||
|
|
]]);
|
||
|
|
}
|
||
|
|
static function getMyByModuleName($module_name){
|
||
|
|
$module_name = \Core::prepareModuleName($module_name);
|
||
|
|
return static::select([
|
||
|
|
\Query::WHERE=>new \Where(\Where::_and([
|
||
|
|
\Where::_operator(static::$ACC,'=',static::getUserID()),
|
||
|
|
\Where::_operator(static::$MODULE,'=',$module_name),
|
||
|
|
]))
|
||
|
|
],true);
|
||
|
|
}
|
||
|
|
|
||
|
|
static function getMyWidth($module_name){
|
||
|
|
$cols = static::getMyByModuleName($module_name);
|
||
|
|
$cols = array_pop($cols);
|
||
|
|
$res = json_decode($cols[static::$WIDTH],true);
|
||
|
|
if(!$res) $res = [];
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
|
||
|
|
static function saveWidth($module_name,$column_name,$width){
|
||
|
|
$cols = static::getMyByModuleName($module_name);
|
||
|
|
$cols = array_pop($cols);
|
||
|
|
$w = json_decode($cols[static::$WIDTH],true);
|
||
|
|
if(!$w) $w = [];
|
||
|
|
$w[(string)$column_name] = floatval($width);
|
||
|
|
static::updateById($cols[static::$ID],[
|
||
|
|
static::$WIDTH=>je($w)
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
static function getMyColumns(string $module_name){
|
||
|
|
$module_name = \Core::prepareModuleName($module_name);
|
||
|
|
$info = $module_name::getColumns();
|
||
|
|
$res = [];
|
||
|
|
$cols = static::getMyByModuleName($module_name);
|
||
|
|
if($cols) {
|
||
|
|
$data = array_pop($cols);
|
||
|
|
$data = json_decode($data[static::$COLUMNS],true);
|
||
|
|
foreach ($data as $v) {
|
||
|
|
$res[$v] = $info[$v];
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$width = [];
|
||
|
|
foreach ($info as $k=>$v){
|
||
|
|
$width[$k] = 0;
|
||
|
|
}
|
||
|
|
static::add([
|
||
|
|
static::$ACC =>static::getUserID(),
|
||
|
|
static::$MODULE =>$module_name,
|
||
|
|
static::$COLUMNS =>json_encode(array_keys($info)),
|
||
|
|
static::$WIDTH =>json_encode($width),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
if(!$res) $res = $info;
|
||
|
|
foreach($res as $k=>$v){
|
||
|
|
if(!$v) {
|
||
|
|
unset($res[$k]);
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if($v->isHidden()) unset($res[$k]);
|
||
|
|
}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
|
||
|
|
static function afterInstall() {
|
||
|
|
parent::afterInstall(); // TODO: Change the autogenerated stub
|
||
|
|
\DB::addUnique(static::$table_name,static::$table_name,[static::$ACC,static::$MODULE]);
|
||
|
|
}
|
||
|
|
static function getFilePathForViewList(){
|
||
|
|
return dirname(__FILE__).'/views/my.php';
|
||
|
|
}
|
||
|
|
|
||
|
|
static function viewMyColumns(string $module_name){
|
||
|
|
try {
|
||
|
|
$module_name = \Core::prepareModuleName($module_name);
|
||
|
|
$info = $module_name::getColumns();
|
||
|
|
foreach($info as $k=>$v){
|
||
|
|
if($v->isHidden()) unset($info[$k]);
|
||
|
|
}
|
||
|
|
$my = static::getMyColumns($module_name);
|
||
|
|
include_once(static::getFilePathForViewList());
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static function setColumns($module_name,$_cols){
|
||
|
|
$cols = [];
|
||
|
|
if(is_array($_cols)) {
|
||
|
|
foreach ($_cols as $v) $cols[] = (string)$v;
|
||
|
|
}
|
||
|
|
static::add([
|
||
|
|
static::$MODULE => $module_name,
|
||
|
|
static::$COLUMNS => je($cols),
|
||
|
|
]);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
static function columnInfo() : array {
|
||
|
|
return [
|
||
|
|
new C([
|
||
|
|
C::VAR_NAME =>&self::$ID,
|
||
|
|
C::TYPE =>eColumnType::INT,
|
||
|
|
C::AUTO_INCREMENT =>true,
|
||
|
|
C::PRIMARY =>true,
|
||
|
|
C::DEFAULT =>0,
|
||
|
|
]),
|
||
|
|
new C([
|
||
|
|
C::VAR_NAME => &self::$ACC,
|
||
|
|
C::TYPE => eColumnType::INT,
|
||
|
|
C::LENGTH => 11,
|
||
|
|
C::DEFAULT => self::getUserID(),
|
||
|
|
]),
|
||
|
|
new C([
|
||
|
|
C::VAR_NAME => &self::$COLUMNS,
|
||
|
|
C::TYPE => eColumnType::TEXT,
|
||
|
|
]),
|
||
|
|
new C([
|
||
|
|
C::VAR_NAME => &self::$MODULE,
|
||
|
|
C::TYPE => eColumnType::VARCHAR,
|
||
|
|
C::LENGTH => 50,
|
||
|
|
]),
|
||
|
|
new C([
|
||
|
|
C::VAR_NAME => &self::$WIDTH,
|
||
|
|
C::TYPE => eColumnType::TEXT,
|
||
|
|
]),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|