103 lines
3.2 KiB
PHP
103 lines
3.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace themes\merakomis\structure;
|
||
|
|
|
||
|
|
use core\core\structure\eRowClick;
|
||
|
|
use ms\ms\structure\msControllerTable;
|
||
|
|
use ms\ms\structure\msTo;
|
||
|
|
use ms\table\Filter;
|
||
|
|
use themes\merakomis\Emp;
|
||
|
|
use themes\merakomis\structure\merakomisModuleTable;
|
||
|
|
|
||
|
|
|
||
|
|
class merakomisControllerTable extends msControllerTable {
|
||
|
|
/** @var merakomisModuleTable */
|
||
|
|
static $class = '';
|
||
|
|
|
||
|
|
public static function updatePositions(){
|
||
|
|
$res = [];
|
||
|
|
if(Emp::$IS_AUTH) {
|
||
|
|
// TODO: Сделать проверку прав доступа
|
||
|
|
\DB::startTransaction();
|
||
|
|
$pos= 0;
|
||
|
|
foreach ($_POST['ids'] as $id){
|
||
|
|
$res[] = static::$class::updateById(intval($id),[
|
||
|
|
static::$class::$POS => intval($pos++),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
\DB::endTransaction();
|
||
|
|
}
|
||
|
|
echo je($res);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public static function getTableData($post = []) {
|
||
|
|
$res = [];
|
||
|
|
if(Emp::$IS_AUTH) {
|
||
|
|
$options = $post['options'];
|
||
|
|
if(!$options[\ModuleTable::ROW_CLICK]) {
|
||
|
|
$options[\ModuleTable::ROW_CLICK] = eRowClick::OPEN_UADD;
|
||
|
|
}
|
||
|
|
$options[\ModuleTable::SAVED_FILTERS] = Filter::formatArray(
|
||
|
|
Filter::getByToOid(
|
||
|
|
str_replace("themes.merakomis.","",static::$class::$controller),
|
||
|
|
msTo::MERAKOMBIS_EMP,
|
||
|
|
Emp::$AUTH_ID
|
||
|
|
)
|
||
|
|
);
|
||
|
|
$search_where = null;
|
||
|
|
if($search = trim((string)$options['search'])) {
|
||
|
|
|
||
|
|
$properties = ['NAME','PHONE','EMAIL','TEXT'];
|
||
|
|
$or_search = [];
|
||
|
|
foreach ($properties as $prop){
|
||
|
|
if(property_exists(static::$class,$prop)) {
|
||
|
|
$search_text = $search;
|
||
|
|
if($prop=='PHONE'){
|
||
|
|
if(substr($search,0,1)=='7'){
|
||
|
|
$search_text = substr($search,1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$or_search[] = \Where::_operator(static::$class::$$prop, 'LIKE', '%' . $search_text . '%');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$s = static::$class::whereSearch($search);
|
||
|
|
if($s){
|
||
|
|
$or_search[] = $s;
|
||
|
|
}
|
||
|
|
|
||
|
|
if($or_search) {
|
||
|
|
$search_where = \Where::_or($or_search);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
$where_and = [];
|
||
|
|
if($options[\Query::WHERE]) $where_and[] = $options[\Query::WHERE];
|
||
|
|
if($search_where) $where_and[] = $search_where;
|
||
|
|
|
||
|
|
if($where_and) {
|
||
|
|
$options[\Query::WHERE] = \Where::_and($where_and);
|
||
|
|
}
|
||
|
|
$res = parent::getTableData($options);
|
||
|
|
}
|
||
|
|
// TODO: Включить после обновления движка
|
||
|
|
if($post['getData']) return $res;
|
||
|
|
else echo je($res);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getForm() {
|
||
|
|
$res = [];
|
||
|
|
if(Emp::$IS_AUTH) {
|
||
|
|
$res = parent::getForm();
|
||
|
|
}
|
||
|
|
echo je($res);
|
||
|
|
}
|
||
|
|
public static function deleteByIds(){
|
||
|
|
$res = [];
|
||
|
|
if(Emp::$IS_AUTH) {
|
||
|
|
static::$class::deleteByIDS($_POST['ids']);
|
||
|
|
}
|
||
|
|
echo je($res);
|
||
|
|
}
|
||
|
|
}
|