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


PHP ArrayHelper::cmp方法代码示例

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


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

示例1: internalSave


//.........这里部分代码省略.........
                     $fks = preg_split('/\\s*,\\s*/', $matches[2], -1, PREG_SPLIT_NO_EMPTY);
                     $ownerMap = array();
                     $relatedMap = array();
                     $fkDefined = true;
                     foreach ($fks as $i => $fk) {
                         if (!isset($joinTable->columns[$fk])) {
                             throw new CDbException(Yii::t('yii', 'The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key "{key}". There is no such column in the table "{table}".', array('{class}' => get_class($owner), '{relation}' => $name, '{key}' => $fk, '{table}' => $joinTable->name)));
                         }
                         if (isset($joinTable->foreignKeys[$fk])) {
                             list($tableName, $pk) = $joinTable->foreignKeys[$fk];
                             if (!isset($ownerMap[$pk]) && $schema->compareTableNames($ownerTableSchema->rawName, $tableName)) {
                                 $ownerMap[$pk] = $fk;
                             } else {
                                 if (!isset($relatedMap[$pk]) && $schema->compareTableNames($relatedTableSchema->rawName, $tableName)) {
                                     $relatedMap[$pk] = $fk;
                                 } else {
                                     $fkDefined = false;
                                     break;
                                 }
                             }
                         } else {
                             $fkDefined = false;
                             break;
                         }
                     }
                     if (!$fkDefined) {
                         $ownerMap = array();
                         $relatedMap = array();
                         foreach ($fks as $i => $fk) {
                             if ($i < count($ownerTableSchema->primaryKey)) {
                                 $pk = is_array($ownerTableSchema->primaryKey) ? $ownerTableSchema->primaryKey[$i] : $ownerTableSchema->primaryKey;
                                 $ownerMap[$pk] = $fk;
                             } else {
                                 $j = $i - count($ownerTableSchema->primaryKey);
                                 $pk = is_array($relatedTableSchema->primaryKey) ? $relatedTableSchema->primaryKey[$j] : $relatedTableSchema->primaryKey;
                                 $relatedMap[$pk] = $fk;
                             }
                         }
                     }
                     if ($ownerMap === array() && $relatedMap === array()) {
                         throw new CDbException(Yii::t('yii', 'The relation "{relation}" in active record class "{class}" is specified with an incomplete foreign key. The foreign key must consist of columns referencing both joining tables.', array('{class}' => get_class($owner), '{relation}' => $name)));
                     }
                     $insertAttributes = array();
                     $deleteAttributes = array();
                     foreach ($related as $model) {
                         $newFlag = $model->getIsNewRecord();
                         if ($data === null) {
                             $newFlag ? $model->insert() : $model->update();
                         } else {
                             $this->internalSave($data, $model);
                         }
                         $joinTableAttributes = array();
                         foreach ($ownerMap as $pk => $fk) {
                             $joinTableAttributes[$fk] = $owner->{$pk};
                         }
                         foreach ($relatedMap as $pk => $fk) {
                             $joinTableAttributes[$fk] = $model->{$pk};
                         }
                         if (!$newFlag) {
                             $deleteAttributes[] = $joinTableAttributes;
                         }
                         $insertAttributes[] = $joinTableAttributes;
                     }
                     if ($deleteAttributes !== array()) {
                         $condition = $builder->createInCondition($joinTable, array_merge(array_values($ownerMap), array_values($relatedMap)), $deleteAttributes);
                         $criteria = $builder->createCriteria($condition);
                         //                            $command   = $builder->createDeleteCommand($joinTable, $criteria)->execute();
                     }
                     foreach ($insertAttributes as $attributes) {
                         $f = false;
                         $cr = new CDbCriteria();
                         foreach ($attributes as $k => $v) {
                             $cr->addCondition('t.' . $k . '=' . $v);
                         }
                         $c = $builder->createFindCommand($joinTable, $cr)->query();
                         foreach ($c as $arr) {
                             if (ArrayHelper::cmp($arr, $attributes)) {
                                 $f = true;
                                 break;
                             }
                         }
                         if ($f) {
                             continue;
                         }
                         $builder->createInsertCommand($joinTable, $attributes)->execute();
                     }
                     break;
             }
         }
         if ($extTransFlag === null) {
             $transaction->commit();
         }
         return true;
     } catch (Exception $e) {
         if ($extTransFlag === null) {
             $transaction->rollBack();
         }
         throw $e;
     }
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:101,代码来源:WithRelatedBehavior.php


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