meraproject/module/academy/course/controller.php

93 lines
2.7 KiB
PHP
Raw Normal View History

<?
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);
}
}