meraproject/module/academy/project/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

88 lines
2.8 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\academy\project;
use academy\Project;
use common\Image;
use ms\ms\structure\msControllerTable;
class Api extends msControllerTable {
static $class = 'academy\Project';
// Работа с проифилями
static function profileSetDescr(){
if(IF_PROFILE){
$project = Project::isProfileMy($_POST['project_id']);
$descr = trim($_POST['descr']);
if($project and $descr){
Project::updateById($project[Project::$ID],[Project::$DESCR=>$descr]);
}
}
}
static function profileSetName(){
if(IF_PROFILE){
$project = Project::isProfileMy($_POST['project_id']);
$name = trim($_POST['name']);
if($project and $name){
Project::updateById($project[Project::$ID],[Project::$NAME=>$name]);
}
}
}
static function profileSetAva(){
if(IF_PROFILE){
$project = Project::isProfileMy($_POST['project_id']);
$img = Image::isProfileMy($_POST['image_id']);
if($project and $img){
Project::updateById($project[Project::$ID],[Project::$AVA=>$img[Image::$ID]]);
}
}
}
static function profileSetBG(){
if(IF_PROFILE){
$project = Project::isProfileMy($_POST['project_id']);
$img = Image::isProfileMy($_POST['image_id']);
if($project and $img){
Project::updateById($project[Project::$ID],[Project::$BG=>$img[Image::$ID]]);
}
}
}
static function profileUpdateSettings(){
$res = [];
if(IF_PROFILE and $project = Project::isProfileMy($_POST['project_id'])){
$arr = [
//'price'=>Project::$PRICE,
'annotation' => Project::$ANNOTATION,
'category' => Project::$CATEGORY,
'vis' => Project::$VIS,
'public' => Project::$PUBLIC,
];
$newData = [];
foreach ($arr as $k=>$v){
if(isset($_POST[$k])) $newData[$v] = $_POST[$k];
}
if(isset($newData[$c = Project::$CATEGORY])) $newData[$c] = intval($newData[$c]);
if(isset($newData[$c = Project::$VIS])) $newData[$c] = intval($newData[$c]);
if(isset($newData[$c = Project::$PUBLIC])) $newData[$c] = intval($newData[$c]);
$x = Project::updateById($project[Project::$ID],$newData);
}
echo je($res);
}
static function profileCreate(){
$res = [];
if(IF_PROFILE){
$r = Project::insert([
Project::$NAME => $_POST['name'],
Project::$ACCOUNT => \Site::$owner_id,
]);
$res['id'] = $r->id;
}
echo je($res);
}
}