112 lines
3.4 KiB
PHP
112 lines
3.4 KiB
PHP
|
|
<?
|
||
|
|
namespace widget\video;
|
||
|
|
|
||
|
|
use core\db\structure\Column as C;
|
||
|
|
use core\db\structure\eColumnType;
|
||
|
|
use core\lang\structure\LangVariable as V;
|
||
|
|
use ms\ms\structure\msModuleTable;
|
||
|
|
use widget\video\block\structure\eWidgetVideoBlockType;
|
||
|
|
use widget\video\block\structure\widgetVideoBlockLang as Vars;
|
||
|
|
|
||
|
|
|
||
|
|
class Block extends msModuleTable {
|
||
|
|
static $self;
|
||
|
|
static $table_name = 'widgetVideoBlock';
|
||
|
|
static $controller = 'widget.video.block';
|
||
|
|
|
||
|
|
static $ID = 'id';
|
||
|
|
static $NAME = 'name';
|
||
|
|
static $VIDEO = 'video';
|
||
|
|
static $POS = 'pos';
|
||
|
|
static $TYPE = 'type';
|
||
|
|
static $ARCHIVE = 'archive';
|
||
|
|
|
||
|
|
|
||
|
|
static function getTitle(){return V::get(Vars::$MODULE_NAME);}
|
||
|
|
static function getSystemLangValues():array{ return Vars::getArray(); }
|
||
|
|
|
||
|
|
static function format($v){
|
||
|
|
return [
|
||
|
|
'id' => intval($v[self::$ID]),
|
||
|
|
'pos' => intval($v[self::$POS]),
|
||
|
|
'title' => trim((string)$v[self::$NAME]),
|
||
|
|
'type' => intval($v[self::$TYPE]),
|
||
|
|
'css_class' => eWidgetVideoBlockType::getCssClass($v[self::$TYPE]),
|
||
|
|
'href' => eWidgetVideoBlockType::getHref($v[self::$TYPE],$v[self::$NAME]),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
public static function getByVideoID($id,$isAssoc=true){
|
||
|
|
$id = intval($id);
|
||
|
|
$where = \Where::_and([
|
||
|
|
\Where::_operator(self::$VIDEO,'=',$id),
|
||
|
|
\Where::_operator(self::$ARCHIVE,'=',0),
|
||
|
|
]);
|
||
|
|
return self::select([
|
||
|
|
\Query::SORT => [self::$POS],
|
||
|
|
\Query::WHERE => new \Where($where)
|
||
|
|
],$isAssoc);
|
||
|
|
|
||
|
|
}
|
||
|
|
public static function getByVideoIDFormatted($id){
|
||
|
|
$res = [];
|
||
|
|
$a = self::getByVideoID($id);
|
||
|
|
foreach ($a as $v){
|
||
|
|
$res[] = self::format($v);
|
||
|
|
}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function installUniques() {
|
||
|
|
\DB::addIndex(self::$table_name,self::$VIDEO);
|
||
|
|
\DB::addIndex(self::$table_name,self::$POS);
|
||
|
|
}
|
||
|
|
|
||
|
|
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,
|
||
|
|
C::HIDDEN =>true,
|
||
|
|
C::TH =>V::get(Vars::$ID),
|
||
|
|
]),
|
||
|
|
new C([
|
||
|
|
C::VAR_NAME => &self::$NAME,
|
||
|
|
C::TYPE => eColumnType::VARCHAR,
|
||
|
|
C::LENGTH => 63
|
||
|
|
]),
|
||
|
|
new C([
|
||
|
|
C::VAR_NAME => &self::$VIDEO,
|
||
|
|
C::TYPE => eColumnType::INT,
|
||
|
|
C::DEFAULT => 0,
|
||
|
|
]),
|
||
|
|
new C([
|
||
|
|
C::VAR_NAME => &self::$POS,
|
||
|
|
C::TYPE => eColumnType::INT,
|
||
|
|
C::DEFAULT => 0,
|
||
|
|
]),
|
||
|
|
new C([
|
||
|
|
C::VAR_NAME => &self::$ARCHIVE,
|
||
|
|
C::TYPE => eColumnType::TINYINT,
|
||
|
|
C::DEFAULT => 0,
|
||
|
|
]),
|
||
|
|
new C([
|
||
|
|
C::VAR_NAME => &self::$TYPE,
|
||
|
|
C::TYPE => eColumnType::TINYINT,
|
||
|
|
C::DEFAULT => 0,
|
||
|
|
]),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
new Block();
|
||
|
|
|
||
|
|
|
||
|
|
///
|
||
|
|
|