当前位置: 首页>>代码示例>>PHP>>正文


PHP CourseManager::copy_course_simple方法代码示例

本文整理汇总了PHP中CourseManager::copy_course_simple方法的典型用法代码示例。如果您正苦于以下问题:PHP CourseManager::copy_course_simple方法的具体用法?PHP CourseManager::copy_course_simple怎么用?PHP CourseManager::copy_course_simple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CourseManager的用法示例。


在下文中一共展示了CourseManager::copy_course_simple方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: copy

 /**
  * Copies a session with the same data to a new session.
  * The new copy is not assigned to the same promotion. @see suscribe_sessions_to_promotions() for that
  * @param   int     Session ID
  * @param   bool    Whether to copy the relationship with courses
  * @param   bool    Whether to copy the relationship with users
  * @param   bool    New courses will be created
  * @param   bool    Whether to set exercises and learning paths in the new session to invisible by default
  * @return  int     The new session ID on success, 0 otherwise
  * @todo make sure the extra session fields are copied too
  */
 public static function copy($id, $copy_courses = true, $copy_users = true, $create_new_courses = false, $set_exercises_lp_invisible = false)
 {
     $id = intval($id);
     $s = self::fetch($id);
     // Check all dates before copying
     // Get timestamp for now in UTC - see http://php.net/manual/es/function.time.php#117251
     $now = time() - date('Z');
     // Timestamp in one month
     $inOneMonth = $now + 30 * 24 * 3600;
     $inOneMonth = api_get_local_time($inOneMonth);
     if (api_strtotime($s['access_start_date']) < $now) {
         $s['access_start_date'] = api_get_local_time($now);
     }
     if (api_strtotime($s['display_start_date']) < $now) {
         $s['display_start_date'] = api_get_local_time($now);
     }
     if (api_strtotime($s['coach_access_start_date']) < $now) {
         $s['coach_access_start_date'] = api_get_local_time($now);
     }
     if (api_strtotime($s['access_end_date']) < $now) {
         $s['access_end_date'] = $inOneMonth;
     }
     if (api_strtotime($s['display_end_date']) < $now) {
         $s['display_end_date'] = $inOneMonth;
     }
     if (api_strtotime($s['coach_access_end_date']) < $now) {
         $s['coach_access_end_date'] = $inOneMonth;
     }
     // Now try to create the session
     $sid = self::create_session($s['name'] . ' ' . get_lang('CopyLabelSuffix'), $s['access_start_date'], $s['access_end_date'], $s['display_start_date'], $s['display_end_date'], $s['coach_access_start_date'], $s['coach_access_end_date'], (int) $s['id_coach'], $s['session_category_id'], (int) $s['visibility'], true);
     if (!is_numeric($sid) || empty($sid)) {
         return false;
     }
     if ($copy_courses) {
         // Register courses from the original session to the new session
         $courses = self::get_course_list_by_session_id($id);
         $short_courses = $new_short_courses = array();
         if (is_array($courses) && count($courses) > 0) {
             foreach ($courses as $course) {
                 $short_courses[] = $course;
             }
         }
         $courses = null;
         //We will copy the current courses of the session to new courses
         if (!empty($short_courses)) {
             if ($create_new_courses) {
                 //Just in case
                 if (function_exists('ini_set')) {
                     api_set_memory_limit('256M');
                     ini_set('max_execution_time', 0);
                 }
                 $params = array();
                 $params['skip_lp_dates'] = true;
                 foreach ($short_courses as $course_data) {
                     $course_info = CourseManager::copy_course_simple($course_data['title'] . ' ' . get_lang('CopyLabelSuffix'), $course_data['course_code'], $id, $sid, $params);
                     if ($course_info) {
                         //By default new elements are invisible
                         if ($set_exercises_lp_invisible) {
                             $list = new LearnpathList('', $course_info['code'], $sid);
                             $flat_list = $list->get_flat_list();
                             if (!empty($flat_list)) {
                                 foreach ($flat_list as $lp_id => $data) {
                                     api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0, 0, 0, 0, $sid);
                                 }
                             }
                             $quiz_table = Database::get_course_table(TABLE_QUIZ_TEST);
                             $course_id = $course_info['real_id'];
                             //@todo check this query
                             $sql = "UPDATE {$quiz_table} SET active = 0 WHERE c_id = {$course_id} AND session_id = {$sid}";
                             $result = Database::query($sql);
                         }
                         $new_short_courses[] = $course_info['real_id'];
                     }
                 }
             } else {
                 foreach ($short_courses as $course_data) {
                     $new_short_courses[] = $course_data['id'];
                 }
             }
             $short_courses = $new_short_courses;
             self::add_courses_to_session($sid, $short_courses, true);
             $short_courses = null;
         }
     }
     if ($copy_users) {
         // Register users from the original session to the new session
         $users = self::get_users_by_session($id);
         $short_users = array();
         if (is_array($users) && count($users) > 0) {
//.........这里部分代码省略.........
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:101,代码来源:sessionmanager.lib.php

示例2: copy_session

 /**
  * @param $id
  * @param $copy_courses
  * @param $copy_users
  * @param $create_new_courses
  * @param $set_exercises_lp_invisible
  * @return int
  */
 public static function copy_session($id, $copy_courses = true, $copy_users = true, $create_new_courses = false, $set_exercises_lp_invisible = false)
 {
     $id = intval($id);
     $params = self::fetch($id);
     $params['name'] = $params['name'] . ' ' . get_lang('CopyLabelSuffix');
     $sid = self::add($params);
     if (!is_numeric($sid) || empty($sid)) {
         return false;
     }
     if ($copy_courses) {
         // Register courses from the original session to the new session
         $courses = self::get_course_list_by_session_id($id);
         $short_courses = $new_short_courses = array();
         if (is_array($courses) && count($courses) > 0) {
             foreach ($courses as $course) {
                 $short_courses[] = $course;
             }
         }
         $courses = null;
         //We will copy the current courses of the session to new courses
         if (!empty($short_courses)) {
             if ($create_new_courses) {
                 //Just in case
                 if (function_exists('ini_set')) {
                     api_set_memory_limit('256M');
                     ini_set('max_execution_time', 0);
                 }
                 $params = array();
                 $params['skip_lp_dates'] = true;
                 foreach ($short_courses as $course_data) {
                     $course_info = CourseManager::copy_course_simple($course_data['title'] . ' ' . get_lang('CopyLabelSuffix'), $course_data['course_code'], $id, $sid, $params);
                     if ($course_info) {
                         //By default new elements are invisible
                         if ($set_exercises_lp_invisible) {
                             $list = new LearnpathList('', $course_info['code'], $sid);
                             $flat_list = $list->get_flat_list();
                             if (!empty($flat_list)) {
                                 foreach ($flat_list as $lp_id => $data) {
                                     api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0, 0, 0, 0, $sid);
                                     api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0, 0, 0, 0);
                                 }
                             }
                             $quiz_table = Database::get_course_table(TABLE_QUIZ_TEST);
                             $course_id = $course_info['real_id'];
                             //@todo check this query
                             //Disabling quiz items
                             $sql = "UPDATE {$quiz_table} SET active = 0 WHERE c_id = {$course_id} ";
                             Database::query($sql);
                         }
                         $new_short_courses[] = $course_info['code'];
                     }
                 }
             } else {
                 foreach ($short_courses as $course_data) {
                     $new_short_courses[] = $course_data['id'];
                 }
             }
             $short_courses = $new_short_courses;
             $res = self::add_courses_to_session($sid, $short_courses, true);
             $short_courses = null;
         }
     }
     if ($copy_users) {
         // Register users from the original session to the new session
         $users = self::get_users_by_session($id);
         $short_users = array();
         if (is_array($users) && count($users) > 0) {
             foreach ($users as $user) {
                 $short_users[] = $user['user_id'];
             }
         }
         $users = null;
         //Subscribing in read only mode
         $res = self::suscribe_users_to_session($sid, $short_users, SESSION_VISIBLE_READ_ONLY, true, false);
         $short_users = null;
     }
     return $sid;
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:86,代码来源:sessionmanager.lib.php

示例3: copy_session

    /**
     * Copies a session with the same data to a new session.
     * The new copy is not assigned to the same promotion. @see suscribe_sessions_to_promotions() for that
     * @param   int     Session ID
     * @param   bool    Whether to copy the relationship with courses
     * @param   bool    Whether to copy the relationship with users
     * @param	bool	New courses will be created
     * @return  int     The new session ID on success, 0 otherwise
     * @todo make sure the extra session fields are copied too
     */
    public static function copy_session($id, $copy_courses = true, $copy_users = true, $create_new_courses = false, $set_exercises_lp_invisible = false)
    {
        $id = intval($id);
        $s = self::fetch($id);
        $s['year_start'] = substr($s['date_start'], 0, 4);
        $s['month_start'] = substr($s['date_start'], 5, 2);
        $s['day_start'] = substr($s['date_start'], 8, 2);
        $s['year_end'] = substr($s['date_end'], 0, 4);
        $s['month_end'] = substr($s['date_end'], 5, 2);
        $s['day_end'] = substr($s['date_end'], 8, 2);
        $consider_start = true;
        if ($s['year_start'] . '-' . $s['month_start'] . '-' . $s['day_start'] == '0000-00-00') {
            $consider_start = false;
        }
        $consider_end = true;
        if ($s['year_end'] . '-' . $s['month_end'] . '-' . $s['day_end'] == '0000-00-00') {
            $consider_end = false;
        }

        $sid = self::create_session(
            $s['name'] . ' ' . get_lang('CopyLabelSuffix'),
            $s['year_start'],
            $s['month_start'],
            $s['day_start'],
            $s['year_end'],
            $s['month_end'],
            $s['day_end'],
            $s['nb_days_acess_before_beginning'],
            $s['nb_days_acess_after_end'],
            false,
            (int)$s['id_coach'],
            $s['session_category_id'],
            (int)$s['visibility'],
            $consider_start,
            $consider_end,
            true
        );

        if (!is_numeric($sid) || empty($sid)) {
            return false;
        }

        if ($copy_courses) {
            // Register courses from the original session to the new session
            $courses = self::get_course_list_by_session_id($id);

            $short_courses = $new_short_courses = array();
            if (is_array($courses) && count($courses) > 0) {
                foreach ($courses as $course) {
                    $short_courses[] = $course;
                }
            }

            $courses = null;

            //We will copy the current courses of the session to new courses
            if (!empty($short_courses)) {
                if ($create_new_courses) {
                    //Just in case
                    if (function_exists('ini_set')) {
                        api_set_memory_limit('256M');
                        ini_set('max_execution_time', 0);
                    }
                    $params = array();
                    $params['skip_lp_dates'] = true;

                    foreach ($short_courses as $course_data) {
                        $course_info = CourseManager::copy_course_simple($course_data['title'] . ' ' . get_lang('CopyLabelSuffix'), $course_data['course_code'], $id, $sid, $params);
                        if ($course_info) {
                            //By default new elements are invisible
                            if ($set_exercises_lp_invisible) {
                                require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathList.class.php';
                                $list = new LearnpathList('', $course_info['code'], $sid);
                                $flat_list = $list->get_flat_list();
                                if (!empty($flat_list)) {
                                    foreach ($flat_list as $lp_id => $data) {
                                        api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0, 0, 0, 0, $sid);
                                        api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0, 0, 0, 0);
                                    }
                                }
                                $quiz_table = Database::get_course_table(TABLE_QUIZ_TEST);
                                $course_id = $course_info['real_id'];
                                //@todo check this query
                                $sql = "UPDATE $quiz_table SET active = 0 WHERE c_id = $course_id ";
                                $result = Database::query($sql);
                            }
                            $new_short_courses[] = $course_info['code'];
                        }
                    }
                } else {
//.........这里部分代码省略.........
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:101,代码来源:sessionmanager.lib.php


注:本文中的CourseManager::copy_course_simple方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。