本文整理汇总了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();
}
}
示例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;
}