当前位置: 首页>>代码示例>>PHP>>正文


PHP SqlHelper::arrToCase方法代码示例

本文整理汇总了PHP中SqlHelper::arrToCase方法的典型用法代码示例。如果您正苦于以下问题:PHP SqlHelper::arrToCase方法的具体用法?PHP SqlHelper::arrToCase怎么用?PHP SqlHelper::arrToCase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SqlHelper的用法示例。


在下文中一共展示了SqlHelper::arrToCase方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionSorting

 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');
 }
开发者ID:nizsheanez,项目名称:documentation,代码行数:25,代码来源:DocumentationAdminController.php

示例2: actionSorting

 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]);
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:25,代码来源:MenuSectionAdminController.php

示例3: run

 public function run()
 {
     $model = $this->model;
     $class = get_class($model);
     if (isset($_POST['tree'])) {
         $this->controller->performAjaxValidation($model);
         //при сортировке дерева параметры корня измениться не могут,
         //поэтоtму его вообще сохранять не будем
         $data = json_decode($_POST['tree']);
         array_shift($data);
         //получаем большие case для update
         $update = array();
         $nestedSortableFields = array('depth' => $class::DEPTH, 'left' => $class::LFT, 'right' => $class::RGT);
         foreach ($nestedSortableFields as $key => $field) {
             $update_data = CHtml::listData($data, 'item_id', $key);
             if ($key == $class::DEPTH) {
                 foreach ($update_data as $key => $val) {
                     $update_data[$key]++;
                 }
             }
             $update[] = "{$field} = " . SqlHelper::arrToCase('id', $update_data);
         }
         //обновляем всю таблицу, кроме рута
         $condition = $class::DEPTH . " > 1";
         $command = Yii::app()->db->createCommand("UPDATE `{$model->tableName()}` SET " . implode(', ', $update) . " WHERE {$condition}");
         $command->execute();
         $this->controller->forward($this->forwardRoute, true);
     }
     $this->controller->render('sort', array('model' => $model, 'class' => $class));
 }
开发者ID:nizsheanez,项目名称:kur.ru,代码行数:30,代码来源:ActionSort.php

示例4: run

 public function run()
 {
     $ids = array_reverse($_POST['File']);
     $files = new MediaFile('sort');
     $case = SqlHelper::arrToCase('id', array_flip($ids), 't');
     $arr = implode(',', $ids);
     Yii::app()->db->getCommandBuilder()->createSqlCommand("UPDATE {$files->tableName()} AS t SET t.order = {$case} WHERE t.id IN ({$arr})")->execute();
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:8,代码来源:SavePriorityAction.php

示例5: setPositions

 public function setPositions($ids, $column, $start)
 {
     $model = $this->getOwner();
     $table = $model->tableName();
     $priorities = array();
     foreach ($ids as $id) {
         $priorities[$id] = $start--;
     }
     $case = SqlHelper::arrToCase('id', $priorities, $model->getTableAlias());
     $in = SqlHelper::in('id', $ids, $model->getTableAlias());
     $c = Yii::app()->db->commandBuilder->createSqlCommand("UPDATE {$table} AS t SET t.{$column} = {$case} WHERE {$in}");
     $c->execute();
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:13,代码来源:SortableBehavior.php

示例6: setPositions

 public function setPositions($ids, $column, $start)
 {
     list($table, $fk1, $fk2) = SqlHelper::parseManyMany($this->owner, $this->relation);
     $model = $this->getOwner();
     $table = $model->tableName();
     $priorities = array();
     foreach ($ids as $id) {
         $priorities[$id] = $start--;
     }
     $case = SqlHelper::arrToCase('id', $priorities, $model->getTableAlias());
     $c = Yii::app()->db->commandBuilder->createSqlCommand("UPDATE {$table} AS t SET t.{$column} = {$case}");
     $c->execute();
 }
开发者ID:nizsheanez,项目名称:alp.ru,代码行数:13,代码来源:ManyManySortableBehavior.php


注:本文中的SqlHelper::arrToCase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。