Check if module exists

@param string $moduleName
@param bool $returnId
@return bool
322358
public function moduleExists($moduleName, $returnId = false)
    {
        $module = $this->findOrFalse('module_name', $moduleName);
        if ($module)
        {
            if ($returnId)
                return $module->module_id;
            else
                return true;
        }

        return false;
    }
1203465
protected static function firstMatchingModule($module_names, $target) {
		foreach ($module_names as $module) {
			if (stripos($module, $target) !== false) {
				return $module;
			}
		}
	}
948638
public static function hasName( $name, $module_id = null ): bool
	{
		if( !self::isValidName($name) )
		{
			return false;
		}

		$builder = \DB::table("events")->where("name", $name);
		if( is_numeric($module_id) )
		{
			$builder->where("module_id", (int) $module_id );
		}

		return $builder->count(["id"]) > 0;
	}
350974
public function findByModule(ModuleInterface $module = null, array $orderBy = null, $limit = null, $offset = null)
    {
        $criteria = [];

        if ($this->isModular($module)) {
            $criteria['module'] = $module;
        }

        /** @var EntityRepository $this */
        return $this->findBy($criteria, $orderBy, $limit, $offset);
    }
1227216
public function get_module( $name ) {
		if ( null === $name ) {
			return false;
		}
		if ( isset( $this->modules[ $name ] ) ) {
			return $this->modules[ $name ];
		}
		$name = "\\{$name}";
		if ( isset( $this->modules[ $name ] ) ) {
			return $this->modules[ $name ];
		}

		return false;
	}
1018282
public static function systemFeatureExists(string $feature_code, $module_id = null) : bool {
		if (!isset($module_id)) {
			$module_id = \Application::$controller->module_id;
		}
		$temp = explode('::', $feature_code);
		$result = \Object\Controller::getSystemModuleByModuleCode($temp[0]);
		if (isset($result['module_ids'][$module_id]['features'])) {
			return in_array($feature_code, $result['module_ids'][$module_id]['features']);
		}
		if (empty($result['module_multiple'])) {
			return in_array($feature_code, $result['all_features']);
		}
		return false;
	}
986546
public static function exists($view, $return_path = false)
	{
		if (starts_with($view, 'name: ') and array_key_exists($name = substr($view, 6), static::$names))
		{
			$view = static::$names[$name];
		}
		
		list($bundle, $view) = Bundle::parse($view);

		$view = str_replace('.', '/', $view);

		// We delegate the determination of view paths to the view loader event
		// so that the developer is free to override and manage the loading
		// of views in any way they see fit for their application.
		$path = Event::until(static::loader, array($bundle, $view));

		if ( ! is_null($path))
		{
			return $return_path ? $path : true;
		}

		return false;
	}
925565
protected function removeModuleDirectory($moduleName)
    {
        $this->files->deleteDirectory($this->getModuleDirectory($moduleName));
        if($this->files->exists($this->getModuleDirectory($moduleName)))
        {
            $this->errors->add('delete_files', 'Unable to delete '.$this->getModuleDirectory($moduleName));
            return false;
        }
        return true;
    }
980623
public static function get_module($id, $sectionreturn = null) {
        global $PAGE;
        // Validate and normalize parameters.
        $params = self::validate_parameters(self::get_module_parameters(),
            array('id' => $id, 'sectionreturn' => $sectionreturn));
        $id = $params['id'];
        $sectionreturn = $params['sectionreturn'];

        // Set of permissions an editing user may have.
        $contextarray = [
            'moodle/course:update',
            'moodle/course:manageactivities',
            'moodle/course:activityvisibility',
            'moodle/course:sectionvisibility',
            'moodle/course:movesections',
            'moodle/course:setcurrentsection',
        ];
        $PAGE->set_other_editing_capability($contextarray);

        // Validate access to the course (note, this is html for the course view page, we don't validate access to the module).
        list($course, $cm) = get_course_and_cm_from_cmid($id);
        self::validate_context(context_course::instance($course->id));

        $courserenderer = $PAGE->get_renderer('core', 'course');
        $completioninfo = new completion_info($course);
        return $courserenderer->course_section_cm_list_item($course, $completioninfo, $cm, $sectionreturn);
    }
1184868
public function enable($module_id)
    {
        try {
            $result = $this->canEnable($module_id);
        } catch (Exception $ex) {
            $result = $ex->getMessage();
        }

        $this->hook->attach("module.enable.before|$module_id", $result, $this);

        if ($result !== true) {
            return $result;
        }

        $this->module->update($module_id, array('status' => 1));
        $this->setOverrideConfig();

        $this->hook->attach("module.enable.after|$module_id", $result, $this);
        return $result;
    }
30431
private function getPathDFS($moduleName, $dependency, &$reversePath = array())
    {
        // does not exist in the graph
        if (!isset($this->dependencies[$moduleName])) {
            return false;
        }

        $reversePath[] = $moduleName;

        // adjacent node
        if (isset($this->dependencies[$moduleName][$dependency])) {
            $reversePath[] = $dependency;

            return true;
        }

        // DFS
        foreach ($this->dependencies[$moduleName] as $predecessor => $_) {
            if ($this->getPathDFS($predecessor, $dependency, $reversePath)) {
                return true;
            }
        }

        return false;
    }
219728
public function find($id, $returnType = Table::RETURN_MODEL) {
        return $this->findBy($this->getPrimaryKey(), $id, $returnType);
    }
336253
public static function getModuleUidByClassname($moduleClassName, $moduleContainer = null)
    {
        if ($moduleContainer == null) {
            $moduleContainer = Yii::$app; // start from ancestor-container
        }
        if ($moduleContainer instanceof YiiBaseModule) {
             if ($moduleContainer::className() == $moduleClassName) {
                 return $moduleContainer->uniqueId;
             }
             $subModules = $moduleContainer->getModules($loadedOnly = false);
             foreach ($subModules as $subModule) {
                 $uid = static::getModuleUidByClassname($moduleClassName, $subModule);
                 if ($uid) return $uid;
             }
        }
        return false;
    }
371048
public static function loadModule($moduleName) {
        $moduleConf = self::getModuleConf($moduleName);

        try {

            if (isset($moduleConf['requires_php_extension']) && is_array($moduleConf['requires_php_extension'])) {
                self::checkPhpExtensions($moduleConf['requires_php_extension']);
            }

            $tmpModule = new \ReflectionClass('\\pff\\modules\\' . $moduleConf['class']);
            if ($tmpModule->isSubclassOf('\\pff\\Abs\\AModule')) {
                $moduleName = strtolower($moduleConf['name']);

                if (isset(self::$_modules[$moduleName])) { //Module has already been loaded
                    return self::$_modules[$moduleName];
                }

                self::$_modules[$moduleName] = $tmpModule->newInstance();
                self::$_modules[$moduleName]->setModuleName($moduleConf['name']);
                self::$_modules[$moduleName]->setModuleVersion($moduleConf['version']);
                self::$_modules[$moduleName]->setModuleDescription($moduleConf['desc']);
                self::$_modules[$moduleName]->setConfig(ServiceContainer::get('config'));
                self::$_modules[$moduleName]->setApp(ServiceContainer::get('app'));
                (isset($moduleConf['runBefore']))? $moduleLoadBefore = $moduleConf['runBefore']: $moduleLoadBefore = null ;

                if (isset ($moduleConf['requires']) && is_array($moduleConf['requires'])) {
                    self::$_modules[$moduleName]->setModuleRequirements($moduleConf['requires']);
                    foreach ($moduleConf['requires'] as $requiredModuleName) {
                        self::loadModule($requiredModuleName);
                        self::$_modules[$moduleName]->registerRequiredModule(self::$_modules[$requiredModuleName]);
                    }
                }

                if ($tmpModule->isSubclassOf('\pff\Iface\IHookProvider')) {
                    ServiceContainer::get('hookmanager')->registerHook(self::$_modules[$moduleName], $moduleName, $moduleLoadBefore);
                }

                return self::$_modules[$moduleName];

            } else {
                throw new ModuleException("Invalid module: " . $moduleConf['name']);
            }
        }
        catch (\ReflectionException $e) {
            throw new ModuleException("Unable to create module instance: " . $e->getMessage());
        }

    }
937787
public function unregisterAdapter($moduleId)
    {

        $registry = $this->getRegistry();
        $config = [];
        if ($registry->isRegistered(self::REGISTRY_ENTRY_KEY)) {
            $config = $registry->get(self::REGISTRY_ENTRY_KEY);
        }

        if (isset($config[self::PREVIEWERS_KEY]) && isset($config[self::PREVIEWERS_KEY][$moduleId])) {
            unset($config[self::PREVIEWERS_KEY][$moduleId]);
            $registry->set(self::REGISTRY_ENTRY_KEY, $config);
            return true;
        }
        return false;
    }
262510
public function findModuleByName(string $moduleName, PathTransfer $pathTransfer): ModuleTransfer
    {
        $moduleTransfer = $this->createModuleTransfer();
        $moduleTransfer->setModuleName($moduleName);

        $coreModulePath = $this->getCoreModulePath($moduleName, $pathTransfer);
        $projectModulePath = $this->getProjectModulePath($moduleName, $pathTransfer);

        $modulePaths = array_filter([
            $coreModulePath,
            $projectModulePath,
        ]);

        if ($modulePaths === []) {
            return $moduleTransfer;
        }

        $schemas = $this->getModuleSchemaPaths($modulePaths);

        $moduleTransfer->setModulePaths($modulePaths);
        $moduleTransfer->setSchemaPaths($schemas);

        return $moduleTransfer;
    }
1338421
public static function exist($name)
    {
        $name = ucfirst($name);

        /*
         * If it was checked before negatively - direct return.
         */
        if (in_array($name, self::$_unavailableModules)) {
            return false;
        }

        /*
         * Check if it was already loaded.
         */
        if (isset(self::$_loadedModules[$name])) {
            return true;
        }

        /*
         * Or the file exists.
         */
        if (file_exists(self::getModulePath().$name.'.php')) {
            return true;
        } else {
            self::$_unavailableModules[] = $name;
        }

        /*
         * Module does not exist.
         */

        return false;
    }