public function beforeAction($action) { $this->scanModules('payment'); $arrModules = Modules::model()->findAllByAttributes(array('category' => 'payment'), array('order' => 'module')); $this->_allowAdvancedPayments = CPropertyValue::ensureBoolean(Yii::app()->params['ALLOW_ADVANCED_PAY_METHODS']); $menuSidebar = array(); foreach ($arrModules as $module) { $currentModule = Yii::app()->getComponent($module->module); if (is_null($currentModule)) { continue; } if ($currentModule->cloudCompatible === false && _xls_get_conf('LIGHTSPEED_CLOUD') > 0) { continue; } if ($currentModule->isDisplayable() === false) { continue; } $menuSidebar[] = array('label' => $currentModule->AdminName, 'url' => array('payments/module', 'id' => $module->module), 'advancedPayment' => $currentModule->advancedMode); } $advancedPaymentMethods = where($menuSidebar, array('advancedPayment' => true)); $simplePaymentMethods = where($menuSidebar, array('advancedPayment' => false)); $this->menuItems = array_merge(array(array('label' => 'Simple Integration Modules', 'linkOptions' => array('class' => 'nav-header'))), $simplePaymentMethods, array(array('label' => 'Advanced Integration Modules', 'linkOptions' => array('class' => 'nav-header'), 'visible' => count($advancedPaymentMethods) > 0)), $advancedPaymentMethods, $this->getPaymentSetupLinks()); $objModules = Modules::model()->findAllByAttributes(array('category' => 'payment', 'active' => 1)); if (count($objModules) === 0 && $action->id == "index") { $this->noneActive = 1; Yii::app()->user->setFlash('error', Yii::t('admin', 'WARNING: You have no payment modules activated. No one can checkout.')); } return parent::beforeAction($action); }
public function actionBulkCreate(array $names = array(), $parentId = 0, $vocabularyId = 0) { $vocabularyId = CPropertyValue::ensureInteger($vocabularyId); if (!$vocabularyId) { return errorHandler()->log('Missing Vocabulary Id'); } foreach ($names as $catName) { $catName = trim($catName); if ($catName == '') { continue; } $model = new Term('single_save'); $model->v_id = $vocabularyId; $model->name = $catName; $model->alias = Utility::createAlias($model, $model->name); $model->state = Term::STATE_ACTIVE; $model->parentId = $parentId; if (!$model->save()) { $this->result->fail(ERROR_HANDLING_DB, 'save category failed'); } else { if ($model->parentId) { $relation = TermHierarchy::model()->findByAttributes(array('term_id' => $model->id)); if (!is_object($relation)) { $relation = new TermHierarchy(); $relation->term_id = $model->id; } $relation->parent_id = $model->parentId; if (!$relation->save()) { Yii::log(CVarDumper::dumpAsString($relation->getErrors()), CLogger::LEVEL_ERROR); } } } } }
public function send($phones, $text) { $request = new DOMDocument("1.0", "UTF-8"); $requestBody = $request->createElement('SMS'); $requestBody->appendChild($this->createOperationsElement(array(self::SEND))); $requestBody->appendChild($this->createAuthElement()); $request->appendChild($requestBody); $sms = $request->createElement('message'); $sms->appendChild($request->createElement('sender', $this->sender)); $textElement = $request->createElement('text'); $textElement->appendChild(new DOMCdataSection($text)); $sms->appendChild($textElement); $requestBody->appendChild($sms); if (is_array($phones) == false) { $phones = array($phones => array()); } $numbers = $request->createElement('numbers'); foreach ($phones as $phone => $value) { $variables = implode(';', CPropertyValue::ensureArray($value)) . ';'; $number = $request->createElement('number', $phone); $number->setAttribute('messageid', md5($phone . date() . $variables)); $number->setAttribute('variables', $variables); $numbers->appendChild($number); } $requestBody->appendChild($numbers); $responseText = $this->doRequest($request->saveXML()); $result = $this->parseResponse($responseText); $status = $result['status']; $ok = (bool) ($status > 0); $needSmsAlert = $ok == false && $status != -4; $credits = $this->balance(); return array('status' => $status, 'ok' => $ok, 'responseText' => $responseText, 'credits' => $credits, 'needSmsAlert' => $needSmsAlert); }
public function render($params = array()) { $height = CPropertyValue::ensureInteger($params['height']); $height -= $height > 40 ? 20 : 0; parent::appendOption($this->_htmlOptions, 'class', $this->_cssClass); parent::appendOption($this->_htmlOptions, 'style', 'height: ' . $height . 'px;'); echo CHtml::tag('li', $this->_htmlOptions, $this->_data); }
public function getIsGuest() { $customer = Customer::model()->findByPk($this->id); if ($customer !== null) { return CPropertyValue::ensureInteger($customer->record_type) === Customer::GUEST; } return parent::getIsGuest(); }
/** * This function generates the products grid * based on the criteria. It also generates the * pagination object need for the users to navigate * through products. * * @return void */ public function generateProductGrid() { $this->_numberOfRecords = Product::model()->count($this->_productGridCriteria); $this->_pages = new CPagination($this->_numberOfRecords); $this->_pages->setPageSize(CPropertyValue::ensureInteger(Yii::app()->params['PRODUCTS_PER_PAGE'])); $this->_pages->applyLimit($this->_productGridCriteria); $this->_productsGrid = self::createBookends(Product::model()->findAll($this->_productGridCriteria)); }
/** * @return array the config array passed to widget () */ public function getGridViewConfig() { if (!isset($this->_gridViewConfig)) { $this->_gridViewConfig = array_merge(parent::getGridViewConfig(), array('possibleResultsPerPage' => array(5, 10, 20, 30, 40, 50, 75, 100), 'defaultGvSettings' => array('isActive' => 65, 'fullName' => 125, 'lastLogin' => 80, 'emailAddress' => 100), 'template' => CHtml::openTag('div', X2Html::mergeHtmlOptions(array('class' => 'page-title'), array('style' => !CPropertyValue::ensureBoolean($this->getWidgetProperty('showHeader')) && !CPropertyValue::ensureBoolean($this->getWidgetProperty('hideFullHeader')) ? 'display: none;' : ''))) . '<h2 class="grid-widget-title-bar-dummy-element">' . '</h2>{buttons}{filterHint}' . '{summary}{topPager}</div>{items}{pager}', 'includedFields' => array('tagLine', 'username', 'officePhone', 'cellPhone', 'emailAddress', 'googleId', 'isActive', 'leadRoutingAvailability'), 'specialColumns' => array('fullName' => array('name' => 'fullName', 'header' => Yii::t('profile', 'Full Name'), 'value' => 'CHtml::link(CHtml::encode($data->fullName),array("view","id"=>$data->id))', 'type' => 'raw'), 'lastLogin' => array('name' => 'lastLogin', 'header' => Yii::t('profile', 'Last Login'), 'value' => '$data->user ? ($data->user->lastLogin == 0 ? "" : ' . 'Formatter::formatDateDynamic ($data->user->lastLogin)) : ""', 'type' => 'raw'), 'isActive' => array('name' => 'isActive', 'header' => Yii::t('profile', 'Active'), 'value' => '"<span title=\'' . '".(Session::isOnline ($data->username) ? ' . '"' . Yii::t('profile', 'Active User') . '" : "' . Yii::t('profile', 'Inactive User') . '")."\'' . ' class=\'".(Session::isOnline ($data->username) ? ' . '"active-indicator" : "inactive-indicator")."\'></span>"', 'type' => 'raw'), 'username' => array('name' => 'username', 'header' => Yii::t('profile', 'Username'), 'value' => '$data->user ? CHtml::encode($data->user->alias) : ""', 'type' => 'raw'), 'leadRoutingAvailability' => array('name' => 'leadRoutingAvailability', 'header' => Yii::t('profile', 'Lead Routing Availability'), 'value' => 'CHtml::encode($data->leadRoutingAvailability ? Yii::t("profile", "Available") : Yii::t("profile", "Unavailable"))', 'type' => 'raw')), 'enableControls' => false)); } return $this->_gridViewConfig; }
public static function parseTree($objRet, $root = 0) { $return = array(); # Traverse the tree and search for direct children of the root foreach ($objRet as $objItem) { if (CPropertyValue::ensureInteger($objItem->child_count) > 0 || CPropertyValue::ensureBoolean(Yii::app()->params['DISPLAY_EMPTY_CATEGORY'])) { $return[] = array('text' => CHtml::link($objItem->family, $objItem->Link), 'label' => $objItem->family, 'link' => $objItem->Link, 'request_url' => $objItem->request_url, 'url' => $objItem->Link, 'id' => $objItem->id, 'child_count' => $objItem->child_count, 'children' => null, 'items' => null); } } return empty($return) ? null : $return; }
public function init() { $this->maxBlockTime = $this->getTimeInterval($this->maxBlockTime); $this->alertRepeatInterval = $this->getTimeInterval($this->alertRepeatInterval); $this->gatewayMinCredit = CPropertyValue::ensureFloat($this->gatewayMinCredit); $gateways = array(); foreach ($this->gateways as $gateway) { $gateways[] = Yii::createComponent($gateway); } $this->gateways = $gateways; }
public function truncate($value, $length, $type = TruncateType::Character) { switch (CPropertyValue::ensureEnum($type, TruncateType)) { case TruncateType::Paragraph: return $this->truncateParagraph($value, $length); case TruncateType::Word: return $this->truncateWord($value, $length); case TruncateType::Character: default: return $this->truncateCharacter($value, $length); } }
public static function enumValue($class, $id) { if ($id === '' || $id === null || $id === false) { return '---'; } $class = new ReflectionClass($class); $values = $class->getConstants(); if (preg_match('/[0-9]+/', $id)) { $values = array_values($values); $id = isset($values[$id]) ? $values[$id] : ''; } return self::formatLabel(CPropertyValue::ensureEnum($id, $class->name)); }
/** * Responds to {@link CActiveRecord::onAfterSave} event. * Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}. * @param CModelEvent $event event parameter */ public function afterSave($event) { $data = array(); $objectId = $this->getOwner()->{$this->objectAttribute}; if ($this->useActiveField) { $data = $this->getOwner()->{$this->name}; if (!is_array($data) && !is_object($data)) { $data = array((int) $data); } } else { if (isset($_POST[$this->name])) { $data = $_POST[$this->name]; if (!is_array($data) && !is_object($data)) { $data = array((int) $data); } } } //delete old $sql = "DELETE FROM " . SITE_ID . '_' . "taxonomy_index t" . "\n USING " . SITE_ID . '_' . "taxonomy_term tt, " . SITE_ID . '_' . "taxonomy_vocabulary tv" . "\n WHERE tt.id = t.term_id AND tv.id = tt.v_id" . (is_numeric($this->taxonomy) ? "\n AND (tv.id = :id)" : "\n AND (tv.alias = :alias)") . "\n AND tv.module = :module AND t.object_id = :object_id"; if (count($data)) { foreach ($data as $index => $val) { $data[$index] = CPropertyValue::ensureInteger($val); } $dataString = implode(',', $data); $sql .= "\n AND t.term_id NOT IN ({$dataString})"; } $command = TermRelation::model()->getDbConnection()->createCommand($sql); if (is_numeric($this->taxonomy)) { $command->bindParam(":id", $this->taxonomy, PDO::PARAM_INT); } else { $command->bindParam(":alias", $this->taxonomy, PDO::PARAM_STR); } $command->bindParam(":module", $this->module, PDO::PARAM_STR); $command->bindParam(":object_id", $objectId, PDO::PARAM_INT); $command->execute(); //update/create if (count($data)) { foreach ($data as $val) { $relation = TermRelation::model()->findByAttributes(array('object_id' => $objectId, 'term_id' => $val)); if (!is_object($relation)) { $relation = new TermRelation(); } $relation->object_id = $objectId; $relation->term_id = $val; if (!$relation->save()) { Yii::log(CVarDumper::dumpAsString($relation->getErrors()), CLogger::LEVEL_ERROR); } } } }
private function prepareOutput() { $preparedAttributes = array(); foreach ($this->getAttributes() as $key => $value) { if (in_array($key, array('enableClientValidation', 'safe', 'skipOnError'))) { $preparedAttributes[$key] = CPropertyValue::ensureBoolean($value); } if ($key === 'except' || $key === 'on') { if (!is_null($value)) { $preparedAttributes[$key] = array_map('trim', explode(',', $value)); } } } return $preparedAttributes; }
public function beforeAction($action) { $this->scanModules('theme'); if (Yii::app()->theme) { $this->currentTheme = Yii::app()->theme->name; if (Theme::hasAdminForm($this->currentTheme)) { $model = Yii::app()->getComponent('wstheme')->getAdminModel($this->currentTheme); $this->currentTheme = $model->name; } } else { $this->currentTheme = "unknown"; } // Only old self-hosted customers can download/upgrade themes on their own. $canDisplayThemeGallery = CPropertyValue::ensureBoolean(Yii::app()->params['LIGHTSPEED_HOSTING']) === false && CPropertyValue::ensureBoolean(Yii::app()->params['ALLOW_LEGACY_THEMES']); $this->menuItems = array(array('label' => 'Manage My Themes', 'url' => array('theme/manage')), array('label' => 'Configure ' . ucfirst($this->currentTheme), 'url' => array('theme/module')), array('label' => 'Edit CSS for ' . ucfirst($this->currentTheme), 'url' => array('theme/editcss'), 'visible' => Theme::hasAdminForm(Yii::app()->theme->name)), array('label' => 'View Theme Gallery', 'url' => array('theme/gallery'), 'visible' => $canDisplayThemeGallery), array('label' => 'Upload Theme .Zip', 'url' => array('theme/upload'), 'visible' => !(Yii::app()->params['LIGHTSPEED_MT'] > 0)), array('label' => 'My Header/Image Gallery', 'url' => array('theme/image', 'id' => 1)), array('label' => 'Upload FavIcon', 'url' => array('theme/favicon'), 'visible' => !(Yii::app()->params['LIGHTSPEED_MT'] > 0))); //run parent beforeAction() after setting menu so highlighting works return parent::beforeAction($action); }
/** * dropDownList Taxonomy * * @param string $name * @param string $taxonomy * @param string $module * @param int $objectId * @param array $htmlOptions */ public static function dropDownList($name, $taxonomy, $module, $objectId, $htmlOptions = array()) { $properties = array('name' => $name, 'taxonomy' => $taxonomy, 'module' => $module, 'objectId' => $objectId); if (isset($htmlOptions['type'])) { $properties['type'] = CPropertyValue::ensureString($htmlOptions['type']); unset($htmlOptions['type']); } if (isset($htmlOptions['repeatChar'])) { $properties['repeatChar'] = CPropertyValue::ensureString($htmlOptions['repeatChar']); unset($htmlOptions['repeatChar']); } if (isset($htmlOptions['useRepeatChar'])) { $properties['useRepeatChar'] = CPropertyValue::ensureBoolean($htmlOptions['useRepeatChar']); unset($htmlOptions['useRepeatChar']); } $properties['htmlOptions'] = $htmlOptions; return Yii::app()->controller->widget('ListTaxonomy', $properties, true); }
/** * @return void */ public function actionIndex() { $model = new Tag('search'); $model->userId = Yii::app()->user->id; /* @var CHttpRequest $request */ $request = Yii::app()->request; if ($request->getQuery('pagesize') != null) { /* @var Setting $setting */ $setting = Setting::model()->name(Setting::PAGINATION_PAGE_SIZE_TAGS)->find(); $pageSize = CPropertyValue::ensureInteger($request->getQuery('pagesize')); if ($pageSize > 0) { $setting->value = $pageSize; $setting->save(); } } if (isset($_GET['Tag'])) { $model->attributes = $_GET['Tag']; } $this->render('index', array('model' => $model)); }
/** * Default action. * * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. * * @return void */ public function actionIndex() { $homePage = _xls_get_conf('HOME_PAGE', '*products'); switch ($homePage) { case "*index": if (Yii::app()->params['LIGHTSPEED_MT'] == '1') { if (Yii::app()->theme->info->showCustomIndexOption) { $this->render("/site/index"); } else { $this->forward("search/browse"); } } else { $this->render("/site/index"); } break; case "*products": $this->forward("search/browse"); break; default: //Custom Page $objCustomPage = CustomPage::LoadByKey($homePage); $productsGrid = null; $dataProvider = null; if (!$objCustomPage instanceof CustomPage) { _xls_404(); } $this->pageTitle = $objCustomPage->PageTitle; $this->pageDescription = $objCustomPage->meta_description; $this->pageImageUrl = ''; $this->breadcrumbs = array($objCustomPage->title => $objCustomPage->RequestUrl); if (CPropertyValue::ensureInteger($objCustomPage->product_display) === 2) { $productsGrid = new ProductGrid($objCustomPage->getProductGridCriteria()); } else { $dataProvider = $objCustomPage->taggedProducts(); } $this->canonicalUrl = $objCustomPage->canonicalUrl; $this->render('/custompage/index', array('model' => $objCustomPage, 'dataProvider' => $dataProvider, 'productsGrid' => $productsGrid)); break; } }
/** * @throws CHttpException * @return void */ public function actionSetSidebarPositions() { // only ajax-request are allowed if (!Yii::app()->request->isAjaxRequest) { throw new CHttpException(400); } $neededParams = array(Setting::MOST_VIEWED_ENTRIES_WIDGET_POSITION, Setting::RECENT_ENTRIES_WIDGET_POSITION, Setting::TAG_CLOUD_WIDGET_POSITION); // check if all needed params exist foreach ($neededParams as $paramName) { if (!isset($_POST[$paramName])) { throw new CHttpException(401); } } // save settings foreach ($neededParams as $paramName) { /* @var Setting $model */ $param = CPropertyValue::ensureInteger($_POST[$paramName]); $model = Setting::model()->findByAttributes(array('name' => $paramName)); $model->value = $param; $model->save(); } echo '1'; }
public function send($phones, $text) { $sender = $this->sender; $result = array(); foreach ($phones as $phone => $variables) { $variables = CPropertyValue::ensureArray($variables); $textMsg = $text; $i = 1; foreach ($variables as $variable) { $textMsg = str_replace('%' . $i . '%', $variable, $textMsg); $i++; } $args = array('login' => $this->username, 'password' => $this->password, 'messages' => array(array('clientId' => $sender, 'phone' => $phone, 'text' => $text))); $response = $this->doRequest(self::SEND_URL, $args); $responseText = CJSON::encode($response); $resultStatus = false; $credits = 0; $status = isset($response['status']) ? $response['status'] : 'no status'; if ($status == 'ok') { if (isset($response['messages']) == false || count($response['messages']) == 0) { throw new Exception('No messages in response'); } $message = $response['messages'][0]; $status = isset($message['status']) ? $message['status'] : 'no status'; $resultStatus = $status == 'accepted'; $response = $this->doRequest(self::CREDITS_URL, array('login' => $this->username, 'password' => $this->password)); if (isset($response['balance'])) { $credits = $response['balance'][0]['balance']; } else { throw new Exception('No credits in response'); } } $result = array('ok' => $status == 'ok', 'status' => $status, 'responseText' => $responseText, 'credits' => $credits, 'needSmsAlert' => true); } return $result; }
/** * We use this function to know if the payment method is allowed to be * used. * * @return bool True if we can display the payment method. False * otherwise. */ public function isDisplayable() { $allowAdvancedPayments = CPropertyValue::ensureBoolean(Yii::app()->params['ALLOW_ADVANCED_PAY_METHODS']); if ($allowAdvancedPayments === false && $this->advancedMode === true) { return false; } return parent::isDisplayable(); }
'); $relationshipsDataProvider = $this->getDataProvider(); ?> <div id="relationships-form" <?php ?> class="<?php echo $this->getWidgetProperty('mode') === 'simple' ? 'simple-mode' : 'full-mode'; ?> "> <?php $columns = array(array('name' => 'expandButton.', 'header' => '', 'value' => "in_array (\n get_class (\$data->relatedModel), \n QuickCRUDBehavior::getModelsWhichSupportQuickView ()) ?\n\n '<span class=\\'detail-view-toggle\\' title=\\'" . CHtml::encode(Yii::t('app', 'View inline record details')) . "\\'\n data-id=\\''.\$data->relatedModel->id.'\\'\n data-class=\\''.get_class (\$data->relatedModel).'\\'\n data-name=\\''.CHtml::encode (\$data->relatedModel->name).'\\'>\n <span class=\\'fa fa-caret-right\\'></span>\n <span class=\\'fa fa-caret-down\\' style=\\'display: none;\\'></span>\n </span>' : ''", 'type' => 'raw'), array('name' => 'name', 'header' => Yii::t("contacts", 'Name'), 'value' => '$data->renderAttribute ("name")', 'type' => 'raw'), array('name' => 'relatedModelName', 'header' => Yii::t("contacts", 'Type'), 'value' => '$data->renderAttribute ("relatedModelName")', 'filter' => array('' => CHtml::encode(Yii::t('app', '-Select one-'))) + $linkableModelsOptions, 'type' => 'raw'), array('name' => 'assignedTo', 'header' => Yii::t("contacts", 'Assigned To'), 'value' => '$data->renderAttribute("assignedTo")', 'type' => 'raw'), array('name' => 'label', 'header' => Yii::t("contacts", 'Label'), 'value' => '$data->renderAttribute("label")', 'type' => 'raw'), array('name' => 'createDate', 'header' => Yii::t('contacts', 'Create Date'), 'value' => '$data->renderAttribute("createDate")', 'filterType' => 'date', 'type' => 'raw')); $columns[] = array('name' => 'deletion.', 'header' => Yii::t("contacts", 'Delete'), 'htmlOptions' => array('class' => 'delete-button-cell'), 'value' => "\n CHtml::ajaxLink(\n '<span class=\\'fa fa-times x2-delete-icon\\'></span>',\n '" . Yii::app()->controller->createUrl('/site/deleteRelationship') . "?firstId='.\$data->relatedModel->id.\n '&firstType='.get_class(\$data->relatedModel).\n '&secondId=" . $model->id . "&secondType=" . get_class($model) . "&redirect=/" . Yii::app()->controller->getId() . "/" . $model->id . "',\n array (\n 'success' => 'function () {\n \$.fn.yiiGridView.update(\\'relationships-grid\\');\n }',\n ),\n array(\n 'class'=>'x2-hint',\n 'title'=>'Deleting this relationship will not delete the linked record.',\n 'confirm'=>'Are you sure you want to delete this relationship?'))", 'type' => 'raw'); $this->widget('InlineRelationshipsGridView', array('id' => "relationships-grid", 'possibleResultsPerPage' => array(5, 10, 20, 30, 40, 50, 75, 100), 'enableGridResizing' => false, 'showHeader' => CPropertyValue::ensureBoolean($this->getWidgetProperty('showHeader')), 'hideFullHeader' => CPropertyValue::ensureBoolean($this->getWidgetProperty('hideFullHeader')), 'resultsPerPage' => $this->getWidgetProperty('resultsPerPage'), 'sortableWidget' => $this, 'defaultGvSettings' => array('expandButton.' => '12', 'name' => '22%', 'relatedModelName' => '18%', 'assignedTo' => '18%', 'label' => '18%', 'createDate' => '15%', 'deletion.' => 70), 'filter' => $this->getFilterModel(), 'htmlOptions' => array('class' => $relationshipsDataProvider->itemCount < $relationshipsDataProvider->totalItemCount ? 'grid-view has-pager' : 'grid-view'), 'dataColumnClass' => 'X2DataColumnGeneric', 'gvSettingsName' => 'inlineRelationshipsGrid', 'baseScriptUrl' => Yii::app()->request->baseUrl . '/themes/' . Yii::app()->theme->name . '/css/gridview', 'template' => '<div class="title-bar">{summary}</div>{items}{pager}', 'afterAjaxUpdate' => 'js: function(id, data) { refreshQtip(); }', 'dataProvider' => $relationshipsDataProvider, 'columns' => $columns, 'enableColDragging' => false, 'rememberColumnSort' => false)); ?> </div> <!----> <?php if ($hasUpdatePermissions) { Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/Relationships.js'); ?> <div class='clearfix'></div> <form id='new-relationship-form' class="form" style='display: none;'> <input type="hidden" id='ModelId' name="ModelId" value="<?php echo $model->id; ?>
/** * Used for general category browsing (which is really a search by category or family) * The URL manager passes the category request_url which we look up here */ public function actionBrowse() { $strC = Yii::app()->getRequest()->getQuery('cat'); $strB = Yii::app()->getRequest()->getQuery('brand'); $strS = Yii::app()->getRequest()->getQuery('class_name'); $strInv = ''; //If we haven't passed any criteria, we just query the database $criteria = new CDbCriteria(); $criteria->alias = 'Product'; if (!empty($strC)) { $objCategory = Category::LoadByRequestUrl($strC); if ($objCategory) { $criteria->join = 'LEFT JOIN xlsws_product_category_assn as ProductAssn ON ProductAssn.product_id=Product.id'; $intIdArray = array($objCategory->id); $intIdArray = array_merge($intIdArray, $objCategory->GetBranchPath()); $criteria->addInCondition('category_id', $intIdArray); $this->pageTitle = $objCategory->PageTitle; $this->pageDescription = $objCategory->PageDescription; $this->pageImageUrl = $objCategory->CategoryImage; $this->breadcrumbs = $objCategory->Breadcrumbs; $this->pageHeader = Yii::t('category', $objCategory->label); $this->subcategories = $objCategory->getSubcategoryTree($this->MenuTree); if ($objCategory->custom_page) { $this->custom_page_content = $objCategory->customPage->page; } $this->canonicalUrl = $objCategory->getCanonicalUrl(); } } if (!empty($strB)) { $objFamily = Family::LoadByRequestUrl($strB); if ($objFamily) { $criteria->addCondition('family_id = :id'); $criteria->params = array(':id' => $objFamily->id); $this->pageTitle = $objFamily->PageTitle; $this->pageHeader = $objFamily->family; $this->canonicalUrl = $objFamily->getCanonicalUrl(); } } if (!empty($strS)) { $objClasses = Classes::LoadByRequestUrl($strS); if ($objClasses) { $criteria->addCondition('class_id = :id'); $criteria->params = array(':id' => $objClasses->id); $this->pageHeader = $objClasses->class_name; $this->canonicalUrl = $objClasses->getCanonicalUrl(); } } if (_xls_get_conf('INVENTORY_OUT_ALLOW_ADD') == Product::InventoryMakeDisappear) { $criteria->addCondition('(inventory_avail>0 OR inventoried=0)'); } if (!_xls_get_conf('CHILD_SEARCH') || empty($strQ)) { $criteria->addCondition('Product.parent IS NULL'); } if (Product::HasFeatured() && empty($strS) && empty($strB) && empty($strC)) { $criteria->addCondition('featured=1'); $this->pageHeader = 'Featured Products'; } $criteria->addCondition('web=1'); $criteria->addCondition('current=1'); $criteria->order = 'Product.' . _xls_get_sort_order(); $productsGrid = new ProductGrid($criteria); $this->returnUrl = $this->canonicalUrl; $this->pageImageUrl = ""; if ($strB == '*') { $familiesCriteria = new CDbCriteria(); $familiesCriteria->order = 'family'; if (CPropertyValue::ensureBoolean(Yii::app()->params['DISPLAY_EMPTY_CATEGORY']) === false) { $familiesCriteria->addCondition('child_count > 0'); } $families = Family::model()->findAll($familiesCriteria); $this->render('brands', array('model' => $families)); } else { $this->render('grid', array('model' => $productsGrid->getProductGrid(), 'item_count' => $productsGrid->getNumberOfRecords(), 'page_size' => Yii::app()->params['PRODUCTS_PER_PAGE'], 'items_count' => $productsGrid->getNumberOfRecords(), 'pages' => $productsGrid->getPages())); } }
public function setScopes ($scopes) { $this->_scopes = CPropertyValue::ensureArray($scopes); }
/** * Inserts a row into the table based on this active record attributes. * If the table's primary key is auto-incremental and is null before insertion, * it will be populated with the actual value after insertion. * Note, validation is not performed in this method. You may call {@link validate} to perform the validation. * After the record is inserted to DB successfully, its {@link isNewRecord} property will be set false, * and its {@link scenario} property will be set to be 'update'. * @param array $attributes list of attributes that need to be saved. Defaults to null, * meaning all attributes that are loaded from DB will be saved. * @return boolean whether the attributes are valid and the record is inserted successfully. * @throws CException if the record is not new * @throws EMongoException on fail of insert or insert of empty document * @throws MongoCursorException on fail of insert, when safe flag is set to true * @throws MongoCursorTimeoutException on timeout of db operation , when safe flag is set to true * @since v1.0 */ public function insert(array $attributes = null) { if (!$this->getIsNewRecord()) { throw new CDbException(Yii::t('yii', 'The EMongoDocument cannot be inserted to database because it is not new.')); } if ($this->beforeSave()) { Yii::trace(get_class($this) . '.insert()', 'ext.MongoDb.EMongoDocument'); $rawData = $this->toArray(); // free the '_id' container if empty, mongo will not populate it if exists if (empty($rawData['_id'])) { unset($rawData['_id']); } // filter attributes if set in param if ($attributes !== null) { foreach ($rawData as $key => $value) { if (!in_array($key, $attributes)) { unset($rawData[$key]); } } } //by yongze add 查看入库数组 if (defined('ENABLE_DEBUGMONGODATA') && ENABLE_DEBUGMONGODATA === true) { // FunctionUTL::Debug($rawData); } // FunctionUTL::Debug($rawData);exit; //开启 if (version_compare(Mongo::VERSION, '1.0.5', '>=') === true) { $result = $this->getCollection()->insert($rawData, array('fsync' => $this->getFsyncFlag(), 'safe' => $this->getSafeFlag())); } else { $result = $this->getCollection()->insert($rawData, CPropertyValue::ensureBoolean($this->getSafeFlag())); } if ($result !== false) { $this->_id = $rawData['_id']; $this->setIsNewRecord(false); $this->setScenario('update'); $this->afterSave(); return true; } throw new EMongoException(Yii::t('yii', 'Can\\t save document to disk, or try to save empty document!')); } return false; }
/** * Format log entry * * @param array $entry * @return array */ public function formatLogEntry(array $entry) { // extract query from the entry $queryString = $entry[0]; $sqlStart = strpos($queryString, '(') + 1; $sqlEnd = strrpos($queryString, ')'); $sqlLength = $sqlEnd - $sqlStart; $queryString = substr($queryString, $sqlStart, $sqlLength); if (false !== strpos($queryString, '. Bound with ')) { list($query, $params) = explode('. Bound with ', $queryString); $binds = array(); $matchResult = preg_match_all("/(?<key>[a-z0-9\\.\\_\\-\\:]+)=(?<value>[\\d\\.e\\-\\+]+|''|'.+?(?<!\\\\)')/ims", $params, $paramsMatched, PREG_SET_ORDER); if ($matchResult) { foreach ($paramsMatched as $paramsMatch) { if (isset($paramsMatch['key'], $paramsMatch['value'])) { $binds[':' . trim($paramsMatch['key'], ': ')] = trim($paramsMatch['value']); } } } $entry[0] = strtr($query, $binds); } else { $entry[0] = $queryString; } if (false !== CPropertyValue::ensureBoolean($this->highlightSql)) { $entry[0] = $this->getTextHighlighter()->highlight($entry[0]); } $entry[0] = strip_tags($entry[0], '<div>,<span>'); return $entry; }
public function setId($value) { $this->id = CPropertyValue::ensureString($value); }
/** * Format log entry * * @param array $entry * @return array */ public function formatLogEntry(array $entry) { // extract query from the entry $queryString = $entry[0]; $sqlStart = strpos($queryString, '(') + 1; $sqlEnd = strrpos($queryString, ')'); $sqlLength = $sqlEnd - $sqlStart; $queryString = substr($queryString, $sqlStart, $sqlLength); if (false !== strpos($queryString, '. Bound with ')) { list($query, $params) = explode('. Bound with ', $queryString); $params = explode(',', $params); $binds = array(); foreach ($params as $param) { list($key, $value) = explode('=', $param, 2); $binds[trim($key)] = trim($value); } $entry[0] = strtr($query, $binds); } else { $entry[0] = $queryString; } if (false !== CPropertyValue::ensureBoolean($this->highlightSql)) { $entry[0] = $this->getTextHighlighter()->highlight($entry[0]); } $entry[0] = strip_tags($entry[0], '<div>,<span>'); return $entry; }
/** * Short Description. * * @return void */ public function actionEdit() { $id = Yii::app()->getRequest()->getQuery('id'); $model = Configuration::model()->findAllByAttributes(array('configuration_type_id' => $id), array('order' => 'sort_order')); if ($this->IsCloud) { $model = $this->sanitizeEditModule($model, 'Cloud'); } if ($this->IsMT) { $model = $this->sanitizeEditModule($model, 'MT'); } if ($this->isHosted) { $model = $this->sanitizeEditModule($model, 'Hosted'); } if (isset($_POST['Configuration'])) { $valid = true; foreach ($model as $i => $item) { if (isset($_POST['Configuration'][$i])) { $item->attributes = $_POST['Configuration'][$i]; } if ($item->key_name == 'LANG_MENU' && $item->key_value == 1) { $itemLanguages = $model[2]; $itemLanguages->attributes = $_POST['Configuration'][2]; if (empty($itemLanguages->key_value)) { $valid = false; } } if ($item->options == "INT") { if ((int) $item->key_value) { $valid = true; } else { $valid = false; } } if ($item->options == "EMAIL") { $valid = $this->validateEmail($item) && $valid; } else { $valid = $item->validate() && $valid; } if (!$valid) { if ($item->options == 'EMAIL') { Yii::app()->user->setFlash('error', $item->title . ' is not a valid email address'); } elseif ($item->key_name == 'LANG_MENU') { Yii::app()->user->setFlash('error', 'Languages field cannot be empty when language menu is enabled'); } elseif ($item->options == "INT") { Yii::app()->user->setFlash('error', $item->title . ': ' . 'Only numbers are allowed', true); } else { $err = $item->getErrors(); Yii::app()->user->setFlash('error', $item->title . ' -- ' . print_r($err['key_value'][0], true)); } break; } } if ($valid) { foreach ($model as $i => $item) { $item->attributes = $_POST['Configuration'][$i]; if ($item->options == "PASSWORD") { $item->key_value = _xls_encrypt($item->key_value); } if ($item->save() === false) { Yii::app()->user->setFlash('error', print_r($item->getErrors(), true)); } else { Yii::app()->user->setFlash('success', Yii::t('admin', 'Configuration updated on {time}.', array('{time}' => date('d F, Y h:i:sa')))); $item->postConfigurationChange(); } if ($item->key_name == 'EMAIL_TEST' && $item->key_value == 1) { $this->sendEmailTest(); } } } } foreach ($model as $i => $item) { if ($item->options == 'BOOL') { $this->registerOnOff($item->id, "Configuration_{$i}_key_value", $item->key_value); } if ($item->options == 'PASSWORD') { $model[$i]->key_value = _xls_decrypt($model[$i]->key_value); } $model[$i]->title = Yii::t('admin', $item->title, array('{color}' => _xls_regionalize('color'), '{check}' => _xls_regionalize('check'))); $model[$i]->helper_text = Yii::t('admin', $item->helper_text, array('{color}' => _xls_regionalize('color'), '{check}' => _xls_regionalize('check'))); } /* * http://www.yiiframework.com/doc/api/1.1/CModel#generateAttributeLabel-detail * * Unless we define the label attribute in activeLabelEx htmlOptions in the view, * the label will be generated when it calls CModel::generateAttributeLabel(). * This is a problem for the labels we want to display on pages like the Google Integration * page that have labels which deliberately require dashes and camel-case formatting. */ $defineLabel = false; switch (CPropertyValue::ensureInteger($id)) { case 20: // IntegrationController::GOOGLE = 20 $defineLabel = true; break; default: break; } $this->render('admin.views.default.edit', array('model' => $model, 'defineLabel' => $defineLabel)); }
/** * @return array the config array passed to widget () */ public function getGridViewConfig() { if (!isset($this->_gridViewConfig)) { $this->_gridViewConfig = array_merge(parent::getGridViewConfig(), array('sortableWidget' => $this, 'id' => $this->getWidgetKey(), 'enableScrollOnPageChange' => false, 'possibleResultsPerPage' => array(5, 10, 20, 30, 40, 50, 75, 100), 'buttons' => array('advancedSearch', 'clearFilters', 'columnSelector', 'autoResize'), 'template' => CHtml::openTag('div', X2Html::mergeHtmlOptions(array('class' => 'page-title'), array('style' => !CPropertyValue::ensureBoolean($this->getWidgetProperty('showHeader')) && !CPropertyValue::ensureBoolean($this->getWidgetProperty('hideFullHeader')) ? 'display: none;' : ''))) . '<h2 class="grid-widget-title-bar-dummy-element">' . '</h2>{buttons}{filterHint}' . '{summary}{topPager}<div class="clear"></div></div>{items}{pager}', 'fixedHeader' => false, 'dataProvider' => $this->dataProvider, 'filter' => $this->model, 'pager' => array('class' => 'CLinkPager', 'maxButtonCount' => 10), 'modelName' => get_class($this->model), 'viewName' => 'profile', 'gvSettingsName' => get_called_class() . $this->widgetUID, 'enableControls' => true, 'fullscreen' => false, 'enableSelectAllOnAllPages' => false)); } return $this->_gridViewConfig; }
/** * @param boolean $value set is panel enabled */ public function setEnabled($value) { $this->_enabled = CPropertyValue::ensureBoolean($value); }