Renders a search.

@param array $config Configuration

@returns	void
423155
public function search($config = array())
    {
        $actor = null;
        $label = AnTranslator::_('LIB-AN-SEARCH-PLACEHOLDER');

        if ($this->getService()->has('com:search.owner')) {
            $actor = $this->getService('com:search.owner');
            $label = AnTranslator::sprintf('LIB-AN-SEARCH-PLACEHOLDER-OWNER', $actor->name);
        }

        $scope = null;

        if ($this->getService()->has('com:search.scope')) {
            $scope = $this->getService('com:search.scope');
        }

        $url = 'index.php?option=com_search';

        if ($actor) {
            $url .= '&oid='.$actor->uniqueAlias;
        }

        $term = AnRequest::get('get.term', 'raw');
        $term = AnService::get('com:search.filter.term')->sanitize($term);

        $config = new AnConfig($config);

        $config->append(array(
            'label' => $label,
            'term' => $term,
            'url' => $url,
            'actor' => $actor,
            'scope' => $scope,
        ));

        return $this->_render('search',  $config);
    }
1041946
public function config($config)
    {
        if (is_array($config)) {
            $this->config = array_merge($this->config, $config);
        } elseif (isset($this->config[$config])) {
            return $this->config[$config];
        } else {
            return;
        }
    }
799964
private function findConfig(array $config, $search) {
        $filteredConfig = [];
        $search = preg_quote($search);
        $search = str_replace('\*', '(.*)', $search);

        foreach ($config as $key => $value) {
            if (preg_match("#^$search#", $key) === 1) {
                $filteredConfig[$key] = $value;
            }
        }

        return $filteredConfig;
    }
347525
public function render($config = array())
    {
        $config = new KObjectConfigJson($config);
        $config->append(array(
            'toolbar' => null,
            'title'   => null,
        ))->append(array(
            'icon' => $config->toolbar->getName()
        ));

        //Set a custom title
        if($config->title || $config->icon)
        {
            if($config->toolbar->hasCommand('title'))
            {
                $command = $config->toolbar->getCommand('title');

                if ($config->title) {
                    $command->set('title', $config->title);
                }

                if ($config->icon) {
                    $command->set('icon', $config->icon);
                }
            }
            else $config->toolbar->addTitle($config->title, $config->icon);
        }

        $html     = '';
        $commands = $config->toolbar->getCommands();

        foreach ($commands as $command)
        {
            if ($command->getName() === 'title')
            {
                $config->command = $command;

                $html .= $this->title($config);
            }
        }

        return $html;
    }
560921
public function renderWidget( $config = [] ) {

		// Form and Fields
		if( !isset( $this->model ) && isset( $this->slug ) ) {

			$this->model = $this->modelService->getBySlugType( $this->slug, $this->type );
		}

		if( isset( $this->model ) && $this->model->isActive() ) {

			// fields and html
			$fieldsHtml		= FormUtil::getApixFieldsHtml( $this->model, $this->form, [ 'label' => $this->labels, 'modelName' => $this->formName ] );
			$captchaHtml	= null;

			// Views Path
			$formPath		= "$this->template/form";
			$captchaPath	= "$this->template/captcha";

			// submit url
			if( !isset( $this->ajaxUrl ) ) {

				$formSlug		= $this->model->slug;
				$this->ajaxUrl	= "form/$formSlug";
			}

			if( $this->model->captcha ) {

				$captchaHtml = $this->render( $captchaPath );
			}

			$formHtml = $this->render( $formPath, [ 'widget' => $this, 'fieldsHtml' => $fieldsHtml, 'captchaHtml' => $captchaHtml ] );

			// Prepare Form Options
			$modelOptions = !empty( $this->model->htmlOptions ) ? json_decode( $this->model->htmlOptions, true ) : [];

			$this->options = \yii\helpers\ArrayHelper::merge( $this->options, $modelOptions );

			$this->options[ 'action' ]			= $this->ajaxUrl;
			$this->options[ 'method' ]			= 'post';
			$this->options[ 'cmt-app' ]			= 'form';
			$this->options[ 'cmt-controller' ]	= 'form';
			$this->options[ 'cmt-action' ]		= 'default';

			if( !isset( $this->options[ 'class' ] ) ) {

				$this->options[ 'class' ] = 'cmg-form';
			}

			if( !isset( $this->options[ 'id' ] ) ) {

				$this->options[ 'id' ] = "frm-$this->slug";
			}

			if( isset( $this->cmtApp ) ) {

				$this->options[ 'cmt-app' ]	= $this->cmtApp;
			}

			if( isset( $this->cmtController ) ) {

				$this->options[ 'cmt-controller' ] = $this->cmtController;
			}

			if( isset( $this->cmtAction ) ) {

				$this->options[ 'cmt-action' ] = $this->cmtAction;
			}

			if( $this->wrap ) {

				return Html::tag( $this->wrapper, $formHtml, $this->options );
			}

			return $formHtml;
		}
		else {

			echo "<div class=\"warning\">Form not found or submission is disabled.</div>";
		}
	}
1007320
public function autocomplete($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'element'  => null,
            'options_callback' => null, // wraps the call to select2 options in JavaScript, can be used to add JS code
            'options'  => array(
                'minimumInputLength' => 2,
                'validate'      => false, //Toggle if the forms validation helper is loaded
                'queryVarName'  => 'search',
                'width'         => 'resolve',
                'name'          => '',
                'model'		    => $config->model,
                'placeholder'   => $config->prompt,
                'allowClear'    => $config->deselect,
                'value'         => $config->value,
                'text'          => $config->text,
                'selected'      => $config->selected,
                'url'           => $config->ajax_url,
                'multiple'      => false
            )
        ))->append(array(
            'options' => array(
                'label' => $config->text
            )
        ));

        $html ='';

        if (!$config->options->url instanceof HttpUrl) {
            $config->options->url = $this->getObject('lib:http.url', ['url' => $config->options->url]);
        }

        if(!empty($config->name))
        {
            $config->options->url->setQuery(array('fields['.$config->name.']' => $config->value.','.$config->text), true);
            $config->options->url = (string)$config->options->url;
        }

        $options   = $config->options;
        $signature = md5('autocomplete-'.$config->element.$config->options_callback.$options);

        if($config->element && !static::isLoaded($signature))
        {
            $options = (string) $options;

            if ($config->options_callback) {
                $options = $config->options_callback.'('.$options.')';
            }

            $html .= $this->select2(array('element' => false));

            if (!static::isLoaded('kodekit-select2-autocomplete')) {
                $html .= '<script>
                if(!Kodekit) {
                    var Kodekit = typeof Koowa !== "undefined" ?  Koowa : {};
                }
                
                Kodekit.getSelect2Options = function(options) {
                    var defaults = {
                        width: "resolve",
                        minimumInputLength: 2,
                        theme: "bootstrap",
                        ajax: {
                            url: options.url,
                            delay: 100,
                            data: function (params) {
                                var page  = params.page || 1,  // page is the one-based page number tracked by Select2
                                    query = {
                                        limit: 10, // page size
                                        offset: (page-1)*10
                                    };
                                query[options.queryVarName] = params.term;
            
                                return query;
                            },
                            processResults: function (data, page) {
                                var results = [],
                                    more = (page * 10) < data.meta.total; // whether or not there are more results available
            
                                kQuery.each(data.data, function(i, item) {
                                    // Change format to what select2 expects
                                    item.id   = item.attributes[options.value];
                                    item.text = item.attributes[options.text];
            
                                    results.push(item);
                                });
            
                                // notice we return the value of more so Select2 knows if more results can be loaded
                                return {results: results, more: more};
                            }
                        }
                    };
                    
                    var settings = kQuery.extend( {}, defaults, options);
                    
                    return settings;
                };
                </script>';

                static::setLoaded('kodekit-select2-autocomplete');
            }

            $html .= '<script>
            kQuery(function($){
                $("'.$config->element.'").select2(Kodekit.getSelect2Options('.$options.'));
            });</script>';

            static::setLoaded($signature);
        }

        return $html;
    }
768545
protected function _checkSearchConfig( array $config )
	{
		$required = array( 'id', 'label', 'status', 'level', 'left', 'right' );

		foreach( $required as $key => $entry )
		{
			if( isset( $config[$entry] ) ) {
				unset( $required[$key] );
			}
		}

		if( count( $required ) > 0 )
		{
			$msg = 'Search config in given configuration are missing: "%1$s"';
			throw new MW_Tree_Exception( sprintf( $msg, implode( ', ', $required ) ) );
		}
	}
577135
protected function setParsedConfig(array $config)
    {
        foreach ($config as $key => $value) {
            $setter = 'set'.ucfirst($key);
            $this->$setter($value);
        }
    }
519095
public static function findPageForSearch( $config = [] ) {

		// Search
		$searchContent	= isset( $config[ 'searchContent' ] ) ? $config[ 'searchContent' ] : false;
		$keywordsParam	= isset( $config[ 'search-param' ] ) ? $config[ 'search-param' ] : 'keywords';

		$keywords = Yii::$app->request->getQueryParam( $keywordsParam );

		// Sort
		$ratingComment	= isset( $config[ 'ratingComment' ] ) ? $config[ 'ratingComment' ] : false;
		$ratingReview	= isset( $config[ 'ratingReview' ] ) ? $config[ 'ratingReview' ] : false;

		// Filters
		$optionFilters	= isset( $config[ 'optionFilters' ] ) ? $config[ 'optionFilters' ] : [];

		$modelClass	= static::$modelClass;
		$modelTable	= $modelClass::tableName();
		$parentType	= static::$parentType;

		// Search
		if( $searchContent && isset( $keywords ) ) {

			$cache = CacheProperties::getInstance()->isCaching();

			// Search in model cache - full search
			if( $cache ) {

				$config[ 'search-col' ][] = "$modelTable.gridCache";
			}
			// Search in model content only
			else {

				// Search Query
				$config[ 'query' ] = isset( $config[ 'query' ] ) ? $config[ 'query' ] : $modelClass::queryWithAll( [ 'relations' => [ 'modelContent', 'modelContent.template' ] ] );

				// Search in model content
				$config[ 'search-col' ][] = 'modelContent.content';
			}
		}

		// Sort
		$sortParam	= Yii::$app->request->get( 'sort' );
		$sortParam	= preg_replace( '/-/', '', $sortParam );

		// Sort using ModelComment Table
		if( ( $ratingComment || $ratingReview ) && $sortParam == 'rating' ) {

			$type	= '';
			$query	= $config[ 'query' ];

			// Sort by Rating using comments available in ModelComment table
			if( $ratingComment ) {

				$type = ModelComment::TYPE_COMMENT;
			}
			// Sort by Rating using reviews available in ModelComment table
			else if( $ratingReview ) {

				$type = ModelComment::TYPE_REVIEW;
			}

			$commentTable	= Yii::$app->factory->get( 'modelCommentService' )->getModelTable();
			$approved		= ModelComment::STATUS_APPROVED;

			$query->leftJoin( $commentTable,
				"$commentTable.parentId=$modelTable.id AND $commentTable.parentType='$parentType' AND
				$commentTable.type='$type' AND $commentTable.status=$approved" );
		}

		// Option Filters
		if( count( $optionFilters ) > 0 ) {

			$query = $config[ 'query' ];

			$optionTable	= Yii::$app->factory->get( 'optionService' )->getModelTable();
			$mOptionTable	= Yii::$app->factory->get( 'modelOptionService' )->getModelTable();

			foreach( $optionFilters as $key => $option ) {

				$optionList = static::getOptions( $option );

				if( count( $optionList ) > 0 ) {

					$query->leftJoin( "$mOptionTable AS MC$key", "$modelTable.id=MC$key.parentId AND MC$key.parentType='$parentType'" )
						->leftJoin( "$optionTable AS O$key", "MC$key.modelId=O$key.id" )
						->andWhere( "MC$key.active=1" );

					$config[ 'filters' ][] = [ 'in', "O$key.id", $optionList ];
				}
			}
		}

		return parent::findPageForSearch( $config );
	}
824166
public function initialize(array $config)
    {
        if (!$this->_config['key']) {
            $this->setConfig('key', Security::getSalt());
        }

        $controller = $this->_registry->getController();

        if ($controller === null) {
            $this->request = ServerRequestFactory::fromGlobals();
        }

        if (empty($this->_config['path'])) {
            $this->setConfig('path', $this->getController()->getRequest()->getAttribute('webroot'));
        }
    }
483182
protected function applyRoles(array $config) : void
    {
        $this->stdout("Init roles: " . count($config) . "\n", Console::FG_YELLOW);
        foreach ($config as $item) {
            if ($role = $this->applyRole($item)) {
                $this->stdout("\t- success: " . $role->name . "\n", Console::FG_GREEN);
            } else {
                $this->stdout("\t- error config role: " . Json::encode($item) . "\n", Console::FG_RED);
            }
        }
    }
958536
public function renderDragger( $config = [] ) {

		$draggerView = CodeGenUtil::isAbsolutePath( $this->draggerView, true ) ? $this->draggerView : "$this->template/$this->draggerView";

		return $this->render( $draggerView, [ 'widget' => $this ] );
	}
1335136
private function parseConfig(array $config = [])
    {
        $this->apiConfig = $this->extractGuzzleConfig($config);

        if (ConfigUtils::configurationExists($this->apiConfig, 'apiDescription')) {
            $this->apiDescription = $this->apiConfig['apiDescription'];
        }
        if (ConfigUtils::configurationExists($this->apiConfig, 'authType')) {
            $this->authType = $this->apiConfig['authType'];
        }
        if (ConfigUtils::configurationExists($this->apiConfig, 'debug')) {
            $this->debugMode = $this->apiConfig['debug'];
            if (ConfigUtils::configurationExists($this->apiConfig, 'debugLogger')) {
                $this->debugLogger = $this->apiConfig['debugLogger'];
            }
        }
    }
786985
public function initialize(array $config)
    {
        $config = Hash::merge($this->_defaultConfig, $config);
        $this->setConfig($config);
    }
1124414
protected function setModes(array $config)
	{
		if(isset($config['modes']))
		{
			$this->setCustomModes($config);
		}
		else if(isset($config['strict']))
		{
			if($config['strict'])
			{
				$this->pdo->prepare($this->strictMode())->execute();
			}
			else
			{
				$this->pdo->prepare("set session sql_mode='NO_ENGINE_SUBSTITUTION'")->execute();
			}
		}
	}
1108005
public function renderInfo( $config = [] ) {

		$infoView = CodeGenUtil::isAbsolutePath( $this->infoView ) ? $this->infoView : "$this->template/$this->infoView";

        return $this->render( $infoView, [
			'widget' => $this,
			'width' => $this->width, 'height' => $this->height,
			'mwidth' => $this->mwidth, 'mheight' => $this->mheight,
			'twidth' => $this->twidth, 'theight' => $this->theight
		] );
	}
641332
protected function applyConfig(array $config) : void
    {
        $this->applyRules(ArrayHelper::get($config, 'rules', []));
        $this->applyRoles(ArrayHelper::get($config, 'roles', []));
        $this->applyPermissions(ArrayHelper::get($config, 'permissions', []));
    }