Display a repository instance list (with edit/delete/create links)

@static
@param stdClass $context the context for which we display the instance
@param string $typename if set, we display only one type of instance
323467
public static function display_instances_list($context, $typename = null) {
        global $CFG, $USER, $OUTPUT;

        $output = $OUTPUT->box_start('generalbox');
        //if the context is SYSTEM, so we call it from administration page
        $admin = ($context->id == SYSCONTEXTID) ? true : false;
        if ($admin) {
            $baseurl = new moodle_url('/'.$CFG->admin.'/repositoryinstance.php', array('sesskey'=>sesskey()));
            $output .= $OUTPUT->heading(get_string('siteinstances', 'repository'));
        } else {
            $baseurl = new moodle_url('/repository/manage_instances.php', array('contextid'=>$context->id, 'sesskey'=>sesskey()));
        }

        $namestr = get_string('name');
        $pluginstr = get_string('plugin', 'repository');
        $settingsstr = get_string('settings');
        $deletestr = get_string('delete');
        // Retrieve list of instances. In administration context we want to display all
        // instances of a type, even if this type is not visible. In course/user context we
        // want to display only visible instances, but for every type types. The repository::get_instances()
        // third parameter displays only visible type.
        $params = array();
        $params['context'] = array($context);
        $params['currentcontext'] = $context;
        $params['return_types'] = 0;
        $params['onlyvisible'] = !$admin;
        $params['type']        = $typename;
        $instances = repository::get_instances($params);
        $instancesnumber = count($instances);
        $alreadyplugins = array();

        $table = new html_table();
        $table->head = array($namestr, $pluginstr, $settingsstr, $deletestr);
        $table->align = array('left', 'left', 'center','center');
        $table->data = array();

        $updowncount = 1;

        foreach ($instances as $i) {
            $settings = '';
            $delete = '';

            $type = repository::get_type_by_id($i->options['typeid']);

            if ($type->get_contextvisibility($context)) {
                if (!$i->readonly) {

                    $settingurl = new moodle_url($baseurl);
                    $settingurl->param('type', $i->options['type']);
                    $settingurl->param('edit', $i->id);
                    $settings .= html_writer::link($settingurl, $settingsstr);

                    $deleteurl = new moodle_url($baseurl);
                    $deleteurl->param('delete', $i->id);
                    $deleteurl->param('type', $i->options['type']);
                    $delete .= html_writer::link($deleteurl, $deletestr);
                }
            }

            $type = repository::get_type_by_id($i->options['typeid']);
            $table->data[] = array(format_string($i->name), $type->get_readablename(), $settings, $delete);

            //display a grey row if the type is defined as not visible
            if (isset($type) && !$type->get_visible()) {
                $table->rowclasses[] = 'dimmed_text';
            } else {
                $table->rowclasses[] = '';
            }

            if (!in_array($i->name, $alreadyplugins)) {
                $alreadyplugins[] = $i->name;
            }
        }
        $output .= html_writer::table($table);
        $instancehtml = '<div>';
        $addable = 0;

        //if no type is set, we can create all type of instance
        if (!$typename) {
            $instancehtml .= '<h3>';
            $instancehtml .= get_string('createrepository', 'repository');
            $instancehtml .= '</h3><ul>';
            $types = repository::get_editable_types($context);
            foreach ($types as $type) {
                if (!empty($type) && $type->get_visible()) {
                    // If the user does not have the permission to view the repository, it won't be displayed in
                    // the list of instances. Hiding the link to create new instances will prevent the
                    // user from creating them without being able to find them afterwards, which looks like a bug.
                    if (!has_capability('repository/'.$type->get_typename().':view', $context)) {
                        continue;
                    }
                    $instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names');
                    if (!empty($instanceoptionnames)) {
                        $baseurl->param('new', $type->get_typename());
                        $instancehtml .= '<li><a href="'.$baseurl->out().'">'.get_string('createxxinstance', 'repository', get_string('pluginname', 'repository_'.$type->get_typename())).  '</a></li>';
                        $baseurl->remove_params('new');
                        $addable++;
                    }
                }
            }
            $instancehtml .= '</ul>';

        } else {
            $instanceoptionnames = repository::static_function($typename, 'get_instance_option_names');
            if (!empty($instanceoptionnames)) {   //create a unique type of instance
                $addable = 1;
                $baseurl->param('new', $typename);
                $output .= $OUTPUT->single_button($baseurl, get_string('createinstance', 'repository'), 'get');
                $baseurl->remove_params('new');
            }
        }

        if ($addable) {
            $instancehtml .= '</div>';
            $output .= $instancehtml;
        }

        $output .= $OUTPUT->box_end();

        //print the list + creation links
        print($output);
    }
1097919
protected function _actionBrowse(AnCommandContext $context)
    {
        $entities = parent::_actionBrowse($context);

        if ($this->type) {
            $entities->where('folder', '=', $this->type);
        }

        $entities->order($this->sort);

        return $entities;
    }
879769
protected function _beforeRepositoryFetch(AnCommandContext $context)
    {
        if (!get_viewer()->admin()) {
            $query = $context->query;
            $query->where('IF(@col(enabled)=FALSE,0,1)');
        }
    }
47316
protected function deleteTypeNameData($typeId, $typeStatus)
    {
        $query = $this->dbHandler->createDeleteQuery();
        $query->deleteFrom('ezcontentclass_name')
            ->where(
                $query->expr->lAnd(
                    $query->expr->eq(
                        $this->dbHandler->quoteColumn('contentclass_id'),
                        $query->bindValue($typeId, null, \PDO::PARAM_INT)
                    ),
                    $query->expr->eq(
                        $this->dbHandler->quoteColumn('contentclass_version'),
                        $query->bindValue($typeStatus, null, \PDO::PARAM_INT)
                    )
                )
            );
        $query->prepare()->execute();
    }
746399
public static function exists($typeName)
    {
        $db = static::getDb();

        return $db->createCommand(
            'SELECT EXISTS ('
            . 'SELECT 1 '
                . 'FROM ' . $db->quoteTableName('pg_type')
                . ' WHERE typname = ' . $db->quoteValue($typeName)
            . ')'
        )->queryScalar();
    }
728445
protected function initializeProxy($typeName, callable $factory = NULL)
	{
		$proxyName = $this->container->loadScopedProxy($typeName);
		
		if($factory === NULL)
		{
			$factory = function() {
				throw new ScopeNotActiveException(sprintf('Scope "%s" is not active', $this->getScope()));
			};
		}
		
		return new $proxyName(new DelegateBinding($typeName, $this->getScope(), 0, $factory), $this, $this->proxies);
	}
785687
public static function autoload(string $typeName): bool
    {
        static $enabled;
        
        if (\defined('KOOLKODE_ASYNC_OPTIMIZATIONS')) {
            if ($enabled === null) {
                $enabled = \array_map('trim', \explode(',', \strtolower(\KOOLKODE_ASYNC_OPTIMIZATIONS)));
            }
            
            if (isset(self::$replacements[$typeName])) {
                foreach ($enabled as $key) {
                    if (isset(self::$replacements[$typeName][$key])) {
                        return \class_alias(self::$replacements[$typeName][$key], $typeName, true);
                    }
                }
            }
        }
        
        return false;
    }
778646
public function initializeContext(Context $context)
    {
        if (false === $context instanceof AliceContextInterface) {
            return;
        }

        /* @var AliceContextInterface $context */
        $fixturesBasePath = $this->fixturesBasePath;
        switch (true) {

            case $context instanceof AliceODMContext:
                $fixturesBasePath .= '/ODM';
                break;

            case $context instanceof AliceORMContext:
                $fixturesBasePath .= '/ORM';
                break;

            case $context instanceof AlicePHPCRContext:
                $fixturesBasePath .= '/PHPCR';
                break;
        }

        if (null === $context->getBasePath()) {
            $context->setBasePath($fixturesBasePath);
        }
    }
732689
private function _checkTypeNameFileNameMatch($typeName) {
		/* currentFilename holds file path - get basename */
		$fileBaseName = basename($this->_currentFilename);
		/*
		 * quick n dirty - append '.' to type name to ensure that we don't miss something like Foo1.php and Foo
		 */
		if ($this->_isActive('typeNameMatchesFileName') && !(substr($fileBaseName, 0, strlen($typeName) + 1) === $typeName . ".")) {
			$msg = $this->_getMessage('TYPE_FILE_NAME_MISMATCH', $typeName, $fileBaseName);
			$this->_writeError('typeNameMatchesFileName', $msg);
		}
	}
123464
public static function delete_data_for_user(approved_contextlist $contextlist) {
        global $DB;

        // If the user has repository_instances data, then only the User context should be present so get the first context.
        $contexts = $contextlist->get_contexts();
        if (count($contexts) == 0) {
            return;
        }
        $context = reset($contexts);

        // Sanity check that context is at the User context level, then get the userid.
        if ($context->contextlevel !== CONTEXT_USER) {
            return;
        }
        $userid = $context->instanceid;

        // Delete the repository_instances records created for the userid.
        $DB->delete_records('repository_instances', ['userid' => $userid]);
    }
826473
protected function typeToClassName($typeName)
    {
        $classBase = Type::studlyCaps($typeName).'Type';

        $class = __NAMESPACE__."\\$classBase";

        if (class_exists($class)) {
            return $class;
        }

        $class = __NAMESPACE__."\UnitTypes\\$classBase";

        if (class_exists($class)) {
            return $class;
        }

        throw new ResourceNotFoundException("XType class for $typeName not found");
    }
1143888
public function buildTypoScriptRenderingConfiguration(string $extensionName, string $pluginName, string $contextRecordId): array
    {
        $configurationBuilder = new RecordRenderingConfigurationBuilder(new RenderingContext($GLOBALS['TSFE']));

        return $configurationBuilder->configurationFor($extensionName, $pluginName, $contextRecordId);
    }
987091
public function setDefaultRepositoryClassName($className)
    {
        $reflectionClass = new \ReflectionClass($className);

        if (!$reflectionClass->implementsInterface(ObjectRepository::class)) {
            throw PHPCRException::invalidDocumentRepository($className);
        }

        $this->attributes['defaultRepositoryClassName'] = $className;
    }
684847
protected function _addClassAttributes($typename, DOMElement $typexml)
    {
        // Do not try to autoload here because _phpTypeToAS should
        // have already attempted to load this class
        if (!class_exists($typename, false)) {
            return;
        }

        $rc = new Zend_Reflection_Class($typename);
        foreach ($rc->getProperties() as $prop) {
            if (!$prop->isPublic()) {
                continue;
            }

            $propxml = $this->_xml->createElement('property');
            $propxml->setAttribute('name', $prop->getName());

            $type = $this->_registerType($this->_getPropertyType($prop));
            $propxml->setAttribute('type', $type);

            $typexml->appendChild($propxml);
        }
    }
685426
public function deleteType($repositoryId, $typeId, ExtensionDataInterface $extension = null)
    {
        $url = $this->getRepositoryUrl($repositoryId);

        $url->getQuery()->modify(
            [
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE_TYPE,
                Constants::CONTROL_TYPE_ID => $typeId
            ]
        );

        $this->post($url);
    }
162738
protected function _beforeRepositoryFetch(AnCommandContext $context)
    {
        $query = $context->query;

        if ($query->keyword) {
            $keywords = $query->keyword;

            if ($keywords) {
                if (strpos($keywords, ' OR ')) {
                    $keywords = explode(' OR ', $keywords);
                    $operation = 'OR';
                } else {
                    $keywords = explode(' ', $keywords);
                    $operation = 'AND';
                }

                if (!empty($operation)) {
                    $clause = $query->clause();
                    $search_column = array();

                    foreach ($this->_searchable_properties as $property) {
                        $search_column[] = "IF(@col($property) IS NULL,\"\",@col($property))";
                    }

                    $search_column = implode($search_column, ',');

                    foreach ($keywords as $keyword) {
                        $clause->where('CONCAT('.$search_column.') LIKE @quote(%'.$keyword.'%)', $operation);
                    }
                }
            }
        }
    }
556968
public function registerDynamicType($typeName)
    {
        if (isset($this->bindings[$typeName])) {
            throw new \InvalidArgumentException("`$typeName` is already registerd.");
        }

        $type = new \ReflectionClass($typeName);
        $this->bindings[$typeName] = new DynamicService($type);

        return $this;
    }