コード例 #1
0
    /**
     * Function rewritten based on old_add_item() from Yannick Warnier. Due the fact that users can decide where the item should come, I had to overlook this function and
     * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
     *
     * @param int $parent
     * @param int $previous
     * @param string $type
     * @param int  resource ID (ref)
     * @param string $title
     * @param string $description
     * @return int
     */
    public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0)
    {
        $course_id = api_get_course_int_id();
        if ($this->debug > 0) {
            error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
        }
        $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
        $parent = intval($parent);
        $previous = intval($previous);
        $type = Database::escape_string($type);
        $id = intval($id);
        $max_time_allowed = Database::escape_string($max_time_allowed);
        if (empty($max_time_allowed)) {
            $max_time_allowed = 0;
        }
        $title = Database::escape_string($title);
        $description = Database::escape_string($description);
        $sql_count = "\tSELECT COUNT(id) AS num\n                        FROM {$tbl_lp_item}\n                        WHERE c_id = {$course_id} AND lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
        $res_count = Database::query($sql_count);
        $row = Database::fetch_array($res_count);
        $num = $row['num'];
        if ($num > 0) {
            if ($previous == 0) {
                $sql = "SELECT id, next_item_id, display_order\n                           FROM " . $tbl_lp_item . "\n                           WHERE   c_id = {$course_id} AND\n                                   lp_id = " . $this->get_id() . " AND\n                                   parent_item_id = " . $parent . " AND\n                                   previous_item_id = 0 OR previous_item_id=" . $parent;
                $result = Database::query($sql);
                $row = Database::fetch_array($result);
                $tmp_previous = 0;
                $next = $row['id'];
                $display_order = 0;
            } else {
                $previous = (int) $previous;
                $sql = "SELECT id, previous_item_id, next_item_id, display_order\n\t\t\t\t\t\tFROM {$tbl_lp_item}\n                        WHERE c_id = {$course_id} AND lp_id = " . $this->get_id() . " AND id = " . $previous;
                $result = Database::query($sql);
                $row = Database::fetch_array($result);
                $tmp_previous = $row['id'];
                $next = $row['next_item_id'];
                $display_order = $row['display_order'];
            }
        } else {
            $tmp_previous = 0;
            $next = 0;
            $display_order = 0;
        }
        $new_item_id = -1;
        $id = Database::escape_string($id);
        if ($type == 'quiz') {
            $sql = 'SELECT SUM(ponderation)
					FROM ' . Database::get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
                    INNER JOIN ' . Database::get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
                    ON quiz_question.iid = quiz_rel_question.question_id
                    WHERE   quiz_rel_question.exercice_id = ' . $id . " AND\n\t            \t\t\tquiz_question.c_id = {$course_id} AND\n\t            \t\t\tquiz_rel_question.c_id = {$course_id} ";
            $rsQuiz = Database::query($sql);
            $max_score = Database::result($rsQuiz, 0, 0);
            //Disabling the exercise if we add it inside a LP
            $exercise = new Exercise();
            $exercise->read($id);
            $exercise->disable();
            $exercise->save();
        } else {
            $max_score = 100;
        }
        if ($prerequisites != 0) {
            $sql_ins = "INSERT INTO " . $tbl_lp_item . " (\n            \t\t\t\t\tc_id,\n                                lp_id, " . "item_type, " . "ref, " . "title, " . "description, " . "path, " . "max_score, " . "parent_item_id, " . "previous_item_id, " . "next_item_id, " . "display_order, " . "prerequisite, " . "max_time_allowed " . ") VALUES (\n                            \t{$course_id} ,\n                                " . $this->get_id() . ", " . "'" . $type . "', " . "'', " . "'" . $title . "', " . "'" . $description . "', " . "'" . $id . "', " . "'" . $max_score . "', " . $parent . ", " . $previous . ", " . $next . ", " . ($display_order + 1) . ", " . $prerequisites . ", " . $max_time_allowed . ")";
        } else {
            // Insert new item.
            $sql_ins = "\n                            INSERT INTO " . $tbl_lp_item . " ( " . "c_id, " . "lp_id, " . "item_type, " . "ref, " . "title, " . "description, " . "path, " . "max_score, " . "parent_item_id, " . "previous_item_id, " . "next_item_id, " . "display_order, " . "max_time_allowed " . ") VALUES (" . $course_id . "," . $this->get_id() . "," . "'" . $type . "'," . "''," . "'" . $title . "'," . "'" . $description . "'," . "'" . $id . "'," . "'" . $max_score . "'," . $parent . "," . $previous . "," . $next . "," . ($display_order + 1) . "," . $max_time_allowed . ")";
        }
        if ($this->debug > 2) {
            error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
        }
        $res_ins = Database::query($sql_ins);
        if ($res_ins) {
            $new_item_id = Database::insert_id();
            // Update the item that should come after the new item.
            $sql_update_next = "\n                            UPDATE " . $tbl_lp_item . "\n                            SET previous_item_id = " . $new_item_id . "\n                            WHERE c_id = {$course_id} AND id = " . $next;
            Database::query($sql_update_next);
            // Update the item that should be before the new item.
            $sql_update_previous = "\n                            UPDATE " . $tbl_lp_item . "\n                            SET next_item_id = " . $new_item_id . "\n                            WHERE c_id = {$course_id} AND id = " . $tmp_previous;
            Database::query($sql_update_previous);
            // Update all the items after the new item.
            $sql_update_order = "\n                            UPDATE " . $tbl_lp_item . "\n                            SET display_order = display_order + 1\n                            WHERE\n                                c_id = {$course_id} AND\n                                lp_id = " . $this->get_id() . " AND\n                                id <> " . $new_item_id . " AND\n                                parent_item_id = " . $parent . " AND\n                                display_order > " . $display_order;
            Database::query($sql_update_order);
            // Update the item that should come after the new item.
            $sql_update_ref = "UPDATE " . $tbl_lp_item . "\n                               SET ref = " . $new_item_id . "\n                               WHERE c_id = {$course_id} AND id = " . $new_item_id;
            Database::query($sql_update_ref);
        }
        // Upload audio.
        if (!empty($_FILES['mp3']['name'])) {
            // Create the audio folder if it does not exist yet.
            $_course = api_get_course_info();
            $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
            if (!is_dir($filepath . 'audio')) {
                mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
                $audio_id = FileManager::add_document($_course, '/audio', 'folder', 0, 'audio');
                api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
                api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'invisible', api_get_user_id(), null, null, null, null, api_get_session_id());
            }
            // Upload the file in the documents tool.
            $file_path = FileManager::handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', false);
            // Getting the filename only.
            $file_components = explode('/', $file_path);
            $file = $file_components[count($file_components) - 1];
            // Store the mp3 file in the lp_item table.
            $sql_insert_audio = "UPDATE {$tbl_lp_item} SET audio = '" . Database::escape_string($file) . "' WHERE id = '" . Database::escape_string($new_item_id) . "'";
            Database::query($sql_insert_audio);
        }
        return $new_item_id;
    }
コード例 #2
0
ファイル: api.lib.php プロジェクト: feroli1000/chamilo-lms
/**
 * @todo Fix tool_visible_by_default_at_creation labels
 * @todo Add sessionId parameter to avoid using context
 *
 * @param int $item_id
 * @param int $tool_id
 * @param int $group_id
 * @param array $courseInfo
 */
function api_set_default_visibility($item_id, $tool_id, $group_id = 0, $courseInfo = array())
{
    $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
    $courseId = $courseInfo['real_id'];
    $courseCode = $courseInfo['code'];
    $original_tool_id = $tool_id;
    switch ($tool_id) {
        case TOOL_LINK:
        case TOOL_LINK_CATEGORY:
            $tool_id = 'links';
            break;
        case TOOL_DOCUMENT:
            $tool_id = 'documents';
            break;
        case TOOL_LEARNPATH:
            $tool_id = 'learning';
            break;
        case TOOL_ANNOUNCEMENT:
            $tool_id = 'announcements';
            break;
        case TOOL_FORUM:
        case TOOL_FORUM_CATEGORY:
        case TOOL_FORUM_THREAD:
            $tool_id = 'forums';
            break;
        case TOOL_QUIZ:
            $tool_id = 'quiz';
            break;
    }
    $setting = api_get_setting('document.tool_visible_by_default_at_creation');
    $visibility = 'invisible';
    if (empty($group_id)) {
        $group_id = api_get_group_id();
    }
    if (isset($setting[$tool_id])) {
        if ($setting[$tool_id] == 'true') {
            $visibility = 'visible';
        }
    }
    // Read the portal and course default visibility
    if ($tool_id == 'documents') {
        $visibility = DocumentManager::getDocumentDefaultVisibility($courseCode);
    }
    api_item_property_update($courseInfo, $original_tool_id, $item_id, $visibility, api_get_user_id(), $group_id, null, null, null, api_get_session_id());
    // Fixes default visibility for tests
    switch ($original_tool_id) {
        case TOOL_QUIZ:
            $objExerciseTmp = new Exercise($courseId);
            $objExerciseTmp->read($item_id);
            if ($visibility == 'visible') {
                $objExerciseTmp->enable();
                $objExerciseTmp->save();
            } else {
                $objExerciseTmp->disable();
                $objExerciseTmp->save();
            }
            break;
    }
}
コード例 #3
0
ファイル: api.lib.php プロジェクト: ragebat/chamilo-lms
/**
 * This function sets the default visibility for any given content, using the
 * default visibility setting of the corresponding tool. For example, if we
 * create a new quiz and call this function, if the quiz tool is
 * invisible/disabled at course creation, the quiz itself will be set to
 * invisible.
 * @param array|\Entity\Course $course
 * @param int The ID of the item in its own table
 * @param string The string identifier of the tool
 * @param int The group ID, in case we want to specify it
 * @param int The integer course ID, in case we cannot get it from the context
 * @todo Fix tool_visible_by_default_at_creation labels
 */
function api_set_default_visibility($course, $item_id, $tool_id, $group_id = null)
{
    $original_tool_id = $tool_id;
    switch ($tool_id) {
        case TOOL_LINK:
            $tool_id = 'links';
            break;
        case TOOL_DOCUMENT:
            $tool_id = 'documents';
            break;
        case TOOL_LEARNPATH:
            $tool_id = 'learning';
            break;
        case TOOL_ANNOUNCEMENT:
            $tool_id = 'announcements';
            break;
        case TOOL_FORUM:
        case TOOL_FORUM_CATEGORY:
        case TOOL_FORUM_THREAD:
            $tool_id = 'forums';
            break;
        case TOOL_QUIZ:
            $tool_id = 'quiz';
            break;
    }
    $setting = api_get_setting('tool_visible_by_default_at_creation');
    if (is_array($course)) {
        $courseId = $course['real_id'];
    } else {
        if ($course instanceof Course) {
            $courseId = $course->getId();
        }
    }
    if (isset($setting[$tool_id])) {
        $visibility = 'invisible';
        if ($setting[$tool_id] == 'true') {
            $visibility = 'visible';
        }
        if (empty($group_id)) {
            $group_id = api_get_group_id();
        }
        api_item_property_update($course, $original_tool_id, $item_id, $visibility, api_get_user_id(), $group_id, null, null, null, api_get_session_id());
        // Fixes default visibility for tests
        switch ($original_tool_id) {
            case TOOL_QUIZ:
                $objExerciseTmp = new Exercise($courseId);
                $objExerciseTmp->read($item_id);
                if ($visibility == 'visible') {
                    $objExerciseTmp->enable();
                    $objExerciseTmp->save();
                } else {
                    $objExerciseTmp->disable();
                    $objExerciseTmp->save();
                }
                break;
        }
    }
}
コード例 #4
0
             remove_resource_from_course_gradebook($link_info['id']);
         }
         Display::display_confirmation_message(get_lang('ExerciseDeleted'));
     }
     break;
 case 'enable':
     // enables an exercise
     $objExerciseTmp->enable();
     $objExerciseTmp->save();
     api_item_property_update($course_info, TOOL_QUIZ, $objExerciseTmp->id, 'visible', api_get_user_id());
     // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
     Display::display_confirmation_message(get_lang('VisibilityChanged'));
     break;
 case 'disable':
     // disables an exercise
     $objExerciseTmp->disable();
     $objExerciseTmp->save();
     api_item_property_update($course_info, TOOL_QUIZ, $objExerciseTmp->id, 'invisible', api_get_user_id());
     Display::display_confirmation_message(get_lang('VisibilityChanged'));
     break;
 case 'disable_results':
     //disable the results for the learners
     $objExerciseTmp->disable_results();
     $objExerciseTmp->save();
     Display::display_confirmation_message(get_lang('ResultsDisabled'));
     break;
 case 'enable_results':
     //disable the results for the learners
     $objExerciseTmp->enable_results();
     $objExerciseTmp->save();
     Display::display_confirmation_message(get_lang('ResultsEnabled'));
コード例 #5
0
 /**
  * Function rewritten based on old_add_item() from Yannick Warnier.
  * Due the fact that users can decide where the item should come, I had to overlook this function and
  * I found it better to rewrite it. Old function is still available.
  * Added also the possibility to add a description.
  *
  * @param int $parent
  * @param int $previous
  * @param string $type
  * @param int  resource ID (ref)
  * @param string $title
  * @param string $description
  * @param int $prerequisites
  * @param int $max_time_allowed
  * @param int $userId
  *
  * @return int
  */
 public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0, $userId = 0)
 {
     $course_id = $this->course_info['real_id'];
     if ($this->debug > 0) {
         error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
     }
     if (empty($course_id)) {
         // Sometimes Oogie doesn't catch the course info but sets $this->cc
         $this->course_info = api_get_course_info($this->cc);
         $course_id = $this->course_info['real_id'];
     }
     $userId = empty($userId) ? api_get_user_id() : $userId;
     $sessionId = api_get_session_id();
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     $_course = $this->course_info;
     $parent = intval($parent);
     $previous = intval($previous);
     $id = intval($id);
     $max_time_allowed = htmlentities($max_time_allowed);
     if (empty($max_time_allowed)) {
         $max_time_allowed = 0;
     }
     $sql = "SELECT COUNT(id) AS num\n                FROM {$tbl_lp_item}\n                WHERE\n                    c_id = {$course_id} AND\n                    lp_id = " . $this->get_id() . " AND\n                    parent_item_id = " . $parent;
     $res_count = Database::query($sql);
     $row = Database::fetch_array($res_count);
     $num = $row['num'];
     if ($num > 0) {
         if ($previous == 0) {
             $sql = "SELECT id, next_item_id, display_order\n                        FROM " . $tbl_lp_item . "\n                        WHERE\n                            c_id = {$course_id} AND\n                            lp_id = " . $this->get_id() . " AND\n                            parent_item_id = " . $parent . " AND\n                            previous_item_id = 0 OR\n                            previous_item_id=" . $parent;
             $result = Database::query($sql);
             $row = Database::fetch_array($result);
             $tmp_previous = 0;
             $next = $row['id'];
             $display_order = 0;
         } else {
             $previous = (int) $previous;
             $sql = "SELECT id, previous_item_id, next_item_id, display_order\n\t\t\t\t\t\tFROM {$tbl_lp_item}\n                        WHERE\n                            c_id = {$course_id} AND\n                            lp_id = " . $this->get_id() . " AND\n                            id = " . $previous;
             $result = Database::query($sql);
             $row = Database::fetch_array($result);
             $tmp_previous = $row['id'];
             $next = $row['next_item_id'];
             $display_order = $row['display_order'];
         }
     } else {
         $tmp_previous = 0;
         $next = 0;
         $display_order = 0;
     }
     $id = intval($id);
     $typeCleaned = Database::escape_string($type);
     if ($type == 'quiz') {
         $sql = 'SELECT SUM(ponderation)
                 FROM ' . Database::get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
                 INNER JOIN  ' . Database::get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
                 ON
                     quiz_question.id = quiz_rel_question.question_id AND
                     quiz_question.c_id = quiz_rel_question.c_id
                 WHERE
                     quiz_rel_question.exercice_id = ' . $id . " AND\n                        quiz_question.c_id = {$course_id} AND\n                        quiz_rel_question.c_id = {$course_id} ";
         $rsQuiz = Database::query($sql);
         $max_score = Database::result($rsQuiz, 0, 0);
         // Disabling the exercise if we add it inside a LP
         $exercise = new Exercise($course_id);
         $exercise->read($id);
         $exercise->disable();
         $exercise->save();
     } else {
         $max_score = 100;
     }
     $params = array("c_id" => $course_id, "lp_id" => $this->get_id(), "item_type" => $typeCleaned, "ref" => '', "title" => $title, "description" => $description, "path" => $id, "max_score" => $max_score, "parent_item_id" => $parent, "previous_item_id" => $previous, "next_item_id" => intval($next), "display_order" => $display_order + 1, "prerequisite" => $prerequisites, "max_time_allowed" => $max_time_allowed, 'min_score' => 0, 'launch_data' => '');
     if ($prerequisites != 0) {
         $params['prerequisite'] = $prerequisites;
     }
     $new_item_id = Database::insert($tbl_lp_item, $params);
     if ($this->debug > 2) {
         error_log('New LP - Inserting chapter: ' . $new_item_id, 0);
     }
     if ($new_item_id) {
         $sql = "UPDATE {$tbl_lp_item} SET id = iid WHERE iid = {$new_item_id}";
         Database::query($sql);
         // Update the item that should come after the new item.
         $sql = " UPDATE {$tbl_lp_item} SET\n                        previous_item_id =  {$new_item_id},\n                        next_item_id = {$new_item_id},\n                        id = {$new_item_id}\n                     WHERE iid = {$new_item_id}";
         Database::query($sql);
         // Update all the items after the new item.
         $sql = "UPDATE " . $tbl_lp_item . "\n                        SET display_order = display_order + 1\n                    WHERE\n                        c_id = {$course_id} AND\n                        lp_id = " . $this->get_id() . " AND\n                        id <> " . $new_item_id . " AND\n                        parent_item_id = " . $parent . " AND\n                        display_order > " . $display_order;
         Database::query($sql);
         // Update the item that should come after the new item.
         $sql = "UPDATE " . $tbl_lp_item . "\n                    SET ref = " . $new_item_id . "\n                    WHERE c_id = {$course_id} AND id = " . $new_item_id;
         Database::query($sql);
         // Upload audio.
         if (!empty($_FILES['mp3']['name'])) {
             // Create the audio folder if it does not exist yet.
             $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
             if (!is_dir($filepath . 'audio')) {
                 mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
                 $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio', '', 0, true, null, $sessionId, $userId);
                 api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', $userId, null, null, null, null, $sessionId);
                 api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'invisible', $userId, null, null, null, null, $sessionId);
             }
             $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', $userId, '', '', '', '', false);
             // Getting the filename only.
             $file_components = explode('/', $file_path);
             $file = $file_components[count($file_components) - 1];
             // Store the mp3 file in the lp_item table.
             $sql = "UPDATE {$tbl_lp_item} SET\n                            audio = '" . Database::escape_string($file) . "'\n                        WHERE id = '" . intval($new_item_id) . "'";
             Database::query($sql);
         }
     }
     return $new_item_id;
 }