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


PHP SqlHelper::parseManyMany方法代码示例

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


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

示例1: initOrder

 public function initOrder()
 {
     list($table, $fk1, $fk2) = SqlHelper::parseManyMany($this->owner, $this->relation);
     $model = $this->getOwner();
     $category_ids = CHtml::listData($model->{$this->relation}, 'id', 'id');
     if (!$category_ids) {
         return true;
     }
     $builder = Yii::app()->db->getCommandBuilder();
     $criteria = new CDbCriteria();
     $criteria->select = "MAX(`{$this->map_field}`)";
     $command = Yii::app()->db->createCommand()->select('id')->from($table);
     foreach ($category_ids as $cat_id) {
         $comm = clone $command;
         $id = $comm->where(array('and', "`{$fk1}`={$model->getPrimaryKey()}", "`{$fk2}`={$cat_id}", "`{$this->map_field}`=0", array('in', $fk2, $category_ids)))->queryScalar();
         $cr = clone $criteria;
         $cr->addCondition('t.' . $fk2 . '=' . $cat_id);
         $max = $builder->createFindCommand($table, $cr)->queryScalar();
         $max++;
         Yii::app()->db->createCommand("UPDATE `{$table}` SET  `{$this->map_field}`={$max} WHERE `id`={$id}")->execute();
     }
 }
开发者ID:nizsheanez,项目名称:alp.ru,代码行数:22,代码来源:ManyManySortableBehavior.php

示例2: clear

 /**
  * @param $relations массив ($relation => $exclude), где $exclude - массив id объектов связи с которыми разрывать не нужно
  *
  * @return bool
  */
 public function clear($relations)
 {
     try {
         $commands = array();
         foreach ($relations as $relation => $exclude) {
             list($table, $fk1, $fk2) = SqlHelper::parseManyMany($this->owner, $relation);
             $criteria = new CDbCriteria(array('condition' => $fk1 . '=' . $this->owner->id));
             $excl = array();
             foreach ($exclude as $ex) {
                 $excl[] = is_object($ex) ? $ex->id : $ex;
             }
             $criteria->addNotInCondition($fk2, $excl);
             $commands[] = Yii::app()->db->getCommandBuilder()->createDeleteCommand($table, $criteria);
         }
         foreach ($commands as $c) {
             $c->execute();
         }
         //no commit, because withRelated save
         return true;
     } catch (CException $e) {
         $this->getOwner()->rollback($e);
     }
     return false;
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:29,代码来源:WithRelatedBehavior.php


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