Get all the items IDs from course IDs.

@param array $courseids The course IDs.
@return array
973615
protected static function get_item_ids_from_course_ids($courseids) {
        global $DB;
        if (empty($courseids)) {
            return [];
        }
        list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
        return $DB->get_fieldset_select('grade_items', 'id', "courseid $insql", $inparams);
    }
817889
protected function extractIds($identities)
	{
		$ids = [];
		if (is_array($identities))
		{
			foreach ($identities as $identity)
			{
				$ids[] = $this->extractId($identity);
			}
		}
		else
		{
			$ids[] = $this->extractId($identities);
		}

		return $ids;
	}
777285
public function getIds(): array {
        $ids  = array($this->id);
        $meta = $this->getMetadata();
        foreach ($meta->allResources(RC::idProp()) as $id) {
            $ids[] = $id->getUri();
        }
        $ids = array_unique($ids);
        return $ids;
    }
824579
public static function getIdList(): array
    {
        $list = [];
        foreach (self::getAll() as $tree) {
            $list[$tree->id] = $tree->title;
        }

        return $list;
    }
687207
private function getInstancesList(array $ids)
    {
        $statuses = $instances = $classes = [];

        foreach ($ids as $key => $instance) {
            $instance = $this->getResource($instance);
            if ($instance->isClass()) {
                $instance = $this->getClass($instance);
                $classes[] = $instance;
            } elseif (!$instance->exists()) {
                $statuses[$instance->getUri()] = [
                    'success' => false,
                    'message' => sprintf('Instance "%s" does not exist', $instance->getUri()),
                ];
                break;
            }
            $instances[$key] = $instance;
        }

        return [
            $statuses,
            $instances,
            $classes
        ];
    }
1368086
protected function getIDListFromDB() : array
    {
        $arElementIDList = (array) Product::getByCategory($this->sValue)->lists('id');

        //Get product ID list for additional category relation
        $arAdditionalElementIDList = (array) DB::table('lovata_shopaholic_additional_categories')->where('category_id', $this->sValue)->lists('product_id');
        $arElementIDList = array_merge($arElementIDList, $arAdditionalElementIDList);
        $arElementIDList = array_unique($arElementIDList);

        return $arElementIDList;
    }
79194
public function get_course($courseid) {
        global $DB;
        if (!array_key_exists($courseid, $this->courses)) {
            $ctxquery = context_helper::get_preload_record_columns_sql('ctx');
            $sql = "SELECT c.id,c.visible,c.fullname,c.shortname,c.cacherev, $ctxquery
            FROM {course} c JOIN {context} ctx ON ctx.contextlevel = ? AND ctx.instanceid=c.id
            WHERE c.id = ?";
            $params = array(CONTEXT_COURSE, $courseid);
            $this->courses[$courseid] = $DB->get_record_sql($sql, $params);
            context_helper::preload_from_record($this->courses[$courseid]);
        }
        return $this->courses[$courseid];
    }
192783
public function findByIds(array $ids): array
    {
        $spec = $this->createSpecification()->where(['id' => $ids]);

        return $this->findAll($spec);
    }
456887
private function getAllChildRoleIds($parentIds)
    {
        $allChildIds = [];

        while (count($parentIds) > 0) {
            $parentIds = $this->getChildIds($parentIds);
            $allChildIds = ArrayHelper::merge($allChildIds, $parentIds);
        };

        return $allChildIds;
    }
443664
public function itemsGet($ids) {
		if ((!is_array($ids)) || (empty($ids))) {
			BLog::addToLog('[BItems.' . $this->tableName . '] itemsGet() $ids empty=' . var_export($ids, true) . ')', LL_ERROR);
			return array();
		}
		if (DEBUG_LOG_BITEMS) {
			BLog::addToLog('[BItems.' . $this->tableName . '] itemsGet(' . implode(',', $ids) . ')');
		}
		$items = array();
		//-------------------------------------------------
		//Trying to get items from internal cache
		//-------------------------------------------------
		$ids_c = array(); //IDs as integer
		$ids_k = array(); //IDs as external cache key
		foreach ($ids as $id) {
			$idd = is_array($id) ? implode(':', $id) : $id;
			if (isset($this->cacheItems[$idd])) {
				$items[$idd] = $this->cacheItems[$idd];
			} else {
				if (!empty($idd)) {
					$items[$idd] = NULL;
					$ids_c[$idd] = $id;
					$ids_k[$idd] = $this->tableName . ':itemid:' . $idd;
				}
			}
		}
		if (empty($ids_c)) {
			return $items;
		}

		//-------------------------------------------------
		//Trying to get left items from external cache
		//-------------------------------------------------
		$cache = BFactory::getCache();
		if (!empty($cache)) {
			$ids_m = array();
			$ids_q = array();
			$items_c = $cache->mget($ids_k);
			foreach ($ids_c as $id) {
				$idd = is_array($id) ? implode(':', $id) : $id;
				$key = $this->tableName . ':itemid:' . $idd;
				if ((isset($items_c[$key])) && (!empty($items_c[$key]))) {
					$classname = $this->itemClassName;
					$items[$idd] = new $classname();
					$items[$idd]->load($items_c[$key]);
					$this->cacheItems[$idd] = $items[$idd];
				} else {
					array_push($ids_m, $id);
					array_push($ids_q, $id);
				}
			}
		} else {
			$ids_m = $ids_c;
			$ids_q = $ids_c;
		}
		if (empty($ids_m)) {
			return $items;
		}
		//-------------------------------------------------
		// Trying to get left items from database
		//-------------------------------------------------
		$db = BFactory::getDBO();
		if (empty($db)) {
			return $items;
		}
		if (is_array($this->primaryKeyName)) {
			$whi = array();
			foreach ($ids_q as $id) {
				$s = array();
				foreach ($id as $idk => $idv) {
					$s[] = '(`' . $idk . '`=' . $db->escapeString($idv) . ')';
				}
				$whi[] = '(' . implode(' AND ', $s) . ')';
			}
			$wh = implode(' OR ', $whi);
			$qr = 'SELECT * from `' . $this->tableName . '` WHERE (' . $wh . ')';
		} else {
			$qr = 'SELECT * from `' . $this->tableName . '` WHERE (`' . $this->primaryKeyName . '` in (' . implode(',', $ids_q) . '))';
		}
		$q = $db->Query($qr);
		if (empty($q)) {
			BLog::addToLog('[items]: itemsGet(): Could not execute query! MySQL error: ' . $db->lasterror(), LL_ERROR);
			return $items;
		}
		$tocache = array();
		$item_obj = array();
		while ($l = $db->fetch($q)) {
			if (is_array($this->primaryKeyName)) {
				$id = array();
				foreach ($this->primaryKeyName as $pk) {
					$id[$pk] = $l[$pk];
				}
				$idd = implode(':', $id);
				$item_obj[$idd] = $l;
			} else {
				$idd = (int)$l[$this->primaryKeyName];
				$item_obj[$idd] = $l;
			}
			foreach ($this->linkedTables as $tbl) {
				$item_obj[$idd][$tbl['field']] = array();
			}
		}
		//-------------------------------------------------
		// Loading data from external tables...
		//-------------------------------------------------
		if (DEBUG_LOG_BITEMS) {
			BLog::addToLog('[BItems.' . $this->tableName . '] itemsGet() Loading data from external tables...');
		}
		foreach ($this->linkedTables as $tbl) {
			$wh = array();
			$wh[] = '(`' . $tbl['extkey'] . '` in (' . implode(',', $ids_q) . '))';
			if (!empty($tbl['filter'])) {
				$wh[] = $tbl['filter'];
			}
			$qrl = 'SELECT * from `' . $tbl['name'] . '` WHERE (' . implode(' AND ', $wh) . ')';
			$ql = $db->Query($qrl);
			if (empty($ql)) {
				BLog::addToLog('[items]: itemsGet(): Could not execute external tables query! MySQL error: ' . $db->lasterror(), LL_ERROR);
				return false;
			}
			$datal = array();
			while ($ll = $db->fetch($ql)) {
				$itemid = (int)$ll[$tbl['extkey']];
				$item_obj[$itemid][$tbl['field']][] = $ll;
			}
		}
		//-------------------------------------------------
		// Creating item object...
		//-------------------------------------------------
		if (DEBUG_LOG_BITEMS) {
			BLog::addToLog('[BItems.' . $this->tableName . '] itemsGet() Creating item objects...');
		}
		foreach ($item_obj as $k => $l) {
			$classname = $this->itemClassName;
			if (!class_exists($classname)) {
				$msg = 'Class "' . $classname . '" does not exist!';
				BLog::addToLog($msg, LL_ERROR);
				die($msg);
			}
			$items[$k] = new $classname();
			$items[$k]->load($l);
			$this->cacheItems[$k] = $items[$k];
			if (CACHE_TYPE) {
				$tocache[$this->tableName . ':itemid:' . $k] = $l;
			}
		}
		//-------------------------------------------------
		// Cache storing, if necessary.
		//-------------------------------------------------
		if ((!empty($cache)) && (count($tocache) != 0)) {
			$cache->mset($tocache, $this->cacheTime);//1 hour
		}
		if (DEBUG_LOG_BITEMS) {
			BLog::addToLog('[BItems.' . $this->tableName . '] itemsGet() All done! Returning items.');
		}
		return $items;
	}
818285
public static function fetch_course_category($courseid) {
        if (empty($courseid)) {
            debugging('Missing course id!');
            return false;
        }

        // course category has no parent
        if ($course_category = grade_category::fetch(array('courseid'=>$courseid, 'parent'=>null))) {
            return $course_category;
        }

        // create a new one
        $course_category = new grade_category();
        $course_category->insert_course_category($courseid);

        return $course_category;
    }
718637
public static function get_user_navigation_options($courseids) {
        global $CFG;
        require_once($CFG->dirroot . '/course/lib.php');

        // Parameter validation.
        $params = self::validate_parameters(self::get_user_navigation_options_parameters(), array('courseids' => $courseids));
        $courseoptions = array();

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

        if (!empty($courses)) {
            foreach ($courses as $course) {
                // Fix the context for the frontpage.
                if ($course->id == SITEID) {
                    $course->context = context_system::instance();
                }
                $navoptions = course_get_user_navigation_options($course->context, $course);
                $options = array();
                foreach ($navoptions as $name => $available) {
                    $options[] = array(
                        'name' => $name,
                        'available' => $available,
                    );
                }

                $courseoptions[] = array(
                    'id' => $course->id,
                    'options' => $options
                );
            }
        }

        $result = array(
            'courses' => $courseoptions,
            'warnings' => $warnings
        );
        return $result;
    }
395701
public static function get_user_administration_options($courseids) {
        global $CFG;
        require_once($CFG->dirroot . '/course/lib.php');

        // Parameter validation.
        $params = self::validate_parameters(self::get_user_administration_options_parameters(), array('courseids' => $courseids));
        $courseoptions = array();

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

        if (!empty($courses)) {
            foreach ($courses as $course) {
                $adminoptions = course_get_user_administration_options($course, $course->context);
                $options = array();
                foreach ($adminoptions as $name => $available) {
                    $options[] = array(
                        'name' => $name,
                        'available' => $available,
                    );
                }

                $courseoptions[] = array(
                    'id' => $course->id,
                    'options' => $options
                );
            }
        }

        $result = array(
            'courses' => $courseoptions,
            'warnings' => $warnings
        );
        return $result;
    }
862512
public static function get_course_enrolment_methods($courseid) {
        global $DB;

        $params = self::validate_parameters(self::get_course_enrolment_methods_parameters(), array('courseid' => $courseid));
        self::validate_context(context_system::instance());

        $course = $DB->get_record('course', array('id' => $params['courseid']), '*', MUST_EXIST);
        if (!core_course_category::can_view_course_info($course) && !can_access_course($course)) {
            throw new moodle_exception('coursehidden');
        }

        $result = array();
        $enrolinstances = enrol_get_instances($params['courseid'], true);
        foreach ($enrolinstances as $enrolinstance) {
            if ($enrolplugin = enrol_get_plugin($enrolinstance->enrol)) {
                if ($instanceinfo = $enrolplugin->get_enrol_info($enrolinstance)) {
                    $result[] = (array) $instanceinfo;
                }
            }
        }
        return $result;
    }
409485
public static function get_chats_by_courses($courseids = array()) {
        global $CFG;

        $returnedchats = array();
        $warnings = array();

        $params = self::validate_parameters(self::get_chats_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 chats in this course, this function checks users visibility permissions.
            // We can avoid then additional validate_context calls.
            $chats = get_all_instances_in_courses("chat", $courses);
            foreach ($chats as $chat) {
                $chatcontext = context_module::instance($chat->coursemodule);
                // Entry to return.
                $chatdetails = array();
                // First, we return information that any user can see in the web interface.
                $chatdetails['id'] = $chat->id;
                $chatdetails['coursemodule']      = $chat->coursemodule;
                $chatdetails['course']            = $chat->course;
                $chatdetails['name']              = external_format_string($chat->name, $chatcontext->id);
                // Format intro.
                list($chatdetails['intro'], $chatdetails['introformat']) =
                    external_format_text($chat->intro, $chat->introformat, $chatcontext->id, 'mod_chat', 'intro', null);
                $chatdetails['introfiles'] = external_util::get_area_files($chatcontext->id, 'mod_chat', 'intro', false, false);

                if (has_capability('mod/chat:chat', $chatcontext)) {
                    $chatdetails['chatmethod']    = $CFG->chat_method;
                    $chatdetails['keepdays']      = $chat->keepdays;
                    $chatdetails['studentlogs']   = $chat->studentlogs;
                    $chatdetails['chattime']      = $chat->chattime;
                    $chatdetails['schedule']      = $chat->schedule;
                }

                if (has_capability('moodle/course:manageactivities', $chatcontext)) {
                    $chatdetails['timemodified']  = $chat->timemodified;
                    $chatdetails['section']       = $chat->section;
                    $chatdetails['visible']       = $chat->visible;
                    $chatdetails['groupmode']     = $chat->groupmode;
                    $chatdetails['groupingid']    = $chat->groupingid;
                }
                $returnedchats[] = $chatdetails;
            }
        }
        $result = array();
        $result['chats'] = $returnedchats;
        $result['warnings'] = $warnings;
        return $result;
    }
800406
protected function getObjectIdsForNodeIds(array $nodeIds)
    {
        $objectIds = array();

        foreach ($nodeIds as $nodeId) {
            $object = eZContentObject::fetchByNodeID($nodeId);
            if ($object instanceof eZContentObject) {
                $objectIds[] = $object->attribute('id');
            }
        }

        return $objectIds;
    }
1134124
public function getSellerIds()
    {
        $sellerIds = array();

        foreach ($this->getOrders() as $order)
        {
            $sellerIds[] = $order->getSeller()->getId();
        }

        return $sellerIds;
    }