本文整理汇总了PHP中ArrayHelper::prepareCompositeKey方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::prepareCompositeKey方法的具体用法?PHP ArrayHelper::prepareCompositeKey怎么用?PHP ArrayHelper::prepareCompositeKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::prepareCompositeKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerRecordImpl
protected function registerRecordImpl(array &$records = NULL, $record) {
parent::registerRecordImpl($records, $record);
$recordKey = NULL;
foreach ($this->keyColumnNames as $keyColumnName) {
$recordKey[] = isset($record[$keyColumnName]) ? $record[$keyColumnName] : NULL;
}
$key = ArrayHelper::prepareCompositeKey($recordKey);
if (isset($records[$key])) {
if ($this->isColumnValueUnique) {
throw new IllegalArgumentException(t(
'Found several records for the key: %key',
array('%key' => ArrayHelper::serialize($recordKey, ', ', TRUE, TRUE))));
}
$records[$key][] = $record;
}
else {
if ($this->isColumnValueUnique) {
$records[$key] = $record;
}
else {
$records[$key][] = $record;
}
}
return TRUE;
}
示例2: formatRecord
public function formatRecord(array &$records = NULL, $record)
{
$result = parent::formatRecord($records, $record);
if ($result) {
$this->errorUnsupportedChainOfResultFormatters();
}
$recordKey = NULL;
foreach ($this->keyColumnNames as $columnName) {
$recordKey[] = isset($record[$columnName]) ? $record[$columnName] : NULL;
}
$key = ArrayHelper::prepareCompositeKey($recordKey);
if (isset($records[$key])) {
if ($this->isColumnValueUnique) {
throw new IllegalArgumentException(t('Found several records for the key: @key', array('@key' => ArrayHelper::printArray($recordKey, ', ', TRUE, TRUE))));
}
$records[$key][] = $record;
} else {
if ($this->isColumnValueUnique) {
$records[$key] = $record;
} else {
$records[$key][] = $record;
}
}
return TRUE;
}
示例3: prepareLookupKey
public static function prepareLookupKey($items) {
$lookupKey = NULL;
if (is_array($items)) {
$normalizedItems = NULL;
foreach ($items as $item) {
$normalizedItems[] = self::normalizeValue($item);
}
$lookupKey = ArrayHelper::prepareCompositeKey($normalizedItems);
}
else {
$lookupKey = self::normalizeValue($items);
}
$lookupKey = strtoupper($lookupKey);
return $lookupKey;
}
示例4: findEligibleColumns4ColumnComment
protected function findEligibleColumns4ColumnComment(SystemTableMetaModelLoaderCallContext $callcontext, AbstractMetaModel $metamodel, $tableOwner, $tableName, $columnName) {
$columns = NULL;
$tableAccessKey = ArrayHelper::prepareCompositeKey(array($tableOwner, $tableName));
if (isset($callcontext->datasets[$tableAccessKey])) {
$column = $callcontext->datasets[$tableAccessKey]->findColumn($columnName);
if (isset($column)) {
$columns[] = $column;
}
}
return $columns;
}
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:13,代码来源:AbstractSystemTableMetaModelGenerator.php
示例5: insertOrUpdateOrDeleteDatasetRecords
public function insertOrUpdateOrDeleteDatasetRecords(DataControllerCallContext $callcontext, AbstractDatasetManipulationRequest $request) {
$environment_metamodel = data_controller_get_environment_metamodel();
$metamodel = data_controller_get_metamodel();
$datasourceQueryHandler = DataSourceQueryFactory::getInstance()->getHandler($this->getDataSourceType());
$dataset = $metamodel->getDataset($request->datasetName);
$datasource = $environment_metamodel->getDataSource($dataset->datasourceName);
$recordMetaData = isset($request->recordsHolder->recordMetaData) ? $request->recordsHolder->recordMetaData : $dataset;
$isRecordIndexed = $request->recordsHolder instanceof IndexedRecordsHolder;
$keyColumnNames = $recordMetaData->getKeyColumnNames();
$nonkeyColumnNames = $recordMetaData->findNonKeyColumnNames();
// preparing a request to find existing records
$queryRequest = new DatasetQueryRequest($request->datasetName);
// loading only key columns from database
$queryRequest->addColumns($keyColumnNames);
// a request can be more efficient for single column key
if (count($keyColumnNames) == 1) {
list($keyColumnIndex, $keyColumnName) = each($keyColumnNames);
$keyColumnIdentifier = $isRecordIndexed ? $keyColumnIndex : $keyColumnName;
$keyValues = NULL;
foreach ($request->recordsHolder->records as $record) {
ArrayHelper::addUniqueValue($keyValues, $record->getColumnValue($keyColumnIdentifier, TRUE));
}
$queryRequest->addQueryValue(
0,
$keyColumnName, OperatorFactory::getInstance()->initiateHandler(EqualOperatorHandler::OPERATOR__NAME, array($keyValues)));
}
else {
for ($i = 0, $count = count($request->recordsHolder->records); $i < $count; $i++) {
$record = $request->recordsHolder->records[$i];
foreach ($keyColumnNames as $keyColumnIndex => $keyColumnName) {
$keyColumnIdentifier = $isRecordIndexed ? $keyColumnIndex : $keyColumnName;
$keyColumnValue = $record->getColumnValue($keyColumnIdentifier, TRUE);
$queryRequest->addQueryValue(
$i,
$keyColumnName, OperatorFactory::getInstance()->initiateHandler(EqualOperatorHandler::OPERATOR__NAME, $keyColumnValue));
}
}
}
// loading existing records ... if any
$existingRecordFormatter = new QueryKeyResultFormatter($keyColumnNames);
$existingRecords = $existingRecordFormatter->formatRecords($datasourceQueryHandler->queryDataset($callcontext, $queryRequest));
// sorting out records for insert, update and delete operations
$keyedRecords = $insertedRecordKeys = $updatedRecordKeys = $deletedRecordKeys = NULL;
foreach ($request->recordsHolder->records as $record) {
$keyParts = NULL;
foreach ($keyColumnNames as $keyColumnIndex => $keyColumnName) {
$keyColumnIdentifier = $isRecordIndexed ? $keyColumnIndex : $keyColumnName;
$keyParts[] = $record->getColumnValue($keyColumnIdentifier, TRUE);
}
$key = ArrayHelper::prepareCompositeKey($keyParts);
$keyedRecords[$key] = $record;
// checking if the record has to be deleted
$isDeletable = TRUE;
if (isset($nonkeyColumnNames)) {
foreach ($nonkeyColumnNames as $columnIndex => $columnName) {
$columnIdentifier = $isRecordIndexed ? $columnIndex : $columnName;
if ($record->getColumnValue($columnIdentifier) != NULL) {
$isDeletable = FALSE;
break;
}
}
}
else {
// the dataset has NO non-key columns. We should not delete these records
$isDeletable = FALSE;
}
if ($isDeletable) {
unset($insertedRecordKeys[$key]);
unset($updatedRecordKeys[$key]);
// the record physically present in database and needs to be deleted
if (isset($existingRecords[$key])) {
unset($existingRecords[$key]);
$deletedRecordKeys[$key] = TRUE;
}
}
elseif (isset($insertedRecordKeys[$key])) {
// the key has been already used to insert a record within this batch. This record needs to be part of update operation
$updatedRecordKeys[$key] = TRUE;
}
elseif (isset($existingRecords[$key])) {
$updatedRecordKeys[$key] = TRUE;
}
else {
$insertedRecordKeys[$key] = TRUE;
}
}
$sqls = NULL;
//.........这里部分代码省略.........
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:101,代码来源:AbstractSQLDataSourceManipulationHandler.php