本文整理汇总了PHP中GxActiveRecord类的典型用法代码示例。如果您正苦于以下问题:PHP GxActiveRecord类的具体用法?PHP GxActiveRecord怎么用?PHP GxActiveRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GxActiveRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param mixed $id the ID of the model to be loaded
* @param string $modelClass the model class name
* @return GxActiveRecord the loaded model
*/
public function loadModel($id, $modelClass)
{
$model = GxActiveRecord::model($modelClass)->findByPk($id);
if ($model === null) {
throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.'));
}
return $model;
}
示例2: loadModel
public function loadModel($key, $modelClass)
{
if (is_array($key)) {
return parent::loadModel($key, $modelClass);
}
$staticModel = GxActiveRecord::model($modelClass);
$model = $staticModel->findByPk($key);
if (!$model) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例3: getRelations
/**
* Returns all the relations of the specified model.
* @param string $modelClass The model class name.
* @return array The relations. Each array item is
* a relation as an array, having 3 items:
* 0: the relation name,
* 1: the relation type,
* 2: the foreign key,
* 3: the related active record class name.
* Or an empty array if no relations were found.
*/
public function getRelations($modelClass) {
$relations = GxActiveRecord::model($modelClass)->relations();
$result = array();
foreach ($relations as $relationName => $relation) {
$result[] = array(
$relationName, // the relation name
$relation[0], // the relation type
$relation[2], // the foreign key
$relation[1] // the related active record class name
);
}
return $result;
}
示例4: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo Yii::t('app', 'View') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'cupo', 'type' => 'raw', 'value' => $model->cupo !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->cupo)), array('cupo/view', 'id' => GxActiveRecord::extractPkValue($model->cupo, true))) : null), array('name' => 'user', 'type' => 'raw', 'value' => $model->user !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->user)), array('user/view', 'id' => GxActiveRecord::extractPkValue($model->user, true))) : null), array('name' => 'recarga', 'type' => 'raw', 'value' => $model->recarga !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->recarga)), array('recarga/view', 'id' => GxActiveRecord::extractPkValue($model->recarga, true))) : null), 'fecha', 'comentario', 'estado')));
示例5: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model) => array('view', 'id' => GxActiveRecord::extractPkValue($model, true)), Yii::t('app', 'Update'));
$this->menu = array(array('label' => Yii::t('app', 'Manage') . ' ' . IguCompanytype::label(2), 'url' => array('admin')));
$this->beginWidget('zii.widgets.CPortlet', array('htmlOptions' => array('class' => '')));
$this->widget('bootstrap.widgets.TbMenu', array('type' => 'pills', 'items' => array(array('label' => 'Create', 'icon' => 'icon-plus', 'url' => Yii::app()->controller->createUrl('create'), 'linkOptions' => array()), array('label' => 'List', 'icon' => 'icon-th-list', 'url' => Yii::app()->controller->createUrl('index'), 'linkOptions' => array()), array('label' => 'Manage', 'icon' => 'icon-search', 'url' => Yii::app()->controller->createUrl('admin'), 'linkOptions' => array('class' => 'search-button')), array('label' => 'Export to PDF', 'icon' => 'icon-download', 'url' => Yii::app()->controller->createUrl('GeneratePdf'), 'linkOptions' => array('target' => '_blank'), 'visible' => true), array('label' => 'Export to Excel', 'icon' => 'icon-download', 'url' => Yii::app()->controller->createUrl('GenerateExcel'), 'linkOptions' => array('target' => '_blank'), 'visible' => true))));
$this->endWidget();
?>
<h3><?php
echo Yii::t('app', 'Update') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h3>
<?php
$this->renderPartial('_form', array('model' => $model));
示例6: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo Yii::t('app', 'View') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'idclient0', 'type' => 'raw', 'value' => $model->idclient0 !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->idclient0)), array('iguRegistration/view', 'id' => GxActiveRecord::extractPkValue($model->idclient0, true))) : null), 'idproduct', 'cashinvested', 'cashprofit', 'year')));
?>
示例7: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'Listar') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Crear') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Actualizar') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->iddocumentoexistente)), array('label' => Yii::t('app', 'Eliminar') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->iddocumentoexistente), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Administrar') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo Yii::t('app', 'Ver') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('iddocumentoexistente', array('name' => 'documentoanexo', 'type' => 'raw', 'value' => $model->documentoanexo !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->documentoanexo)), array('documentoAnexo/view', 'id' => GxActiveRecord::extractPkValue($model->documentoanexo, true))) : null), 'archivo', 'matricula_id', 'docente_id', 'fecha_creacion', 'usuario_id')));
?>
示例8: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'Listar') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Agregar') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Editar') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Borrar') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Administrar') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('nombre', array('name' => 'idAreaEmpresa', 'type' => 'raw', 'value' => $model->idAreaEmpresa !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->idAreaEmpresa)), array('areasEmpresa/view', 'id' => GxActiveRecord::extractPkValue($model->idAreaEmpresa, true))) : null))));
示例9: dataTables
protected function dataTables($aColumns, $modelClass, $customQuery = NULL)
{
$staticModel = GxActiveRecord::model($modelClass);
$sIndexColumn = $staticModel->getTableSchema()->primaryKey;
$namaTabel = $staticModel->tableName();
/*
* Paging
*/
$sLimit = "";
if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1') {
$sLimit = "LIMIT " . $_GET['iDisplayStart'] . ", " . $_GET['iDisplayLength'];
}
/*
* Ordering
*/
$sOrder = "";
if (isset($_GET['iSortCol_0'])) {
$sOrder = "ORDER BY ";
for ($i = 0; $i < intval($_GET['iSortingCols']); $i++) {
if ($_GET['bSortable_' . intval($_GET['iSortCol_' . $i])] == "true") {
$sOrder .= "`" . $aColumns[intval($_GET['iSortCol_' . $i])] . "` " . $_GET['sSortDir_' . $i] . ", ";
}
}
$sOrder = substr_replace($sOrder, "", -2);
if ($sOrder == "ORDER BY") {
$sOrder = "";
}
}
/*
* Filtering
* NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large tables, and MySQL's regex functionality is very limited
*/
$sWhere = "";
if (isset($_GET['sSearch']) && $_GET['sSearch'] != "") {
$sWhere = "WHERE (";
for ($i = 0; $i < count($aColumns); $i++) {
$sWhere .= "`" . $aColumns[$i] . "` LIKE '%" . $_GET['sSearch'] . "%' OR ";
}
$sWhere = substr_replace($sWhere, "", -3);
$sWhere .= ')';
}
/* Individual column filtering */
for ($i = 0; $i < count($aColumns); $i++) {
if (isset($_GET['bSearchable_' . $i]) && $_GET['bSearchable_' . $i] == "true" && $_GET['sSearch_' . $i] != '') {
if ($sWhere == "") {
$sWhere = "WHERE ";
} else {
$sWhere .= " AND ";
}
$sWhere .= "`" . $aColumns[$i] . "` LIKE '%" . $_GET['sSearch_' . $i] . "%' ";
}
}
if ($customQuery != NULL) {
if (strlen(trim($sWhere)) == 0) {
$sWhere = "WHERE " . $customQuery;
} else {
$sWhere .= " AND " . $customQuery;
}
}
/*
* SQL queries
* Get data to display
*/
$sQuery = "\n\t\t SELECT `" . str_replace(" , ", " ", implode("`, `", $aColumns)) . "`\n\t\t FROM {$namaTabel}\n\t\t {$sWhere}\n\t\t {$sOrder}\n\t\t {$sLimit}\n\t\t ";
//echo $sQuery;
$rResult = Yii::app()->db->createCommand($sQuery)->queryAll();
/* Data set length after filtering */
$sQuery = "SELECT COUNT(*) AS FR\n\t\t FROM {$namaTabel}\n\t\t {$sWhere}\n\t\t {$sOrder}";
$rResultFilterTotal = Yii::app()->db->createCommand($sQuery)->queryAll();
foreach ($rResultFilterTotal as $v) {
$aResultFilterTotal = $v;
}
$iFilteredTotal = $aResultFilterTotal["FR"];
/* Total data set length */
$sQuery = "\n\t\t SELECT COUNT(`" . $sIndexColumn . "`) as total\n\t\t FROM {$namaTabel}";
if ($customQuery != NULL) {
$sQuery .= " WHERE " . $customQuery;
}
$rResultTotal = Yii::app()->db->createCommand($sQuery)->queryAll();
$i = 0;
$iTotal = 0;
foreach ($rResultTotal as $v) {
$iTotal = $v["total"];
}
return array("result" => $rResult, "total" => $iTotal, "filtertotal" => $iFilteredTotal);
}
示例10: array
<?php
/* @var $this TexteController */
/* @var $model Texte */
$this->breadcrumbs = array(Yii::t('app', 'Administration') => $this->createUrl('/admin/index'), $model->label(2) => array('index'), Yii::t('app', 'Update'));
$this->menu = array(array('label' => $model->label() . ' ' . Yii::t('app', 'Create'), 'url' => array('create'), "icon" => "plus-sign"), array('label' => $model->label() . ' ' . Yii::t('app', 'View'), 'url' => array('view', 'id' => GxActiveRecord::extractPkValue($model, true)), "icon" => "eye-open"), array('label' => $model->label() . ' ' . Yii::t('app', 'Delete'), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?'), "icon" => "remove"));
?>
<h1><?php
echo Yii::t('app', 'Update') . ': ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->renderPartial('_form', array('model' => $model));
示例11: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo Yii::t('app', 'View') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'test', 'type' => 'raw', 'value' => $model->test !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->test)), array('test/view', 'id' => GxActiveRecord::extractPkValue($model->test, true))) : null), 'name')));
?>
示例12: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo Yii::t('app', 'View') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'subdistribution', 'type' => 'raw', 'value' => $model->subdistribution !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->subdistribution)), array('subdistribution/view', 'id' => GxActiveRecord::extractPkValue($model->subdistribution, true))) : null), array('name' => 'vendor', 'type' => 'raw', 'value' => $model->vendor !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->vendor)), array('vendor/view', 'id' => GxActiveRecord::extractPkValue($model->vendor, true))) : null), array('name' => 'phone', 'type' => 'raw', 'value' => $model->phone !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->phone)), array('phone/view', 'id' => GxActiveRecord::extractPkValue($model->phone, true))) : null))));
?>
示例13: array
<?php
$this->breadcrumbs = array('Pah Anggarans' => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' PahAnggaran', 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' PahAnggaran', 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' PahAnggaran', 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' PahAnggaran', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')));
?>
<h1><?php
echo Yii::t('app', 'View');
?>
PahAnggaran #<?php
echo GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', 'doc_ref', 'periode_bulan', 'periode_tahun', 'trans_date', 'lock', array('label' => 'Users', 'type' => 'raw', 'value' => GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->users)), array('users/view', 'id' => GxActiveRecord::extractPkValue($model->users, true))))), 'itemTemplate' => "<tr class=\"{class}\"><td style=\"width: 120px\"><b>{label}</b></td><td>{value}</td></tr>\n", 'htmlOptions' => array('class' => 'table')));
?>
<!--h2>Pah Anggaran Detils</h2-->
<?php
/*
echo GxHtml::openTag('ul');
foreach($model->pahAnggaranDetils as $relatedModel) {
echo GxHtml::openTag('li');
echo GxHtml::link(GxHtml::encode(GxHtml::valueEx($relatedModel)), array('pahAnggaranDetil/view', 'id' => GxActiveRecord::extractPkValue($relatedModel, true)));
echo GxHtml::closeTag('li');
}
echo GxHtml::closeTag('ul');*/
示例14: array
<?php
$this->breadcrumbs = array('Pe Donaturs' => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' PeDonatur', 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' PeDonatur', 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' PeDonatur', 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' PeDonatur', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')));
?>
<h1><?php
echo Yii::t('app', 'View');
?>
PeDonatur #<?php
echo GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', 'name', 'phone', 'alamat', 'inactive', array('label' => 'PeChartMaster', 'type' => 'raw', 'value' => GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->accountCode)), array('peChartMaster/view', 'id' => GxActiveRecord::extractPkValue($model->accountCode, true))))), 'itemTemplate' => "<tr class=\"{class}\"><td style=\"width: 120px\"><b>{label}</b></td><td>{value}</td></tr>\n", 'htmlOptions' => array('class' => 'table')));
?>
<!--h2>Pe Kas Masuks</h2-->
<?php
/*
echo GxHtml::openTag('ul');
foreach($model->peKasMasuks as $relatedModel) {
echo GxHtml::openTag('li');
echo GxHtml::link(GxHtml::encode(GxHtml::valueEx($relatedModel)), array('peKasMasuk/view', 'id' => GxActiveRecord::extractPkValue($relatedModel, true)));
echo GxHtml::closeTag('li');
}
echo GxHtml::closeTag('ul');*/
示例15: saveRelated
/**
* Saves the MANY_MANY relations of this record.
* Internally used by {@link saveWithRelated} and {@link saveMultiple}.
* See {@link saveWithRelated} and {@link saveMultiple} for details.
* @param array $relatedData The relation data in the format returned by {@link GxController::getRelatedData}.
* @param boolean $runValidation Whether to perform validation before saving the record.
* @param boolean $batch Whether to try to do the deletes and inserts in batch.
* While batches may be faster, using active record instances provides better control, validation, event support etc.
* Batch is only supported for deletes.
* @return boolean Whether the saving succeeds.
* @see saveWithRelated
* @see saveMultiple
* @throws CException If this record is new.
* @throws CException If this active record has composite PK.
* @uses pivotModels
*/
protected function saveRelated($relatedData, $runValidation = true, $batch = true)
{
if (empty($relatedData)) {
return true;
}
// This active record can't be new for the method to work correctly.
if ($this->getIsNewRecord()) {
throw new CException(Yii::t('giix.messages', 'Cannot save the related records to the database because the main record is new.'));
}
// Save each related data.
foreach ($relatedData as $relationName => $relationData) {
// The pivot model class name.
$pivotClassNames = $this->pivotModels();
$pivotClassName = $pivotClassNames[$relationName];
$pivotModelStatic = GxActiveRecord::model($pivotClassName);
// Get the foreign key names for the models.
$activeRelation = $this->getActiveRelation($relationName);
$relatedClassName = $activeRelation->className;
if (preg_match('/(.+)\\((.+),\\s*(.+)\\)/', $activeRelation->foreignKey, $matches)) {
// By convention, the first fk is for this model, the second is for the related model.
$thisFkName = $matches[2];
$relatedFkName = $matches[3];
}
// Get the primary key value of the main model.
$thisPkValue = $this->getPrimaryKey();
if (is_array($thisPkValue)) {
throw new CException(Yii::t('giix.messages', 'Composite primary keys are not supported.'));
}
// Get the current related models of this relation and map the current related primary keys.
$currentRelation = $pivotModelStatic->findAll(new CDbCriteria(array('select' => $relatedFkName, 'condition' => "{$thisFkName} = :thisfkvalue", 'params' => array(':thisfkvalue' => $thisPkValue))));
$currentMap = array();
foreach ($currentRelation as $currentRelModel) {
$currentMap[] = $currentRelModel->{$relatedFkName};
}
// Compare the current map to the new data and identify what is to be kept, deleted or inserted.
$newMap = $relationData;
$deleteMap = array();
$insertMap = array();
if ($newMap !== null) {
// Identify the relations to be deleted.
foreach ($currentMap as $currentItem) {
if (!in_array($currentItem, $newMap)) {
$deleteMap[] = $currentItem;
}
}
// Identify the relations to be inserted.
foreach ($newMap as $newItem) {
if (!in_array($newItem, $currentMap)) {
$insertMap[] = $newItem;
}
}
} else {
// If the new data is empty, everything must be deleted.
$deleteMap = $currentMap;
}
// If nothing changed, we simply continue the loop.
if (empty($deleteMap) && empty($insertMap)) {
continue;
}
// Now act inserting and deleting the related data: first prepare the data.
// Inject the foreign key names of both models and the primary key value of the main model in the maps.
foreach ($deleteMap as &$deleteMapPkValue) {
$deleteMapPkValue = array_merge(array($relatedFkName => $deleteMapPkValue), array($thisFkName => $thisPkValue));
}
unset($deleteMapPkValue);
// Clear reference;
foreach ($insertMap as &$insertMapPkValue) {
$insertMapPkValue = array_merge(array($relatedFkName => $insertMapPkValue), array($thisFkName => $thisPkValue));
}
unset($insertMapPkValue);
// Clear reference;
// Now act inserting and deleting the related data: then execute the changes.
// Delete the data.
if (!empty($deleteMap)) {
if ($batch) {
// Delete in batch mode.
if ($pivotModelStatic->deleteByPk($deleteMap) !== count($deleteMap)) {
return false;
}
} else {
// Delete one active record at a time.
foreach ($deleteMap as $value) {
$pivotModel = GxActiveRecord::model($pivotClassName)->findByPk($value);
if (!$pivotModel->delete()) {
//.........这里部分代码省略.........