meraproject/themes/merakomis/team/member/controller.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

185 lines
6.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?
namespace controller\themes\merakomis\team\member;
use core\core\structure\eRowClick;
use ms\ms\structure\msControllerTable;
use themes\Merakomis;
use themes\merakomis\Emp;
use themes\merakomis\Project;
use themes\merakomis\structure\merakomisControllerTable;
use themes\merakomis\Team;
use themes\merakomis\team\Member;
class Api extends merakomisControllerTable {
static $class = 'themes\merakomis\team\Member';
public static function getForm() {
$res = [];
if(Emp::$IS_AUTH) {
$_POST[static::$class::$ID] = $_POST['id'];
$res = static::$class::getFormInfo($_POST);
$res['title'] = 'Редактор члена команды';
}
echo je($res);
}
public static function getTableData($post = []) {
$TITLE = null;
$post['options'][\Query::LEFT_JOINS] = [
[Emp::$table_name,Emp::$ID,Member::$EMP]
];
if(($id = intval($post['data']['params']['id']))){
//$project = Team::getProjectByTeamID($id);
$project = Project::getByID($id);
//$TITLE = ['title'=>Project::getCodeName($project),'subtitle'=>'Команда проекта','text'=>'Сводная таблица, содержащая данные о команде проекта.'];
//$TITLE = ['title'=>Project::getCodeName($project),'subtitle'=>Merakomis::$TEAM_TABLE_SUBTITLE,'text'=>Merakomis::$TEAM_TABLE_TEXT];
$team_id = $project[Project::$TEAM];
$TITLE = [
'title' => Project::getCodeName($project),
'edit' => true,
'subtitle' => Merakomis::$TEAM_TABLE_SUBTITLE,
'text' => Merakomis::$TEAM_TABLE_TEXT,
'subtitle_var' => Merakomis::$_TEAM_TABLE_SUBTITLE,
'text_var' => Merakomis::$_TEAM_TABLE_TEXT,
];
$post['options'][\Query::WHERE] = \Where::_operator(Member::$TEAM,'=',$team_id);
$post['options'][\ModuleTable::ROW_CLICK] = eRowClick::NONE;
$sort = [
Emp::$NAME => 'ASC',
];
if($_POST['options']['sort']){
$sort = [];
$count = 0;
foreach ($_POST['options']['sort'] as $k=>$v){
if($k==Member::$EMP) $k = Emp::$NAME;
$sort[$k] = $v;
if($v) $count++;
}
if(!$count) $sort = [];
}
$post['options'][\Query::SORT] = $sort;
} else if(isset($post['data']['project'])){
if($id = intval($post['data']['project'])){
$project = Project::getByID($id);
$team_id = $project[Project::$TEAM];
$my_post = Member::getMyPostForTeam($team_id);
$posts = Member\structure\eMemberRole::getSubRoles($my_post);
if(!$posts) $posts=[0];
$sections = [];
if(isset($post['options']['filter']['section'])){
foreach ($post['options']['filter']['section'] as $v){
if(!$v) {
$sections = [];
break;
} else {
$sections[] = $v;
}
}
}
$post['options'][\Query::WHERE] = \Where::_and([
\Where::_operator(Member::$TEAM,'=',$team_id),
\Where::_operator(Member::$ACTIVE,'=',1),
\Where::_operator(Emp::$ARCHIVE,'=',0),
$sections ? \Where::_in(Member::$SECTION,$sections) : null,
//$posts ? \Where::_in(Member::$POST,$posts) : null,
]);
$post['options'][\ModuleTable::ROW_CLICK] = eRowClick::NONE;
$post['options'][\Query::COUNT] = 0;
$post['options'][\ModuleTable::COLUMN_LIST] = [
Member::$EMP,
Member::$ROLE,
Member::$SECTION,
Member::$_DISCORD,
Member::$_EMAIL,
Member::$_PHONE,
(Emp::$table_name.'_name'),
];
$post['options'][\Query::SELECT] = ['*','if('.Member::$ROLE.'='.Member\structure\eMemberRole::MAIN_ENGINEER.',1,0) as type'];
$sort = [];
if($_POST['options']['sort']){
$sort['type']='DESC';
$count = 0;
foreach ($_POST['options']['sort'] as $k=>$v){
if($k==Member::$EMP) $k = Emp::$NAME;
$sort[$k] = $v;
if($v) $count++;
}
if(!$count) $sort = [];
}
$post['options'][\Query::SORT] =$sort ? : [
'type' => 'DESC',
Emp::$NAME => 'ASC',
];
$TITLE = ['title'=>'Команда проекта','subtitle'=>'','text'=>'Контакт-лист команды проекта'];
}
}
$post['options'][\ModuleTable::COLUMN_RENDER] = [
Member::$EMP => [
/*
\ModuleTable::COLUMN_RENDER_LINK_FUNCTION=>function($v){
return '/public_profile/'.$v[Member::$EMP].'/';
}
*/
]
];
$post['getData'] = true;
$res = parent::getTableData($post);
if($TITLE) $res['title'] = $TITLE;
//if($_POST['options']['sort'][Member::$EMP]) {
if($_POST['options']['sort'][Member::$EMP] || isset($post['data']['project'])) {
$res['columns'][0]['sort'] = $res['sort'][Emp::$NAME]?:'';
}
// $res['sort'][Member::$ROLE] = 'DESC';
/*
if($_POST['options']['sort'][Member::$EMP] || $res['sort'][Emp::$NAME]){
$res['sort'][Member::$EMP] = $res['sort'][Emp::$NAME]?:'ASC';
unset($res['sort'][Emp::$NAME]);
}
/*
switch (intval($id)){
case merakomru::$PARTNERS->id_for_theme : $res['title'] = 'Партнёры'; break;
}
*/
$res["per_page_options"] = [
["id"=>0,"title"=>'Показать всё'],
["id"=>10, "title"=>'10'],
["id"=>25, "title"=>'25'],
["id"=>50, "title"=>'50'],
["id"=>100,"title"=>'100'],
];
echo je($res);
}
}