meraproject/module/academy/course/lesson/controller.php

55 lines
1.6 KiB
PHP
Raw Normal View History

<?
namespace controller\academy\course\lesson;
use academy\Course;
use academy\course\Section;
use ms\ms\structure\msControllerTable;
use academy\course\Lesson;
class Api extends msControllerTable {
static $class = 'academy\course\Lesson';
// Работа с проифилями
static function profileSetDescr(){
if(IF_PROFILE){
$lesson = Lesson::isProfileMy($_POST['lesson_id']);
$descr = trim($_POST['descr']);
if($lesson and $descr){
Lesson::updateById($lesson[Lesson::$ID],[Lesson::$CONTENT=>$descr]);
}
}
}
static function profileSetName(){
if(IF_PROFILE){
$lesson = Lesson::isProfileMy($_POST['lesson_id']);
$name = trim($_POST['name']);
if($lesson and $name){
Lesson::updateById($lesson[Lesson::$ID],[Lesson::$NAME=>$name]);
}
}
}
static function profileCreate(){
$res = [];
if(IF_PROFILE and $course = Course::isProfileMy($_POST['course_id'])){
$course_id = $course[Course::$ID];
$sections = Course::getLessons($course_id);
$section = array_pop($sections['sections']);
$section_id = $section[Section::$ID];
$r = Lesson::insert([
Lesson::$COURSE => $course_id,
Lesson::$SECTION => $section_id,
Lesson::$NAME => 'Новый урок',
Lesson::$ACCOUNT => \Site::$owner_id,
]);
$res['id'] = $r->id;
}
echo je($res);
}
}