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

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