/** * * Returns Google API key if found in collection * @param string $domain * @return string Google API key */ public function getAPIKeyByDomain($domain) { if (!$this->_keys->contains($domain)) { return false; } return $this->_keys->itemAt($domain); }
public function relations() { $map = new CMap(parent::relations()); $nrelation = array('images' => array(self::HAS_MANY, 'Image', 'model_id', 'condition' => 'images.model_name = \'Category\'')); $map->mergeWith($nrelation); return $map; }
public function renderInput() { //set default settings $this->attributes = CMap::mergeArray($this->defaultWidgetSettings, $this->attributes); /* * if we have more than 1 forms on page for single model, * than at some input will be same id. we must set different id. * but Yii generate non different id for error tag. */ if (!isset($this->errorOptions['inputID']) && isset($this->attributes['id'])) { $this->errorOptions['inputID'] = $this->attributes['id']; } //replace sinonym on full alias if (isset($this->widgets[$this->type])) { $this->type = $this->widgets[$this->type]; if (strpos($this->type, '.') === false) { $this->type = $this->widgets_path . str_repeat('.' . $this->type, 2); } $attributes = $this->attributes; $attributes['model'] = $this->getParent()->getModel(); $attributes['attribute'] = $this->name; $attributes['input_element'] = $this; ob_start(); $this->getParent()->getOwner()->widget($this->type, $attributes); return ob_get_clean(); } return parent::renderInput(); }
/** *### .renderItem() */ protected function renderItem($options, $templateData) { //apply editable if not set 'editable' params or set and not false $apply = !empty($options['name']) && (!isset($options['editable']) || $options['editable'] !== false); if ($apply) { //ensure $options['editable'] is array if (!isset($options['editable'])) { $options['editable'] = array(); } //take common url if not defined for particular item and not related model if (!isset($options['editable']['url']) && strpos($options['name'], '.') === false) { $options['editable']['url'] = $this->url; } //take common params if not defined for particular item if (!isset($options['editable']['params'])) { $options['editable']['params'] = $this->params; } $editableOptions = CMap::mergeArray($options['editable'], array('model' => $this->data, 'attribute' => $options['name'], 'emptytext' => $this->nullDisplay === null ? Yii::t('zii', 'Not set') : strip_tags($this->nullDisplay))); //if value in detailview options provided, set text directly (as value means text) if (isset($options['value']) && $options['value'] !== null) { $editableOptions['text'] = $templateData['{value}']; $editableOptions['encode'] = false; } /** @var $widget TbEditableField */ $widget = $this->controller->createWidget('TbEditableField', $editableOptions); //'apply' can be changed during init of widget (e.g. if related model and unsafe attribute) if ($widget->apply) { ob_start(); $widget->run(); $templateData['{value}'] = ob_get_clean(); } } parent::renderItem($options, $templateData); }
/** * Panel initialization. * Generate unique tag for page. Attach panels, log watcher. Register scripts for printing debug panel. */ public function init() { parent::init(); if (!$this->enabled) { return; } Yii::setPathOfAlias('yii2-debug', dirname(__FILE__)); Yii::app()->setImport(array('yii2-debug.*', 'yii2-debug.panels.*')); if ($this->logPath === null) { $this->logPath = Yii::app()->getRuntimePath() . '/debug'; } $panels = array(); foreach (CMap::mergeArray($this->corePanels(), $this->panels) as $id => $config) { if (!isset($config['highlightCode'])) { $config['highlightCode'] = $this->highlightCode; } $panels[$id] = Yii::createComponent($config, $this, $id); } $this->panels = $panels; Yii::app()->setModules(array($this->moduleId => array('class' => 'Yii2DebugModule', 'owner' => $this))); if ($this->internalUrls && Yii::app()->getUrlManager()->urlFormat == 'path') { $rules = array(); foreach ($this->coreUrlRules() as $key => $value) { $rules[$this->moduleId . '/' . $key] = $this->moduleId . '/' . $value; } Yii::app()->getUrlManager()->addRules($rules, false); } Yii::app()->attachEventHandler('onEndRequest', array($this, 'onEndRequest')); $this->initToolbar(); }
/** *### .renderItem() */ protected function renderItem($options, $templateData) { //apply editable if not set 'editable' params or set and not false $apply = !empty($options['name']) && (!isset($options['editable']) || $options['editable'] !== false); if ($apply) { //ensure $options['editable'] is array if (!isset($options['editable'])) { $options['editable'] = array(); } //merge options with defaults: url, params, etc. $options['editable'] = CMap::mergeArray($this->_data, $options['editable']); //options to be passed into EditableField (constructed from $options['editable']) $widgetOptions = array('model' => $this->data, 'attribute' => $options['name']); //if value in detailview options provided, set text directly (as value here means text) if (isset($options['value']) && $options['value'] !== null) { $widgetOptions['text'] = $templateData['{value}']; $widgetOptions['encode'] = false; } $widgetOptions = CMap::mergeArray($widgetOptions, $options['editable']); /** @var $widget TbEditableField */ $widget = $this->controller->createWidget('TbEditableField', $widgetOptions); //'apply' maybe changed during init of widget (e.g. if related model has unsafe attribute) if ($widget->apply) { ob_start(); $widget->run(); $templateData['{value}'] = ob_get_clean(); } } parent::renderItem($options, $templateData); }
/** * * Creates a single node as xml format * * @access private * @param string name of the tag * @param mixed tag value as string or array of nested tags in 'tagName' => 'tagValue' format * @param array Attributes(if any) in 'attrName' => 'attrValue' format * @return string formatted xml tag */ private function makeNode($tagName, $tagContent, $attributes = array()) { $node = ''; if (is_array($tagContent) && $this->type == self::RSS1) { $attributes['rdf:parseType'] = "Resource"; } if (in_array($tagName, $this->feedElements->itemAt('CDATAEncoded'))) { if ($this->type == self::ATOM) { $attributes['type'] = "html"; } $node .= CHtml::openTag($tagName, $attributes) . '<![CDATA['; } else { $node .= CHtml::openTag($tagName, $attributes); } if (is_array($tagContent)) { foreach ($tagContent as $tag => $content) { $node .= $this->makeNode($tag, $content); } } else { $node .= in_array($tagName, $this->feedElements->itemAt('CDATAEncoded')) ? $tagContent : CHtml::encode($tagContent); } $node .= in_array($tagName, $this->feedElements->itemAt('CDATAEncoded')) ? PHP_EOL . ']]>' : ''; $node .= CHtml::closeTag($tagName); return $node . PHP_EOL; }
protected function renderItem($options, $templateData) { //if editable set to false --> not editable $isEditable = array_key_exists('editable', $options) && $options['editable'] !== false; //if name not defined or it is not safe --> not editable $isEditable = !empty($options['name']) && $this->data->isAttributeSafe($options['name']); if ($isEditable) { //ensure $options['editable'] is array if (!array_key_exists('editable', $options) || !is_array($options['editable'])) { $options['editable'] = array(); } //take common url if (!array_key_exists('url', $options['editable'])) { $options['editable']['url'] = $this->url; } $editableOptions = CMap::mergeArray($options['editable'], array('model' => $this->data, 'attribute' => $options['name'], 'emptytext' => $this->nullDisplay === null ? Yii::t('zii', 'Not set') : strip_tags($this->nullDisplay))); //if value in detailview options provided, set text directly if (array_key_exists('value', $options) && $options['value'] !== null) { $editableOptions['text'] = $templateData['{value}']; $editableOptions['encode'] = false; } $templateData['{value}'] = $this->controller->widget('EditableField', $editableOptions, true); } parent::renderItem($options, $templateData); }
/** * * Sets plugin options * @param array $options * @throws CException */ public function setOptions($options) { if (!is_array($options)) { throw new CException(Yii::t('EGMap', 'KeyDrEGMapKeyDragZoomagZoom options must be of type array!')); } $this->options = CMap::mergeArray($this->options, $options); }
/** * Initializes the widget. */ public function init() { if (is_null($this->theme)) { $this->theme = 'default'; } // check if options parameter is a json string if (is_string($this->options)) { if (!($this->options = CJSON::decode($this->options))) { throw new CException('The options parameter is not valid JSON.'); } } // merge options with default values $defaultOptions = array(); $this->options = CMap::mergeArray($defaultOptions, $this->options); // merge options with Javascript events $normalizedEvents = array(); foreach ($this->events as $name => $handler) { $normalizedEvents[$name] = new CJavaScriptExpression($handler); } $this->options = CMap::mergeArray($normalizedEvents, $this->options); // set field initial value if (isset($this->options['formatSubmit'])) { if (!isset($this->htmlOptions['data-value']) && $this->hasModel()) { $this->htmlOptions['data-value'] = CHtml::resolveValue($this->model, $this->attribute); } } // prepend pickadate scripts to the begining of the additional js files array if (!empty($this->language)) { array_unshift($this->scripts, "translations/{$this->language}"); } array_unshift($this->scripts, 'picker.date'); array_unshift($this->scripts, $this->baseScript); }
public function renderMenuItem() { $parentMenuItem = parent::renderMenuItem(); $itemOptions = array('itemOptions' => array('id' => get_class($this))); $content = CMap::mergeArray($parentMenuItem, $itemOptions); return $content; }
/** * Retrieves a list of models based on the current search/filter conditions. * @param array $options * @return YdActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search($options = array()) { $criteria = new CDbCriteria(); $criteria->compare('t.id', $this->id); $criteria->compare('t.name', $this->name, true); return new YdActiveDataProvider($this, CMap::mergeArray(array('criteria' => $criteria), $options)); }
/** * @see CMenu::renderMenuRecursive */ protected function renderMenuRecursive($items) { foreach ($items as $item) { echo CHtml::openTag('li', isset($item['htmlOptions']) ? $item['htmlOptions'] : array()); if (isset($item['encodeLabel']) ? $item['encodeLabel'] : $this->encodeLabel) { $item['label'] = CHtml::encode($item['label']); } if (isset($item['url']) && !($this->activeLinkDisable && $item['active'])) { $menu = CHtml::link($item['label'], $item['url'], isset($item['linkOptions']) ? $item['linkOptions'] : array()); } else { $menu = CHtml::tag('span', isset($item['linkOptions']) ? $item['linkOptions'] : array(), $item['label']); } if (isset($this->itemTemplate) || isset($item['template'])) { $template = isset($item['template']) ? $item['template'] : $this->itemTemplate; echo strtr($template, array('{menu}' => $menu)); } else { echo $menu; } if (isset($item['items']) && count($item['items'])) { echo "\n" . CHtml::openTag('ul', CMap::mergeArray($this->submenuHtmlOptions, $item['submenuHtmlOptions'] ? $item['submenuHtmlOptions'] : array())) . "\n"; $this->renderMenuRecursive($item['items']); echo CHtml::closeTag('ul') . "\n"; } echo CHtml::closeTag('li') . "\n"; } }
public function cmsDataTypeRelations($event) { $event->relations = CMap::mergeArray( $event->relations, array('gallery' => array(ImageGallery::HAS_MANY, 'ImageGallery', ImageGallery::getPkAttr())) ); }
/** * Load the environment file and Yii config file for the application * The Yii config file must be named as main-APP_ID where APP_ID is defined in the index.php * * @return array */ function configureApplication($appId, $resolver) { ensureSSL(); if ($resolver !== true) { return array(); } include_once WEB_ROOT . '../server/modules/Xpress/components/Application.php'; // load environment info $envFile = checkInditionEnv(); if ($envFile) { include $envFile; // load application config $appConfigFile = WEB_ROOT . '../server/config/main-' . APP_ID . '.php'; if (file_exists($appConfigFile)) { $appConfig = (include $appConfigFile); } else { $appConfig = array(); } // merge app config with base config $base = (require WEB_ROOT . '../server/config/base.php'); $config = CMap::mergeArray($base, $appConfig); if ($appConfig['modules'] == array()) { $config['components']['Xpress']['RebuildModuleCache'] = true; } return $config; } else { return array(); } }
/** * Renders the header cell. */ public function renderHeaderCell() { if ($this->grid->json) { $header = array('id' => $this->id); $content = array(); if ($this->grid->enableSorting && $this->sortable && $this->name !== null) { $sort = $this->grid->dataProvider->getSort(); $label = isset($this->header) ? $this->header : $sort->resolveLabel($this->name); if ($sort->resolveAttribute($this->name) !== false) { $label .= '<span class="caret"></span>'; } $content['content'] = $sort->link($this->name, $label, array('class' => 'sort-link')); } else { if ($this->name !== null && $this->header === null) { if ($this->grid->dataProvider instanceof CActiveDataProvider) { $content['content'] = CHtml::encode($this->grid->dataProvider->model->getAttributeLabel($this->name)); } else { $content['content'] = CHtml::encode($this->name); } } else { $content['content'] = trim($this->header) !== '' ? $this->header : $this->grid->blankDisplay; } } return CMap::mergeArray($header, $content); } parent::renderHeaderCell(); }
/** * initialize widget * */ public function init() { //check needed values /*if(!isset($this->dataUrl)) { throw new CException("You have to define a dataUrl!",500); }*/ //get widget id if (isset($this->htmlOptions['id'])) { $id = $this->htmlOptions['id']; } else { $this->htmlOptions['id'] = $this->getId(); } //set additional default options that only make sense after initialization $this->defaultOptions = CMap::mergeArray($this->defaultOptions, array('parent' => $this->id)); //merge options with default options $this->options = CMap::mergeArray($this->defaultOptions, $this->options); //set correct image path according to skin if not set already if (!isset($this->options['icon_path'])) { $this->options['icon_path'] = $this->getAssetPath() . '/codebase/imgs/' . $this->skinToImgFolderMappings[$this->options['skin']] . '/'; } //set correct image path according to skin if not set already if (!isset($this->options['image_path'])) { $this->options['image_path'] = $this->getAssetPath() . '/codebase/imgs/' . $this->skinToImgFolderMappings[$this->options['skin']] . '/'; } $this->options['items'] = array(array('id' => 'file', 'text' => 'File', 'items' => array(array('id' => 'fileopen', 'text' => 'Open File')))); //publish assets parent::init(); }
protected function renderDataCellContent($row, $data) { if (!$this->isEditable($data)) { parent::renderDataCellContent($row, $data); return; } $options = CMap::mergeArray($this->editable, array('model' => $data, 'attribute' => $this->name)); //if value defined for column --> use it as element text if (strlen($this->value)) { ob_start(); parent::renderDataCellContent($row, $data); $text = ob_get_clean(); $options['text'] = $text; $options['encode'] = false; } $editable = $this->grid->controller->createWidget('TbEditableField', $options); //manually make selector non unique to match all cells in column $selector = get_class($editable->model) . '_' . $editable->attribute; $editable->htmlOptions['rel'] = $selector; $editable->renderLink(); //manually render client script (one for all cells in column) if (!$this->isScriptRendered) { $script = $editable->registerClientScript(); Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $selector . '-event', ' $("#' . $this->grid->id . '").parent().on("ajaxUpdate.yiiGridView", "#' . $this->grid->id . '", function() {' . $script . '}); '); $this->isScriptRendered = true; } }
/** * Initializes the widget. */ public function init() { $behavior = $this->controller->asa('seo'); if ($behavior !== null && $behavior->metaDescription !== null) { $this->_description = $behavior->metaDescription; } else { if ($this->defaultDescription !== null) { $this->_description = $this->defaultDescription; } } if ($behavior !== null && $behavior->metaKeywords !== null) { $this->_keywords = $behavior->metaKeywords; } else { if ($this->defaultKeywords !== null) { $this->_keywords = $this->defaultKeywords; } } if ($behavior !== null) { $this->_properties = CMap::mergeArray($behavior->metaProperties, $this->defaultProperties); } else { $this->_properties = $this->defaultProperties; } if ($behavior !== null && $behavior->canonical !== null) { $this->_canonical = $behavior->canonical; } }
protected function registerLocale() { $langFile = dirname(__FILE__) . '/locale/' . $this->lang . '.php'; if (file_exists($langFile)) { $this->options = CMap::mergeArray($this->options, include $langFile); } }
/** * @param $attribute * @param null $value * @param null $name * @param array $htmlOptions * @return mixed|null|string */ public static function renderField($attribute, $value = null, $name = null, $htmlOptions = []) { $name = $name ?: 'Attribute[' . $attribute->id . ']'; switch ($attribute->type) { case Attribute::TYPE_SHORT_TEXT: return CHtml::textField($name, $value, $htmlOptions); break; case Attribute::TYPE_TEXT: return Yii::app()->getController()->widget(Yii::app()->getModule('store')->getVisualEditor(), ['name' => $name, 'value' => $value], true); break; case Attribute::TYPE_DROPDOWN: $data = CHtml::listData($attribute->options, 'id', 'value'); return CHtml::dropDownList($name, $value, $data, array_merge($htmlOptions, ['empty' => '---'])); break; case Attribute::TYPE_CHECKBOX_LIST: $data = CHtml::listData($attribute->options, 'id', 'value'); return CHtml::checkBoxList($name . '[]', $value, $data, $htmlOptions); break; case Attribute::TYPE_CHECKBOX: return CHtml::checkBox($name, $value, CMap::mergeArray(['uncheckValue' => 0], $htmlOptions)); break; case Attribute::TYPE_NUMBER: return CHtml::numberField($name, $value, $htmlOptions); break; case Attribute::TYPE_FILE: return CHtml::fileField($name . '[name]', null, $htmlOptions); break; } return null; }
/** * @param $name * @param $attribute * @param null $model * @param bool $layout * @return VisualElementBaseWidget */ public function createChildWidget($name, $attribute, $model = null, $layout = false, $params = array()) { if ($model == null) { $model = $this->model; } return $this->controller->createWidget($name, CMap::mergeArray(array('form' => $this->form, 'model' => $this->model, 'attributeName' => $attribute, 'layout' => $layout), $params)); }
/** * Register required script files * @param $id */ public function registerClientScript($id) { Yii::app()->bootstrap->registerAssetCss('redactor.css'); Yii::app()->bootstrap->registerAssetJs('redactor.min.js'); $options = CJSON::encode(CMap::mergeArray($this->editorOptions, array('lang' => $this->lang))); Yii::app()->bootstrap->registerRedactor('#' . $id, $options); }
public function run() { $this->controller->layout = false; $feedSettings = CMap::mergeArray($this->getDefaultFeedSettings(), $this->getFeedSettings()); $feedItems = $this->getRssItems(); $feed = new EFeed($this->type); $channelTags = HArray::val($feedSettings, 'channelTags', array()); unset($feedSettings['channelTags']); //Настраиваем канал foreach ($feedSettings as $settingName => $settingValue) { $feed->{$settingName} = $settingValue; } $feed->addChannelTagsArray($channelTags); //Заносим элементы канала $c = count($feedItems); for ($i = 0; $i < $c; $i++) { $feed->addItem($feedItems[$i]); } if ($c == 0) { echo 'No feed items'; return; } //рендерим канал $feed->generateFeed(); }
/** */ public function run() { /** * @var CClientScript $cs */ $cs = Yii::app()->getClientScript(); // Javascript var if (empty($this->jsVarName)) { $this->jsVarName = $this->getId() . 'Layout'; } // Container ID if (!isset($this->htmlOptions['id'])) { $this->htmlOptions['id'] = $this->getId(); } $id = $this->htmlOptions['id']; echo CHtml::openTag('div', $this->htmlOptions); $layoutsOptions = $this->renderLayouts(); echo '</div>'; // Prepare options $options = CMap::mergeArray($this->options, $layoutsOptions); $options = empty($options) ? '' : CJavaScript::encode($options); // Register global JS var $cs->registerScript(__CLASS__ . '#jsVar#' . $this->getId(), 'var ' . $this->jsVarName . ';', CClientScript::POS_HEAD); // Register Layouts init script $cs->registerScript(__CLASS__ . '#init#' . $this->getId(), $this->jsVarName . ' = $("#' . $id . '").layout(' . $options . ');', CClientScript::POS_READY); }
/** * @param int $depth how many levels of relations to open * @param bool $hrefOnly determines if the model attributes to be displayed are hrefOnly or all of its attributes * @return array */ public function format($depth = 1, $hrefOnly = false) { $model = $this->owner; $processUrl = $this->processUrl; $attributes = array('href' => $processUrl($model)); if (!$hrefOnly) { $attributes = CMap::mergeArray($attributes, $model->attributes); } if ($depth <= 0) { return $attributes; } $relations = $model->relations(); foreach ($relations as $relationName => $relation) { if ($model->getRelated($relationName) !== null) { $hrefOnly = !in_array($relationName, $this->expand); if (is_array($model->getRelated($relationName))) { foreach ($model->getRelated($relationName) as $relatedModel) { $relatedModel->attachBehavior('hyperMedia', new self($this->expand, $processUrl, $this->objectFormatter)); $attributes[$relationName] = $relatedModel->format($depth - 1, $hrefOnly); } } else { $relatedModel = $model->getRelated($relationName); $relatedModel->attachBehavior('hyperMedia', new self($this->expand, $processUrl, $this->objectFormatter)); $attributes[$relationName] = $relatedModel->format($depth - 1, $hrefOnly); } } else { $attributes[$relationName] = null; } } $formatter = $this->objectFormatter; $attributes = $formatter($model, $attributes); return $attributes; }
public static function getListAgency() { $sql = "SELECT id, agency_name FROM {{users}} WHERE active = 1 AND type=:type"; $all = Yii::app()->db->createCommand($sql)->queryAll(true, array(':type' => User::TYPE_AGENCY)); $list = CHtml::listData($all, 'id', 'agency_name'); return CMap::mergeArray(array(0 => ''), $list); }
public function init() { $this->defaultOptions = CMap::mergeArray($this->defaultOptions, array('delegate' => $this->delegate)); $this->target = '#' . $this->id; echo CHtml::openTag($this->tagName, array('id' => $this->id), $this->htmlOptions); parent::init(); }
protected function resolveRedactorOptions() { $parentOptions = parent::resolveRedactorOptions(); $options = array('paragraphy' => 'false', 'buttons' => $this->resolveRedactorButtons(), 'plugins' => CJSON::encode($this->resolvePlugins())); $options = CMap::mergeArray($parentOptions, $options); return $options; }
public function execute($url, $options = array(), $postData = array()) { $ch = curl_init(); $options = CMap::mergeArray(self::$defaultOptions, $options); $options[CURLOPT_URL] = $url; if (!empty($postData)) { $options[CURLOPT_POST] = true; $options[CURLOPT_POSTFIELDS] = $postData; } foreach ($options as $key => $value) { curl_setopt($ch, $key, $value); } $start = microtime(true); // загрузка страницы и выдача её браузеру $this->content = curl_exec($ch); $this->totalTime = microtime(true) - $start; $this->errorCode = curl_errno($ch); if ($this->errorCode) { $this->errorMessage = curl_error($ch); } $this->httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // завершение сеанса и освобождение ресурсов curl_close($ch); if ($this->errorCode) { return false; } else { if (!$this->isHttpOK()) { $this->errorMessage = $this->content; return false; } else { return true; } } }