Implements route().

Allows route to be selected for /admin/config/.

@param $selection
@param string $configArea
@param $selection

@return mixed|string

@throws RuntimeException
184861
public static function route($configArea, $selection)
    {
        if (isset($selection) && isset($configArea)) {
            $needle = str_replace('%config_area%', $configArea, static::$URL);
            $haystack = str_replace('%selection%', $selection, $needle);
            return $haystack;
        } else {
            // Bad selection was provided.
            throw new RuntimeException("Not a valid config area selection.");
        }
    }
445711
public function load($routingResource, $type = null)
    {
        if ($this->loaded) {
            throw new RuntimeException('Do not add the Admin "extra" loader twice');
        }
        $routes = new RouteCollection();

        foreach ($this->resourceCollection->all() as $name => $resource) {
            $configuration = $this
                ->configurationFactory
                ->createAdminConfiguration(
                    $resource->getName(),
                    $resource->getConfiguration(),
                    $this->applicationConfiguration
                )
            ;

            foreach ($configuration->getParameter('actions') as $actionName => $actionData) {
                $actionConfiguration = $this
                    ->configurationFactory
                    ->createActionConfiguration($actionName, $actionData, $name, $configuration)
                ;
                $route = new Route(
                    $actionConfiguration->getParameter('route_path'),
                    $actionConfiguration->getParameter('route_defaults'),
                    $actionConfiguration->getParameter('route_requirements')
                );
                $routes->add($actionConfiguration->getParameter('route'), $route);
            }

            if ($this->applicationConfiguration->getParameter('enable_homepage')) {
                $route = new Route('/', ['_controller' => HomeAction::class], []);
                $routes->add('lag.admin.homepage', $route);
            }
        }

        return $routes;
    }
1307474
public function makeRadio($config, $selected, $custom)
    {
        return '<input '.$this->processCustom($custom).' id="'.$this->getId($config).'" '.$selected.' type="radio" name="'.$config['name'].'" class="'. $config['class'] .'">';
    }
1209373
public function chosen() : ?Connection
    {
        if ($this->filename === null) {
            return null;
        }

        if (! file_exists($this->filename)) {
            return null;
        }

        $params = include $this->filename;

        if (! is_array($params)) {
            throw InvalidConfiguration::invalidArrayConfiguration();
        }

        return DriverManager::getConnection($params);
    }
1014750
public function select(array $configs, $options)
    {
        $label = (!empty($options['name']) ? ucwords($options['name']) : '');

        return '
        <div class="input-field">
        '.parent::plainSelect(array_merge([
            'id' => $this->genId($label),
        ], $configs), $options).(empty($label) | (substr($label, 0,
                1) == '_') ? '' : '<label for="'.$label.'">'.$this->inputToRead($label).'</label>').'
        </div>
         ';
    }
180997
private function getOption(string $element, string $section, $default = null)
    {
        if (!isset($this->config['declarations'][$element])) {
            throw new ScaffolderException("Undefined declaration '{$element}'.");
        }

        if (array_key_exists($section, $this->config['declarations'][$element])) {
            return $this->config['declarations'][$element][$section];
        }

        return $default;
    }
78362
protected function getUrlFromConfiguration($routeName, $configuration, $item = null)
    {
        foreach ($configuration['route_parameters'] as $key=>$parameter) {
            $configuration['route_parameters'][$key] = $this->getItemParameter($item, $parameter);
        }
        
        $url = $this->router->generate($routeName, $configuration['route_parameters']);
        
        $urlObject = new Url(
                $url,
                (isset($configuration['last_mod']) ? $this->getItemParameter($item, $configuration['last_mod']) : null),
                (isset($configuration['priority']) ? $this->getItemParameter($item, $configuration['priority']) : null),
                (isset($configuration['change_freq']) ? $this->getItemParameter($item, $configuration['change_freq']) : null)
        );
        return $urlObject;
    }
200974
protected function configure()
    {
        $request = $this->getRequest();

        $adminCode = $request->get('_sonata_admin');

        if (!$adminCode) {
            throw new \RuntimeException(sprintf(
                'There is no `_sonata_admin` defined for the controller `%s` and the current route `%s`',
                \get_class($this),
                $request->get('_route')
            ));
        }

        $this->admin = $this->container->get('sonata.admin.pool')->getAdminByAdminCode($adminCode);

        if (!$this->admin) {
            throw new \RuntimeException(sprintf(
                'Unable to find the admin class related to the current controller (%s)',
                \get_class($this)
            ));
        }

        $this->templateRegistry = $this->container->get($this->admin->getCode().'.template_registry');
        if (!$this->templateRegistry instanceof TemplateRegistryInterface) {
            throw new \RuntimeException(sprintf(
                'Unable to find the template registry related to the current admin (%s)',
                $this->admin->getCode()
            ));
        }

        $rootAdmin = $this->admin;

        while ($rootAdmin->isChild()) {
            $rootAdmin->setCurrentChild(true);
            $rootAdmin = $rootAdmin->getParent();
        }

        $rootAdmin->setRequest($request);

        if ($request->get('uniqid')) {
            $this->admin->setUniqid($request->get('uniqid'));
        }
    }
545027
public function getRoute(AdminInterface $admin, $action, $params = [], $isIndex = false)
    {
        $defaults = [];
        $path = '/' . $admin->getAlias();

        // append action if required
        if(!$isIndex) {
            $path .= '/' . $action;
        }

        foreach($params as $paramKey => $paramValue) {
            if(is_int($paramKey)) {
                $paramName = $paramValue;
            }
            else {
                $paramName = $paramKey;
                $defaults[$paramName] = $paramValue;
            }
            $path .= '/{' . $paramName . '}';
        }

        $controller = 'ShuweeAdminBundle:Content:' . $action;

        $defaults = array_merge(
          [
            '_controller' => $controller,
            'alias' => $admin->getAlias(),

          ],
          $defaults
        );

        return new Route($path, $defaults);
    }
117414
public function makeSelect(string $connectionName = ''): SelectQueryBuilder
    {
        $connection = $this->provideConnection($connectionName);
        $statementBuilder = new SelectStatementBuilder;
        return new SelectQueryBuilder($connection, $statementBuilder);
    }
633219
public function cache($key, $config = 'default')
    {
        if ($this->_type !== 'select' && $this->_type !== null) {
            throw new RuntimeException('You cannot cache the results of non-select queries.');
        }

        return $this->_cache($key, $config);
    }
1061930
protected function getControllerOptions( array $selected )
	{
		$html = '';
		$aimeos = Base::getAimeos();
		$context = Scheduler\Base::getContext();
		$cntlPaths = $aimeos->getCustomPaths( 'controller/jobs' );

		$langid = 'en';
		if( isset( $GLOBALS['BE_USER']->uc['lang'] ) && $GLOBALS['BE_USER']->uc['lang'] != '' ) {
			$langid = $GLOBALS['BE_USER']->uc['lang'];
		}

		$localeItem = \Aimeos\MShop::create( $context, 'locale' )->createItem();
		$localeItem->setLanguageId( $langid );
		$context->setLocale( $localeItem );

		$controllers = \Aimeos\Controller\Jobs::get( $context, $aimeos, $cntlPaths );

		foreach( $controllers as $name => $controller )
		{
			$active = ( in_array( $name, $selected ) ? 'selected="selected"' : '' );
			$title = htmlspecialchars( $controller->getDescription(), ENT_QUOTES, 'UTF-8' );
			$cntl = htmlspecialchars( $controller->getName(), ENT_QUOTES, 'UTF-8' );
			$name = htmlspecialchars( $name, ENT_QUOTES, 'UTF-8' );

			$html .= sprintf( '<option value="%1$s" title="%2$s" %3$s>%4$s</option>', $name, $title, $active, $cntl );
		}

		return $html;
	}
1368175
public function getFormat(StorageSelection $selection)
    {
        $ext = pathinfo($selection->getId(), PATHINFO_EXTENSION);

        $type = $this->discoverFormat($ext, $selection->getId());

        return $type;
    }
179540
public function getConfiguration(array $config, ContainerBuilder $container)
    {
        $configuration = parent::getConfiguration($config, $container);
        if (null === $configuration) {
            throw new \RuntimeException('No configuration found');
        }

        return $configuration;
    }
523225
public function preSelect(Select $select)
	{
		$tableGateway = $this->tableGateway;
		$tableName    = $tableGateway->getTable();
		$tableClass   = get_class($tableGateway);

		$tablePrimKey = $this->getPrimaryKey($tableGateway);    
		
		$locale       = $this->getLocale();

		foreach ($this->getTranslatableFields() as $tf) {
			$name = 'I18n__'.$tf;
			// get name of translation table
			$joinTable = $this->getTranslationTable()->table;
			
			$expression = new Expression("
				$name.foreign_key = ?.?
				AND $name.model = ?
				AND $name.field = ?
				AND $name.locale = ?"
				,array(
					$tableName,$tablePrimKey,
					$tableClass,
					$tf,
					$locale
				)
				,array(
					Expression::TYPE_IDENTIFIER,
					Expression::TYPE_IDENTIFIER
				)
			);
			
			$select->join(
				array($name => $joinTable),//join table name
				$expression //conditions
				// `I18n__description`.`content` AS `description`
				#,array($tf => 'content') 
					// this way we dont need postSelect replacement
			
				// `I18n__description`.`content` AS `sampletableI18n__description`
				,array($tableName.$name => 'content') 
					// toSolve: dar taghaabol baa exp. DMS gharaar migirad va field e tarjome shode tarjome nemishavad
                ,Select::JOIN_LEFT
			);
		}
	}
136802
private function getRoute(string $routeName): Route
    {
        foreach ($this->router->getRouteCollection() as $name => $route) {
            if ($routeName === $name) {
                return $route;
            }
        }

        throw new RuntimeException(sprintf('The route "%s" does not exist.', $routeName));
    }
1160433
public function admin_authorised_user_selector(&$options) {
        global $CFG;
        $formcontent = html_writer::empty_tag('input',
                        array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden'));

        $table = new html_table();
        $table->size = array('45%', '10%', '45%');
        $table->attributes['class'] = 'roleassigntable generaltable generalbox boxaligncenter';
        $table->summary = '';
        $table->cellspacing = 0;
        $table->cellpadding = 0;

        // LTR/RTL support, for drawing button arrows in the right direction
        if (right_to_left()) {
            $addarrow = '▶';
            $removearrow = '◀';
        } else {
            $addarrow = '◀';
            $removearrow = '▶';
        }

        //create the add and remove button
        $addinput = html_writer::empty_tag('input',
                        array('name' => 'add', 'id' => 'add', 'type' => 'submit',
                            'value' => $addarrow . ' ' . get_string('add'),
                            'title' => get_string('add')));
        $addbutton = html_writer::tag('div', $addinput, array('id' => 'addcontrols'));
        $removeinput = html_writer::empty_tag('input',
                        array('name' => 'remove', 'id' => 'remove', 'type' => 'submit',
                            'value' => $removearrow . ' ' . get_string('remove'),
                            'title' => get_string('remove')));
        $removebutton = html_writer::tag('div', $removeinput, array('id' => 'removecontrols'));


        //create the three cells
        $label = html_writer::tag('label', get_string('serviceusers', 'webservice'),
                        array('for' => 'removeselect'));
        $label = html_writer::tag('p', $label);
        $authoriseduserscell = new html_table_cell($label .
                        $options->alloweduserselector->display(true));
        $authoriseduserscell->id = 'existingcell';
        $buttonscell = new html_table_cell($addbutton . html_writer::empty_tag('br') . $removebutton);
        $buttonscell->id = 'buttonscell';
        $label = html_writer::tag('label', get_string('potusers', 'webservice'),
                        array('for' => 'addselect'));
        $label = html_writer::tag('p', $label);
        $otheruserscell = new html_table_cell($label .
                        $options->potentialuserselector->display(true));
        $otheruserscell->id = 'potentialcell';

        $cells = array($authoriseduserscell, $buttonscell, $otheruserscell);
        $row = new html_table_row($cells);
        $table->data[] = $row;
        $formcontent .= html_writer::table($table);

        $formcontent = html_writer::tag('div', $formcontent);

        $actionurl = new moodle_url('/' . $CFG->admin . '/webservice/service_users.php',
                        array('id' => $options->serviceid));
        $html = html_writer::tag('form', $formcontent,
                        array('id' => 'assignform', 'action' => $actionurl, 'method' => 'post'));
        return $html;
    }