meraproject/module/blog/news/section/model.php
keboss-m 5c21d25d45 Initial commit: Merakomis portal, Docker stack and user-reader API.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:04:05 +03:00

130 lines
4.2 KiB
PHP

<?
namespace blog\news;
use blog\News;
use common\Seo;
use core\db\structure\Column as C;
use core\db\structure\eColumnType;
use ms\ms\structure\eTab;
use ms\ms\structure\eTabType;
use ms\ms\structure\msTo;
use ui\form\structure\eInputType;
use ui\Form;
use ui\input\Input;
use core\lang\structure\LangVariable as V;
use ms\ms\structure\msModuleTable;
use blog\news\section\structure\blogNewsSectionLang as Vars;
use blog\Section as BlogSection;
class Section extends msModuleTable {
static $self;
static $table_name = 'blogNewsSection';
static $controller = 'blog.news.section';
static $easy_left_joins;
static $ID = 'id';
static $NEWS = 'news';
static $SECTION = 'section';
static $ACCOUNT = 'account';
public static function installUniques() {
\DB::addUnique(self::$table_name,self::$table_name.'_unique',[self::$NEWS,self::$SECTION]);
\DB::addIndex(self::$table_name,self::$NEWS);
\DB::addIndex(self::$table_name,self::$SECTION);
}
static function getTitle(){return V::get(Vars::$MODULE_NAME);}
static function getSystemLangValues():array{ return Vars::getArray(); }
public function __construct($install_id = null) {
parent::__construct($install_id);
self::$easy_left_joins = [
[BlogSection::$table_name,BlogSection::$ID,self::$SECTION]
];
}
static function getForm($values = [], $options = []) :array {
$C = News::getByID($values[self::$NEWS]);
$sections = BlogSection::getNameList([
\Query::WHERE => new \Where(\Where::_and([
\Where::_operator(BlogSection::$BLOG,'=',$C[News::$BLOG]),
\Where::_operator(BlogSection::$ACCOUNT,'=',UID),
]))
]);
return [
self::getCommonFormInputs(),
[
Form::VIEW =>Form::INPUT,
Form::KEY_VALUE =>self::$NEWS,
Form::TYPE =>eInputType::HIDDEN,
],
[
Form::VIEW=>Form::ROW,
Form::COLS => [
[
Form::VIEW =>Form::INPUT,
Form::COL_CLASSES =>'col-12',
Form::KEY_VALUE =>self::$SECTION,
Form::TYPE =>eInputType::SELECT_SEARCH,
Form::INPUT_OPT => [
Input::PLACEHOLDER => $c = V::get(Vars::$NAME),
Input::LABEL => $c,
Input::OPTIONS => $sections
],
],
]
],
self::getCommonFormSubmits($values),
];
}
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::$NEWS,
C::TYPE => eColumnType::INT,
C::HIDDEN => true,
]),
new C([
C::VAR_NAME => &self::$SECTION,
C::TYPE => eColumnType::INT,
C::TH => V::get(Vars::$SECTION),
C::FUNC_VALUE_DATA => function($v){
return BlogSection::getName($v);
}
]),
new C([
C::VAR_NAME => &self::$ACCOUNT,
C::TYPE => eColumnType::INT,
C::LENGTH => 11,
C::TH => V::get(Vars::$ACCOUNT),
C::DEFAULT => intval(UID),
c::HIDDEN=>true,
c::FUNC_VALUE => function($v){
if($id = $v[self::$ACCOUNT]) {
return \Account::getName( \Account::getByID($id) );
} else return '-';
},
]),
];
}
}
new Section();