public function run() { $this->log("Start parse"); $currenciesList = CHtml::listData(Currency::model()->findAll(), 'code', function ($data) { return $data; }); $url = "http://www.cbr.ru/scripts/XML_daily.asp"; // URL, XML документ, всегда содержит актуальные данные $rate = null; // загружаем полученный документ в дерево XML if (!($xml = simplexml_load_file($url))) { $this->log("XML loading error"); die('XML loading error'); } foreach ($xml->Valute as $m) { $code = strtolower($m->CharCode); if (key_exists($code, $currenciesList)) { $rate = (double) str_replace(",", ".", (string) $m->Value); $this->log("Rate {$code} is: " . $rate); if (!empty($rate)) { $currency = $currenciesList[$code]; $currency->rate = $rate; if ($currency->update(['rate'])) { $this->log("Rate {$code} saved successfully"); } else { $this->log("Rate {$code} not saved"); } } else { $this->log("Rate {$code} is empty"); } } } $this->log("Finish parse"); }
/** * @param $attribute * @param $value * @return string */ public static function renderValue(Attribute $attribute, $value, $template = '<p>{item}</p>') { $unit = $attribute->unit ? ' ' . $attribute->unit : ''; $res = null; switch ($attribute->type) { case Attribute::TYPE_TEXT: case Attribute::TYPE_SHORT_TEXT: case Attribute::TYPE_NUMBER: $res = $value; break; case Attribute::TYPE_DROPDOWN: $data = CHtml::listData($attribute->options, 'id', 'value'); if (is_array($value)) { $value = array_shift($value); } if (isset($data[$value])) { $res .= $data[$value]; } break; case Attribute::TYPE_CHECKBOX_LIST: $data = CHtml::listData($attribute->options, 'id', 'value'); if (is_array($value)) { foreach (array_intersect(array_keys($data), $value) as $val) { $res .= strtr($template, ['{item}' => $data[$val]]); } } break; case Attribute::TYPE_CHECKBOX: $res = $value ? Yii::t("StoreModule.store", "Yes") : Yii::t("StoreModule.store", "No"); break; } return $res . $unit; }
/** * @param array $variables * * @throws HttpException */ public function actionEditOrder(array $variables = []) { $this->requireAdmin(); $variables['orderSettings'] = craft()->market_orderSettings->getByHandle('order'); if (empty($variables['order'])) { if (!empty($variables['orderId'])) { $variables['order'] = craft()->market_order->getById($variables['orderId']); if (!$variables['order']->id) { throw new HttpException(404); } } else { $variables['order'] = new Market_OrderModel(); } } if (!empty($variables['orderId'])) { $variables['title'] = "Order " . substr($variables['order']->number, 0, 7); } else { $variables['title'] = Craft::t('Create a new Order'); } $variables['orderStatuses'] = \CHtml::listData(craft()->market_orderStatus->getAll(), 'id', 'name'); if ($variables['order']->orderStatusId == null) { $variables['orderStatuses'] = ['0' => 'No Status'] + $variables['orderStatuses']; } $this->prepVariables($variables); $this->renderTemplate('market/orders/_edit', $variables); }
public function actionSorting($root_id, $menu_id) { if (isset($_POST['tree'])) { $model = new MenuSection(); $this->performAjaxValidation($model); //при сортировке дерева параметры корня измениться не могут, //поэтоtму его вообще сохранять не будем $data = json_decode($_POST['tree']); array_shift($data); //получаем большие case для update $update = []; $js_to_sql_mapping = ['depth' => 'level', 'left' => 'left', 'right' => 'right']; foreach ($js_to_sql_mapping as $js_field => $field) { $update_data = CHtml::listData($data, 'item_id', $js_field); $update[] = "t.{$field} = " . SqlHelper::arrToCase('id', $update_data, 't'); } $in = implode(', ', array_values(CHtml::listData($data, 'item_id', 'item_id'))); $condition = "t.level > 1"; $command = Yii::app()->db->commandBuilder->createSqlCommand("UPDATE `{$model->tableName()}` as t SET " . implode(', ', $update) . " WHERE {$condition} AND t.id IN ({$in})"); $command->execute(); echo CJSON::encode(['status' => 'ok', 'redirect' => $this->createUrl('manage', ['menu_id' => $menu_id])]); Yii::app()->end(); } $this->render('sorting', ['root_id' => $root_id, 'menu_id' => $menu_id]); }
public function actionSorting() { if (isset($_POST['tree'])) { $model = new Category(); $this->performAjaxValidation($model); //при сортировке дерева параметры корня измениться не могут, //поэтоtму его вообще сохранять не будем $data = json_decode($_POST['tree']); array_shift($data); //получаем большие case для update $update = array(); $nestedSortableFields = array('depth' => Category::DEPTH, 'left' => Category::LFT, 'right' => Category::RGT); foreach ($nestedSortableFields as $key => $field) { $update_data = CHtml::listData($data, 'item_id', $key); $update[] = "{$field} = " . SqlHelper::arrToCase('id', $update_data); } //обновляем всю таблицу, кроме рута $condition = Category::DEPTH . " > 1"; $command = Yii::app()->db->commandBuilder->createSqlCommand("UPDATE `{$model->tableName()}` SET " . implode(', ', $update) . " WHERE {$condition}"); $command->execute(); echo CJSON::encode(array('status' => 'ok', 'redirect' => $this->createUrl('manage'))); Yii::app()->end(); } $this->render('sorting'); }
public function SearchID($subject_name) { $subject_name = trim($subject_name, " \n\t"); if ($subject_name == 'республика Чувашская') { $subject_name = 'Чувашская республика'; } $subjects = $this->findAll(); $_RF_SUBJECTS = CHtml::listData($subjects, 'id', 'name'); $result = $this->gs_array_search($subject_name, $_RF_SUBJECTS); if (!$result) { $_RF_SUBJECTS = CHtml::listData($subjects, 'id', 'name_full'); $result = $this->gs_array_search($subject_name, $_RF_SUBJECTS); } if (!$result) { $subject_name = explode(' ', $subject_name); foreach ($subject_name as $s) { $ls = mb_strtolower($s, 'UTF-8'); if ($ls == 'республика' || $ls == 'край' || $ls == 'область' || $ls == 'округ') { continue; } $result = $this->gs_array_search($s, $_RF_SUBJECTS); if ($result) { break; } } } return $result; }
public function actionSetSorters() { $sql = 'SELECT id, name_' . Yii::app()->language . ' AS name FROM {{location_country}} ORDER BY name_' . Yii::app()->language . ' ASC'; $res = Yii::app()->db->createCommand($sql)->queryAll(); $countries = CHtml::listData($res, 'id', 'name'); $co = 1; foreach ($countries as $coid => $coname) { $sql = 'UPDATE {{location_country}} SET sorter="' . $co . '" WHERE id = ' . $coid . ' LIMIT 1'; Yii::app()->db->createCommand($sql)->execute(); $sql = 'SELECT id, name_' . Yii::app()->language . ' AS name FROM {{location_region}} WHERE country_id = :country ORDER BY name_' . Yii::app()->language . ' ASC'; $res = Yii::app()->db->createCommand($sql)->queryAll(true, array(':country' => $coid)); $regions = CHtml::listData($res, 'id', 'name'); $r = 1; foreach ($regions as $rid => $rname) { $sql = 'UPDATE {{location_region}} SET sorter="' . $r . '" WHERE id = ' . $rid . ' LIMIT 1'; Yii::app()->db->createCommand($sql)->execute(); $sql = 'SELECT id, name_' . Yii::app()->language . ' AS name FROM {{location_city}} WHERE region_id = :region ORDER BY name_' . Yii::app()->language . ' ASC'; $res = Yii::app()->db->createCommand($sql)->queryAll(true, array(':region' => $rid)); $cities = CHtml::listData($res, 'id', 'name'); $c = 1; foreach ($cities as $cid => $cname) { $sql = 'UPDATE {{location_city}} SET sorter="' . $c . '" WHERE id = ' . $cid . ' LIMIT 1'; Yii::app()->db->createCommand($sql)->execute(); $c++; } $r++; } $co++; } echo 'ok'; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['EvaAttributesMatrix'])) { $model->attributes = $_POST['EvaAttributesMatrix']; if ($model->save()) { $this->redirect(['index']); } } $dropDownData = []; $survObjCriteria = new CDbCriteria(); $survObjCriteria->with = ['options']; $survObjCriteria->select = 'inputName'; $survObjCriteria->condition = "inputName='survObj' AND options.frameworkFieldId=t.id"; $rsSurveillanceObjective = FrameworkFields::model()->find($survObjCriteria); $dropDownData['objectives'] = CHtml::listData($rsSurveillanceObjective->options, 'optionId', 'label'); $rsQuestionGrp = EvaQuestionGroups::model()->find(['select' => 'questions']); $questionsArray = array_keys((array) json_decode($rsQuestionGrp->questions)); $dropDownData['groups'] = array_combine($questionsArray, range(1, count($questionsArray))); //print_r($dropDownData['groups']); die; $dropDownData['attributes'] = CHtml::listData(EvaAttributes::model()->findAll(), 'attributeId', 'name'); $this->menu = [['label' => 'Add Attribute Relevance', 'url' => $this->createUrl('create')], ['label' => 'List Attribute Relevance', 'url' => $this->createUrl('index')]]; $this->render('update', ['model' => $model, 'dropDownData' => $dropDownData]); }
/** * Create/Edit TaxZone * * @param array $variables * * @throws HttpException */ public function actionEdit(array $variables = []) { $this->requireAdmin(); if (empty($variables['taxZone'])) { if (!empty($variables['id'])) { $id = $variables['id']; $variables['taxZone'] = craft()->market_taxZone->getById($id); if (!$variables['taxZone']->id) { throw new HttpException(404); } } else { $variables['taxZone'] = new Market_TaxZoneModel(); } } if (!empty($variables['id'])) { $variables['title'] = $variables['taxZone']->name; } else { $variables['title'] = Craft::t('Create a Tax Zone'); } $countries = craft()->market_country->getAll(); $states = craft()->market_state->getAll(); $variables['countries'] = \CHtml::listData($countries, 'id', 'name'); $variables['states'] = \CHtml::listData($states, 'id', 'name'); $this->renderTemplate('market/settings/taxzones/_edit', $variables); }
public static function getCommentsByPage($id, $classify, $page = 1, $pageSize = 30, $field = "id,uid,username,logid,tocommentid,content,cTime") { if (!$id || !$classify) { return array(); } $page = $page <= 1 ? 1 : $page; $pageSize = !$pageSize ? 30 : $pageSize; $limitStart = ($page - 1) * $pageSize; $sql = "SELECT {$field} FROM {{comments}} WHERE logid='{$id}' AND classify='{$classify}' AND status=" . Posts::STATUS_PASSED . " ORDER BY cTime LIMIT {$limitStart},{$pageSize}"; $items = Yii::app()->db->createCommand($sql)->queryAll(); if (!empty($items)) { $uids = array_filter(array_keys(CHtml::listData($items, 'uid', ''))); $uidsStr = join(',', $uids); if ($uidsStr != '') { $usernames = Yii::app()->db->createCommand("SELECT id,truename FROM {{users}} WHERE id IN({$uidsStr})")->queryAll(); if (!empty($usernames)) { foreach ($items as $k => $val) { foreach ($usernames as $val2) { if ($val['uid'] > 0 && $val['uid'] == $val2['id']) { $items[$k]['loginUsername'] = $val2['truename']; } } } } } } return $items; }
public function layout($model) { echo CHtml::openTag('div', array('class' => 'widget categories content-inner widget_post_category')); if ($this->data('title') != '') { echo CHtml::openTag('h3', array('class' => 'main-color widget_header')); echo $this->data('title'); echo CHtml::closeTag('h3'); } echo CHtml::openTag('div', array('class' => 'row')); echo CHtml::openTag('div', array('class' => 'col-xs-12')); $first = true; $end = CHtml::listData($model, 'ID', 'ID'); foreach ($model as $post) { if ($this->data('showThumbPost')) { echo CHtml::openTag('div', array('class' => 'single_comments')); echo "<span>"; if ($post->post_image != '') { echo CHtml::image(Helper::getThumb('content', $post->post_image)); } echo "</span>"; $this->getLink($post, true, $this->data('showExcerpt'), 20); echo CHtml::closeTag('div'); } else { echo CHtml::openTag('div', array('class' => 'single_comments')); $this->getLink($post, true, $this->data('showExcerpt'), $this->data('batasJudul')); echo CHtml::closeTag('div'); } } if ($this->data('showIndexLink')) { echo CHtml::Link('<i class="glyphicon glyphicon-plus"></i> Indeks ', array('indeks/populer'), array('class' => 'indeks')); } echo CHtml::closeTag('div'); echo CHtml::closeTag('div'); echo CHtml::closeTag('div'); }
public function insertOrUpdate($relatedType, $relatedId, $lang, $currentKeywords) { $currentKeywordList = self::convert2Array($currentKeywords); $criteria = new CDbCriteria(); $criteria->compare('related_type', $relatedType); $criteria->compare('related_id', $relatedId); $criteria->compare('lang', $lang); $keywords = self::model()->findAll($criteria); $oldKeywordList = CHtml::listData($keywords, 'internal_link_keyword_id', 'keyword'); $flag = 0; // 需要删除的 $deleteKeywordList = array_diff($oldKeywordList, $currentKeywordList); $criteria = new CDbCriteria(); $criteria->compare('related_type', $relatedType); $criteria->compare('related_id', $relatedId); $criteria->compare('lang', $lang); $criteria->addInCondition('keyword', $deleteKeywordList); $flag += self::model()->deleteAll($criteria); // 需要添加的 $addKeywordsList = array_diff($currentKeywordList, $oldKeywordList); foreach ($addKeywordsList as $addKeyword) { $keyword = new self(); $keyword->related_type = $relatedType; $keyword->related_id = $relatedId; $keyword->lang = $lang; $keyword->keyword = $addKeyword; if ($keyword->save()) { $flag++; } } return $flag; }
/** * Authenticates a user. * @return boolean whether authentication succeeds. */ public function authenticate() { $user = User::model()->findByAttributes(array('username' => $this->username)); if ($user === null) { // No user found! $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ($user->password !== SHA1($this->password)) { // Invalid password! $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { // Okay! if (!$user->admin) { $ARData = DeviceUser::model()->with('device')->findAllByAttributes(array('user_id' => $user->id)); $devices = CHtml::listData($ARData, 'device_id', 'device.reference'); $menu = array(); $mydevices = array(); foreach ($devices as $id => $name) { $menu[] = array('label' => $name, 'url' => '/client/status/' . $id); $mydevices[] = $id; } $this->setState('clientMenu', $menu); $this->setState('devices', $mydevices); } $this->setState('isAdmin', $user->admin ? true : false); $this->_id = $user->id; $this->errorCode = self::ERROR_NONE; } } return !$this->errorCode; }
public function layout($model) { echo CHtml::openTag('div', array('class' => 'widget categories content-inner ')); if ($this->data('title') != '') { echo CHtml::openTag('h3', array('class' => 'main-color widget_header')); echo $this->data('title'); echo CHtml::closeTag('h3'); } echo CHtml::openTag('div', array('class' => 'row')); echo CHtml::openTag('div', array('class' => 'col-xs-12')); $first = true; $end = CHtml::listData($model, 'ID', 'ID'); foreach ($model as $post) { if ($this->data('showThumbPost')) { echo CHtml::openTag('div', array('class' => 'single_comments')); if ($this->getFoto($post) != '') { echo CHtml::image(Helper::getThumb('content', $this->getFoto($post))); } $this->getLink($post); echo CHtml::closeTag('div'); } else { echo CHtml::openTag('div', array('class' => 'single_comments')); $this->getLink($post); echo CHtml::closeTag('div'); } } if ($this->data('showIndexLink')) { echo CHtml::Link('<i class="fa fa-angle-double-right"></i> Index Photo', array('/photohome'), array('class' => 'indeks')); } echo CHtml::closeTag('div'); echo CHtml::closeTag('div'); echo CHtml::closeTag('div'); }
public static function getVariantsValuesList() { if (self::$_variantsValuesList === null) { self::$_variantsValuesList = CHtml::listData(EavVariant::model()->findAll(), 'id', 'title'); } return self::$_variantsValuesList; }
public function layout($model) { echo CHtml::openTag('div', array('class' => 'widget categories content-inner widget_post_category')); if ($this->data('title') != '') { echo CHtml::openTag('h3', array('class' => 'main-color widget_header')); echo $this->data('title'); echo CHtml::closeTag('h3'); } echo CHtml::openTag('div', array('class' => 'row')); echo CHtml::openTag('div', array('class' => 'col-xs-12')); $first = true; $end = CHtml::listData($model->posts($this->criteria()), 'ID', 'ID'); foreach ($model->posts($this->criteria()) as $post) { if ($this->data('showThumbPost')) { echo CHtml::openTag('div', array('class' => 'single_comments')); echo "<span>"; if ($post->post_image != '') { echo CHtml::image(Helper::getThumb('content', $post->post_image)); } echo "</span>"; $this->getLink($post, $this->data('showIntro')); echo CHtml::closeTag('div'); } else { echo CHtml::openTag('div', array('class' => 'single_comments')); $this->getLink($post, $this->data('showIntro')); echo CHtml::closeTag('div'); } } if ($this->data('showIndexLink')) { echo CHtml::Link('<i class="glyphicon glyphicon-plus"></i> Indeks', array('/label/index', 'id' => $model->term_id, 'slug' => $model->slug), array('class' => 'indeks')); } echo CHtml::closeTag('div'); echo CHtml::closeTag('div'); echo CHtml::closeTag('div'); }
protected function refreshEavAttributes() { $attachedEavAttributes = $this->attachedEavAttributes; $oldEavAttributes = EavAttributeToSet::model()->findAllByAttributes(array('eav_set_id' => $this->id)); $orderArray = CHtml::listData($oldEavAttributes, 'eav_attribute_id', 'weight'); EavAttributeToSet::model()->deleteAllByAttributes(array('eav_set_id' => $this->id)); if (is_array($attachedEavAttributes)) { $counter = end($orderArray) + 10; //var_dump($counter); //exit(); foreach ($attachedEavAttributes as $key => $id) { if (EavAttribute::model()->exists('t.id = :id', array(':id' => $id))) { $rel = new EavAttributeToSet(); $rel->eav_set_id = $this->id; $rel->eav_attribute_id = $id; if (key_exists($id, $orderArray)) { $rel->weight = $orderArray[$id]; } else { $rel->weight = $counter; $counter += 10; } $rel->save(); } } } }
public function actionAddPaid($id = 0, $withDate = 0) { $model = new AddToUserForm(); $tariffs = TariffPlans::getAllTariffPlans(true, true); $tariffsArray = CHtml::listData($tariffs, 'id', 'name'); $request = Yii::app()->request; $data = $request->getPost('AddToUserForm'); if ($data) { $userId = $request->getPost('user_id'); $withDate = $request->getPost('withDate'); $model->attributes = $data; if ($model->validate()) { $user = User::model()->findByPk($userId); $tariff = TariffPlans::getFullTariffInfoById($model->tariff_id); if (!$tariff || !$user) { throw new CException('Not valid data'); } if (TariffPlans::applyToUser($userId, $tariff['id'], $model->date_end, null, true)) { echo CJSON::encode(array('status' => 'ok', 'userId' => $userId, 'html' => TariffPlans::getTariffPlansHtml($withDate, true, $user))); Yii::app()->end(); } } else { echo CJSON::encode(array('status' => 'err', 'html' => $this->renderPartial('_add_to_user', array('id' => $userId, 'model' => $model, 'withDate' => $withDate, 'tariffsArray' => $tariffsArray), true))); Yii::app()->end(); } } $renderData = array('id' => $id, 'model' => $model, 'withDate' => $withDate, 'tariffsArray' => $tariffsArray); if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('_add_to_user', $renderData); } else { $this->render('_add_to_user', $renderData); } }
public function actionCities() { $region_id = Yii::app()->request->getQuery('region_id', 0); $cities = BglGeoCity::model()->findAllByAttributes(array('regionid' => $region_id)); print json_encode(CHtml::listData($cities, 'id', 'name')); Yii::app()->end(); }
/** * 根据地区woeid获取雅虎天气 * 获取woeid http://sugg.us.search.yahoo.net/gossip-gl-location/?appid=weather&output=xml&command=地名(如香港) * 匹配规则:preg_match('/woeid=(\d+)\&lon=.*?\&lat=.*?\&s=.*?\&c=.*?\&country_woeid/si', $_return,$match); * 获取天气:https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.media.weather%20where%20woeid%20in(12523356%2C90717580%2C20069923)&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback= */ public function actionWeather() { ini_set('memory_limit', '256M'); ini_set('max_execution_time', '1800'); $areas = Area::model()->findAll(array('select' => 'woeid', 'condition' => 'woeid>0 AND theorder=3')); $woeids = array_keys(CHtml::listData($areas, 'woeid', '')); $woeidsStr = join(',', $woeids); $dir = Yii::app()->basePath . '/runtime/weather'; $totalDir = $dir . '/total.log'; zmf::createUploadDir($dir); $start = microtime(true); if ($woeidsStr != '') { $url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.media.weather%20where%20woeid%20in({$woeidsStr})&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env"; $json = zmf::curlget($url); file_put_contents($totalDir, $json); } $dataArr = CJSON::decode($json, true); $data = $dataArr['query']; if (!$data) { exit('Failed'); } $results = $data['results']['result']; $detailDir = $dir . '/detail/'; zmf::createUploadDir($detailDir); foreach ($results as $result) { if ($result['location']['woeid']) { $_dir = $detailDir . $result['location']['woeid'] . '.log'; file_put_contents($_dir, CJSON::encode($result)); } } echo microtime(true) - $start . '--<br/>'; }
public function actionAdmin() { $countNewsProduct = NewsProduct::getCountNoShow(); if ($countNewsProduct > 0) { Yii::app()->user->setFlash('info', Yii::t('common', 'There are new product news') . ': ' . CHtml::link(Yii::t('common', '{n} news', $countNewsProduct), array('/news/backend/main/product'))); } $this->rememberPage(); $this->getMaxSorter(); $this->getMinSorter(); $model = new Apartment('search'); $model->resetScope(); $model->unsetAttributes(); // clear any default values if (isset($_GET[$this->modelName])) { $model->attributes = $_GET[$this->modelName]; } $model->setRememberScenario('ads_remember'); $model = $model->with(array('user')); $this->params['paidServicesArray'] = array(); if (issetModule('paidservices')) { $paidServices = PaidServices::model()->findAll('id != ' . PaidServices::ID_ADD_FUNDS); $this->params['paidServicesArray'] = CHtml::listData($paidServices, 'id', 'name'); } $this->render('admin', array_merge(array('model' => $model), $this->params)); }
public function actionWrite() { $post = new Post(); $post->blog_id = Yii::app()->getRequest()->getParam('blog-id'); if ($postId = (int) Yii::app()->getRequest()->getQuery('id')) { $post = Post::model()->findUserPost($postId, Yii::app()->getUser()->getId()); if ($post === null) { throw new CHttpException(404); } } if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['Post'])) { $data = Yii::app()->getRequest()->getPost('Post'); $data['user_id'] = Yii::app()->getUser()->getId(); $data['status'] = Yii::app()->getRequest()->getPost('draft', Post::STATUS_PUBLISHED); $data['tags'] = Yii::app()->getRequest()->getPost('tags'); if ($post->createPublicPost($data)) { $message = Yii::t('BlogModule.blog', 'Post sent for moderation!'); $redirect = ['/blog/publisher/my']; if ($post->isDraft()) { $message = Yii::t('BlogModule.blog', 'Post saved!'); } if ($post->isPublished()) { $message = Yii::t('BlogModule.blog', 'Post published!'); $redirect = ['/blog/post/view', 'slug' => $post->slug]; } Yii::app()->getUser()->setFlash(\yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, $message); $this->redirect($redirect); } } $this->render('write', ['post' => $post, 'blogs' => (new Blog())->getListForUser(Yii::app()->getUser()->getId()), 'tags' => array_values(CHtml::listData(Tag::model()->findAll(), 'id', 'name'))]); }
public function actionIndex() { $this->tituloManual = "Novo pedido"; $modelPizzaria = Pizzaria::model()->find(); $modelBanner = Banner::model()->ativos()->find(); if (!$this->validaSituacao()) { $this->render('indisponivel', array('modelPizzaria' => $modelPizzaria, 'modelBanner' => $modelBanner)); Yii::app()->end(); } $dataBebidas = new Produto(); $dataPratosLanche = new Produto(); $dataPromocao = new Promocao(); $modelSabor = array(); $modelTamanho = array(); $arrayTipoSabor = array(); $listCombinado = array(); switch ($modelPizzaria->tipo_restaurante) { case TipoRestaurante::_TIPO_PIZZARIA_: $modelSabor = Sabor::model()->ativos()->findAll(); $modelTamanho = Tamanho::getArrayTamanho(); $arrayTipoSabor = TipoSabor::getArrayTipoSabor(); break; default: $listCombinado = CHtml::listData(Combinado::model()->ativos()->findAll(), 'id', 'nome'); break; } $this->render('index', array('modelPedido' => new Pedido(), 'loginForm' => new LoginForm(), 'modelCliente' => new Cliente(), 'modelUsuario' => new Usuario(), 'dataBebidas' => $dataBebidas->ativos()->bebidas()->search(), 'dataPratosLanche' => $dataPratosLanche->ativos()->pratoLanche()->search(), 'dataPromocao' => $dataPromocao->ativas()->search(), 'modelSabor' => $modelSabor, 'modelTamanho' => $modelTamanho, 'arrayTipoSabor' => $arrayTipoSabor, 'modelPizzaria' => $modelPizzaria, 'arrayBairro' => CHtml::listData(EnderecoPermitido::model()->ativos()->findAll(array('group' => 'bairro', 'distinct' => true)), 'bairro', 'bairro'), 'arrayFormaPagamento' => CHtml::listData(FormaPagamento::model()->ativos()->findAll(), 'id', 'nome'), 'listCombinado' => $listCombinado, 'modelBanner' => $modelBanner)); }
function renderVariation($variation, $i) { if (!ProductSpecification::model()->findByPk(1)) { return false; } if (!$variation) { $variation = new ProductVariation(); $variation->specification_id = 1; } $str = '<tr> <td>'; $str .= CHtml::dropDownList("Variations[{$i}][specification_id]", $variation->specification_id, CHtml::listData(ProductSpecification::model()->findall(), "id", "title"), array('empty' => '-')); $str .= '</td> <td>'; $str .= CHtml::textField("Variations[{$i}][title]", $variation->title); $str .= '</td> <td>'; // Price adjustion $str .= CHtml::dropDownList("Variations[{$i}][sign_price]", $variation->price_adjustion >= 0 ? '+' : '-', array('+' => '+', '-' => '-')); $str .= '</td> <td>'; $str .= CHtml::textField("Variations[{$i}][price_adjustion]", abs($variation->price_adjustion), array('size' => 5)); // Weight adjustion $str .= '</td> <td>'; $str .= CHtml::dropDownList("Variations[{$i}][sign_weight]", $variation->weight_adjustion >= 0 ? '+' : '-', array('+' => '+', '-' => '-')); $str .= '</td> <td>'; $str .= CHtml::textField("Variations[{$i}][weight_adjustion]", abs($variation->weight_adjustion), array('size' => 5)); $str .= '</td> <td>'; for ($j = -10; $j <= 10; $j++) { $positions[$j] = $j; } $str .= CHtml::dropDownList("Variations[{$i}][position]", $variation->position, $positions); $str .= '</td></tr>'; return $str; }
public function actionAddPaid($id = 0, $withDate = 0) { $model = new AddToAdForm(); $paidServices = PaidServices::model()->findAll('id != ' . PaidServices::ID_ADD_FUNDS); $paidServicesArray = CHtml::listData($paidServices, 'id', 'name'); $request = Yii::app()->request; $data = $request->getPost('AddToAdForm'); if ($data) { $apartmentId = $request->getPost('ad_id'); $withDate = $request->getPost('withDate'); $model->attributes = $data; if ($model->validate()) { $apartment = Apartment::model()->findByPk($apartmentId); $paidService = PaidServices::model()->findByPk($model->paid_id); if (!$paidService || !$apartment) { throw new CException('Not valid data'); } if (PaidServices::applyToApartment($apartmentId, $paidService->id, $model->date_end)) { echo CJSON::encode(array('status' => 'ok', 'apartmentId' => $apartmentId, 'html' => $apartment->getPaidHtml($withDate, true))); Yii::app()->end(); } } else { echo CJSON::encode(array('status' => 'err', 'html' => $this->renderPartial('_add_to_form', array('id' => $apartmentId, 'model' => $model, 'withDate' => $withDate, 'paidServicesArray' => $paidServicesArray), true))); Yii::app()->end(); } } $renderData = array('id' => $id, 'model' => $model, 'withDate' => $withDate, 'paidServicesArray' => $paidServicesArray); if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('_add_to_ad', $renderData); } else { $this->render('_add_to_ad', $renderData); } }
public function actionUpdate($id) { $model = new SettingsForm(); if (isset($_POST['SettingsForm'])) { $model->attributes = $_POST['SettingsForm']; if ($model->validate() && $model->save()) { $this->redirect(array('index')); } } else { $model->loadDataFromStore($id); } $directories = glob(Yii::getPathOfAlias('webroot.themes') . "/*", GLOB_ONLYDIR); $themes = array(); foreach ($directories as $directory) { $themes[] = basename($directory); } $layouts = CHtml::listData(Layout::model()->findAll(), 'layout_id', 'name'); $countries = CHtml::listData(Country::model()->findAll(), 'country_id', 'name'); $zones = CHtml::listData(Zone::model()->findAllByAttributes(array('country_id' => $model->country)), 'zone_id', 'name'); $languages = CHtml::listData(Language::model()->findAll(), 'language_id', 'name'); $currencies = CHtml::listData(Currency::model()->findAll(), 'currency_id', 'title'); $yesNoOptions = array(0 => Yii::t('settings', 'No'), 1 => Yii::t('settings', 'Yes')); $lengthClasses = CHtml::listData(LengthClassDescription::model()->findAll(), 'length_class_id', 'title'); $weightClasses = CHtml::listData(WeightClassDescription::model()->findAll(), 'weight_class_id', 'title'); $taxesOptions = array("" => Yii::t("settings", "--- None ---"), "shipping" => Yii::t("settings", "Shipping Address"), "payment" => Yii::t("settings", "Payment Address")); $customerGroups = CHtml::listData(CustomerGroupDescription::model()->findAll(), 'customer_group_id', 'name'); $informations = array_merge(array(0 => Yii::t("settings", "--- None ---")), CHtml::listData(InformationDescription::model()->findAll(), 'information_id', 'title')); // TODO: localisation $orderStatuses = CHtml::listData(OrderStatus::model()->findAllByAttributes(array('language_id' => 1)), 'order_status_id', 'name'); // TODO: localisation $returnStatuses = CHtml::listData(ReturnStatus::model()->findAllByAttributes(array('language_id' => 1)), 'return_status_id', 'name'); $mailProtocols = array("mail" => Yii::t("settings", "Mail"), "smtp" => Yii::t("settings", "SMTP")); $this->render('update', array('model' => $model, 'themes' => $themes, 'layouts' => $layouts, 'countries' => $countries, 'zones' => $zones, 'languages' => $languages, 'currencies' => $currencies, 'yesNoOptions' => $yesNoOptions, 'lengthClasses' => $lengthClasses, 'weightClasses' => $weightClasses, 'taxesOptions' => $taxesOptions, 'customerGroups' => $customerGroups, 'informations' => $informations, 'orderStatuses' => $orderStatuses, 'returnStatuses' => $returnStatuses, 'mailProtocols' => $mailProtocols)); }
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 actionFilterMacroNames() { $macros = $this->getMacros(false); $unique_names = CHtml::listData($macros, 'name', 'name'); asort($unique_names); $this->renderPartial('_macro_names', array('names' => $unique_names)); }
public function getDetails($cate) { $model = $this->findAllByAttributes(array('opt_category' => $cate)); $result = CHtml::listData($model, 'id', 'details'); $value = array_values($result); return array_combine($value, $value); }
public function actionVieworders($id) { $user_id = Yii::app()->user->id; $criteria = new CDbCriteria(); $criteria->condition = "citm_cart_id=:citm_cart_id AND cart_user_id=:cart_user_id"; $criteria->params = array(':citm_cart_id' => $id, ':cart_user_id' => $user_id); $criteria->with = array('cartCartItem', 'cartItem'); $criteria->order = 'citm_item_id asc'; $model = CartItems::model()->findAll($criteria); $customizatiosData = array(); if (!empty($model)) { foreach ($model as $key => $arrObj) { if (!empty($arrObj->citm_customization)) { $customizations = json_decode($arrObj->citm_customization, true); $customizatiosData[$arrObj->citm_id] = $customizations; } } } $fabricDetails = Fabrics::model()->findAll(); $buttonDetails = Buttons::model()->findAll(); $fabrics = array(); if (!empty($fabricDetails)) { foreach ($fabricDetails as $key2 => $arr) { $fabId = $arr->fab_id; $fabrics[$fabId] = $arr; } } $buttons = CHtml::listData($buttonDetails, 'but_id', 'but_name'); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } $this->render('vieworders', array('model' => $model, 'fabrics' => $fabrics, 'buttons' => $buttons, 'customizatiosData' => $customizatiosData)); }