public static function get_imscps_by_courses($courseids = array()) {
        global $CFG;

        $returnedimscps = array();
        $warnings = array();

        $params = self::validate_parameters(self::get_imscps_by_courses_parameters(), array('courseids' => $courseids));

        $courses = array();
        if (empty($params['courseids'])) {
            $courses = enrol_get_my_courses();
            $params['courseids'] = array_keys($courses);
        }

        // Ensure there are courseids to loop through.
        if (!empty($params['courseids'])) {

            list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);

            // Get the imscps in this course, this function checks users visibility permissions.
            // We can avoid then additional validate_context calls.
            $imscps = get_all_instances_in_courses("imscp", $courses);
            foreach ($imscps as $imscp) {
                $context = context_module::instance($imscp->coursemodule);

                // Entry to return.
                $imscpdetails = array();
                // First, we return information that any user can see in the web interface.
                $imscpdetails['id'] = $imscp->id;
                $imscpdetails['coursemodule']      = $imscp->coursemodule;
                $imscpdetails['course']            = $imscp->course;
                $imscpdetails['name']              = external_format_string($imscp->name, $context->id);

                if (has_capability('mod/imscp:view', $context)) {
                    // Format intro.
                    list($imscpdetails['intro'], $imscpdetails['introformat']) =
                        external_format_text($imscp->intro, $imscp->introformat, $context->id, 'mod_imscp', 'intro', null);
                    $imscpdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_imscp', 'intro', false, false);
                }

                if (has_capability('moodle/course:manageactivities', $context)) {
                    $imscpdetails['revision']      = $imscp->revision;
                    $imscpdetails['keepold']       = $imscp->keepold;
                    $imscpdetails['structure']     = $imscp->structure;
                    $imscpdetails['timemodified']  = $imscp->timemodified;
                    $imscpdetails['section']       = $imscp->section;
                    $imscpdetails['visible']       = $imscp->visible;
                    $imscpdetails['groupmode']     = $imscp->groupmode;
                    $imscpdetails['groupingid']    = $imscp->groupingid;
                }
                $returnedimscps[] = $imscpdetails;
            }
        }
        $result = array();
        $result['imscps'] = $returnedimscps;
        $result['warnings'] = $warnings;
        return $result;
    }
public static function get_imscps_by_courses($courseids = array()) {
        global $CFG;

        $returnedimscps = array();
        $warnings = array();

        $params = self::validate_parameters(self::get_imscps_by_courses_parameters(), array('courseids' => $courseids));

        $courses = array();
        if (empty($params['courseids'])) {
            $courses = enrol_get_my_courses();
            $params['courseids'] = array_keys($courses);
        }

        // Ensure there are courseids to loop through.
        if (!empty($params['courseids'])) {

            list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);

            // Get the imscps in this course, this function checks users visibility permissions.
            // We can avoid then additional validate_context calls.
            $imscps = get_all_instances_in_courses("imscp", $courses);
            foreach ($imscps as $imscp) {
                $context = context_module::instance($imscp->coursemodule);

                // Entry to return.
                $imscpdetails = array();
                // First, we return information that any user can see in the web interface.
                $imscpdetails['id'] = $imscp->id;
                $imscpdetails['coursemodule']      = $imscp->coursemodule;
                $imscpdetails['course']            = $imscp->course;
                $imscpdetails['name']              = external_format_string($imscp->name, $context->id);

                if (has_capability('mod/imscp:view', $context)) {
                    // Format intro.
                    list($imscpdetails['intro'], $imscpdetails['introformat']) =
                        external_format_text($imscp->intro, $imscp->introformat, $context->id, 'mod_imscp', 'intro', null);
                    $imscpdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_imscp', 'intro', false, false);
                }

                if (has_capability('moodle/course:manageactivities', $context)) {
                    $imscpdetails['revision']      = $imscp->revision;
                    $imscpdetails['keepold']       = $imscp->keepold;
                    $imscpdetails['structure']     = $imscp->structure;
                    $imscpdetails['timemodified']  = $imscp->timemodified;
                    $imscpdetails['section']       = $imscp->section;
                    $imscpdetails['visible']       = $imscp->visible;
                    $imscpdetails['groupmode']     = $imscp->groupmode;
                    $imscpdetails['groupingid']    = $imscp->groupingid;
                }
                $returnedimscps[] = $imscpdetails;
            }
        }
        $result = array();
        $result['imscps'] = $returnedimscps;
        $result['warnings'] = $warnings;
        return $result;
    }
public static function get_imscps_by_courses ( $ courseids = array ( ) ) { global $ CFG ; $ returnedimscps = array ( ) ; $ warnings = array ( ) ; $ params = self :: validate_parameters ( self :: get_imscps_by_courses_parameters ( ) , array ( 'courseids' => $ courseids ) ) ; $ courses = array ( ) ; if ( empty ( $ params [ 'courseids' ] ) ) { $ courses = enrol_get_my_courses ( ) ; $ params [ 'courseids' ] = array_keys ( $ courses ) ; } // Ensure there are courseids to loop through. if ( ! empty ( $ params [ 'courseids' ] ) ) { list ( $ courses , $ warnings ) = external_util :: validate_courses ( $ params [ 'courseids' ] , $ courses ) ; // Get the imscps in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $ imscps = get_all_instances_in_courses ( "imscp" , $ courses ) ; foreach ( $ imscps as $ imscp ) { $ context = context_module :: instance ( $ imscp -> coursemodule ) ; // Entry to return. $ imscpdetails = array ( ) ; // First, we return information that any user can see in the web interface. $ imscpdetails [ 'id' ] = $ imscp -> id ; $ imscpdetails [ 'coursemodule' ] = $ imscp -> coursemodule ; $ imscpdetails [ 'course' ] = $ imscp -> course ; $ imscpdetails [ 'name' ] = external_format_string ( $ imscp -> name , $ context -> id ) ; if ( has_capability ( 'mod/imscp:view' , $ context ) ) { // Format intro. list ( $ imscpdetails [ 'intro' ] , $ imscpdetails [ 'introformat' ] ) = external_format_text ( $ imscp -> intro , $ imscp -> introformat , $ context -> id , 'mod_imscp' , 'intro' , null ) ; $ imscpdetails [ 'introfiles' ] = external_util :: get_area_files ( $ context -> id , 'mod_imscp' , 'intro' , false , false ) ; } if ( has_capability ( 'moodle/course:manageactivities' , $ context ) ) { $ imscpdetails [ 'revision' ] = $ imscp -> revision ; $ imscpdetails [ 'keepold' ] = $ imscp -> keepold ; $ imscpdetails [ 'structure' ] = $ imscp -> structure ; $ imscpdetails [ 'timemodified' ] = $ imscp -> timemodified ; $ imscpdetails [ 'section' ] = $ imscp -> section ; $ imscpdetails [ 'visible' ] = $ imscp -> visible ; $ imscpdetails [ 'groupmode' ] = $ imscp -> groupmode ; $ imscpdetails [ 'groupingid' ] = $ imscp -> groupingid ; } $ returnedimscps [ ] = $ imscpdetails ; } } $ result = array ( ) ; $ result [ 'imscps' ] = $ returnedimscps ; $ result [ 'warnings' ] = $ warnings ; return $ result ; }
Returns a list of IMSCP packages in a provided list of courses,
if no list is provided all IMSCP packages that the user can view will be returned.

@param array $courseids the course ids
@return array of IMSCP packages details and possible warnings
@since Moodle 3.0
Returns a list of IMSCP packages in a provided list of courses if no list is provided all IMSCP packages that the user can view will be returned .