$tableSlides = StudyPressDB::getPrefix() . 'studi_slides'; $tableCategCourse = StudyPressDB::getPrefix() . 'studi_categ_cours'; if ($access->getVar("SHOW TABLES LIKE '{$tableCat}'") == $tableCat) { if ($access->getVar("SHOW TABLES LIKE '{$tableCourse}'") == $tableCourse) { $catWPId = wp_create_category('Temporary Category'); $managerCourse = new CourseManager(); $course = new Course(array('name' => 'Temporary Course', 'description' => '', 'authors' => array($user->id()), 'categories' => array($catWPId !== 0 ? $catWPId : 1))); $courseId = $managerCourse->add($course); $resultLesson = $access->getResults("SELECT * FROM {$tableCourse}"); $authors = array(); foreach ($resultLesson as $lesson) { $managerLesson = new LessonManager(); if ($a = get_user_by('login', $lesson['author'])) { $authors[] = $a->ID; } $lessonId = $managerLesson->add(new Lesson(array('name' => $lesson['nom'] != "" ? $lesson['nom'] : "Course", 'author' => $a ? $a->display_name : $user->displayName(), 'authorId' => $a ? $a->ID : $user->id(), 'description' => $lesson['cours_des'], 'duration' => $lesson['duration'], 'courseId' => $courseId))); if (!in_array($user->id(), $authors)) { $authors[] = $user->id(); } if ($access->getVar("SHOW TABLES LIKE '{$tableSlides}'") == $tableSlides) { $slidesResult = $access->getResults("SELECT * FROM {$tableSlides} WHERE course_id = '" . $lesson['course_id'] . "'"); $managerSlide = new SlideManager(); foreach ($slidesResult as $slide) { $managerSlide->add(new Slide(array('courseId' => $lessonId, 'name' => $slide['slides_name'] != "" ? $slide['slides_name'] : "Slide", 'content' => $slide['slides_content'], 'order' => $slide['slides_order']))); } } } $course->setAuthors($authors); $managerCourse->update($courseId, $course); add_action('admin_init', 'sp_notice_warning_migrate'); function sp_notice_warning_migrate()
$v->addRule('pictureurl', 'numeric', true, 1, 999999, true); } if (isset($_POST['lesson']['file']) && !empty($_POST['lesson']['file'])) { $v->addRule('file', 'numeric', true, 1, 99999, true); } if (isset($_POST['lesson']['courseId']) && !empty($_POST['lesson']['courseId'])) { $v->addRule('courseId', 'numeric', true, 1, 99999, true); } else { $v->errors['courseId'] = $tr->__("You must create a course"); } $v->run(); if (sizeof($v->errors) > 0) { $error_lesson_add = $v->getMessageErrors(); } else { $currentUser = new StudyPressUserWP(); $id_lesson = $managerLesson->add(new Lesson(array('pictureUrl' => isset($v->sanitized['pictureurl']) ? $v->sanitized['pictureurl'] : '', 'name' => $v->sanitized['name'], 'author' => $currentUser->displayName(), 'authorId' => $currentUser->id(), 'courseId' => $v->sanitized['courseId']))); if (isset($v->sanitized['file']) && !empty($v->sanitized['file'])) { $urlFile = wp_get_attachment_url($v->sanitized['file']); $managerSlide = new SlideManager(); $slide = new Slide(array('courseId' => $id_lesson, 'name' => $tr->__("Download the file"), 'content' => "<a href='" . $urlFile . "'>" . basename($urlFile, pathinfo($urlFile, PATHINFO_EXTENSION)) . "</a>")); $managerSlide->add($slide); $lesson = $managerLesson->getById($id_lesson); $postId = $managerLesson->post($lesson); $permalink = get_permalink($postId); $action = $lesson->getAuthor() . " " . $tr->__("shared a lesson") . " : " . "<a href='{$permalink}'>" . $lesson->getName() . "</a>"; $imageUrl = $lesson->getPicture(); $content = "<a href='{$permalink}'><img src='{$imageUrl}' width='150' height='150' /></a>"; $managerLesson->shareOnGroupsBP($lesson, $action, $content); } } }