本文整理汇总了PHP中EEM_Base::get_combined_primary_key_fields方法的典型用法代码示例。如果您正苦于以下问题:PHP EEM_Base::get_combined_primary_key_fields方法的具体用法?PHP EEM_Base::get_combined_primary_key_fields怎么用?PHP EEM_Base::get_combined_primary_key_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EEM_Base
的用法示例。
在下文中一共展示了EEM_Base::get_combined_primary_key_fields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _get_read_query_params
/**
* Gets info about reading query params that are acceptable
*
* @param \EEM_Base $model eg 'Event' or 'Venue'
* @param string $version
* @return array describing the args acceptable when querying this model
* @throws \EE_Error
*/
protected function _get_read_query_params(\EEM_Base $model, $version)
{
$default_orderby = array();
foreach ($model->get_combined_primary_key_fields() as $key_field) {
$default_orderby[$key_field->get_name()] = 'ASC';
}
return array_merge($this->_get_response_selection_query_params($model, $version), array('where' => array('required' => false, 'default' => array()), 'limit' => array('required' => false, 'default' => EED_Core_Rest_Api::get_default_query_limit()), 'order_by' => array('required' => false, 'default' => $default_orderby), 'group_by' => array('required' => false, 'default' => null), 'having' => array('required' => false, 'default' => null), 'caps' => array('required' => false, 'default' => EEM_Base::caps_read)));
}
示例2: _update_from_data_array
/**
* Given the model object data, finds the row to update and updates it
* @param string|int $id_in_csv
* @param array $model_object_data
* @param EEM_Base $model
* @param array $old_db_to_new_db_mapping
* @return array updated $old_db_to_new_db_mapping
*/
protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping)
{
try {
//let's keep two copies of the model object data:
//one for performing an update, one for everthing else
$model_object_data_for_update = $model_object_data;
if ($model->has_primary_key_field()) {
$conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]);
//remove the primary key because we shouldn't use it for updating
unset($model_object_data_for_update[$model->primary_key_name()]);
} elseif ($model->get_combined_primary_key_fields() > 1) {
$conditions = array();
foreach ($model->get_combined_primary_key_fields() as $key_field) {
$conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()];
}
} else {
$model->primary_key_name();
//this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey)
}
$success = $model->update($model_object_data_for_update, array($conditions));
if ($success) {
$this->_total_updates++;
EE_Error::add_success(sprintf(__("Successfully updated %s with csv data %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data_for_update)));
//we should still record the mapping even though it was an update
//because if we were going to insert somethign but it was going to conflict
//we would have last-minute decided to update. So we'd like to know what we updated
//and so we record what record ended up being updated using the mapping
if ($model->has_primary_key_field()) {
$new_key_for_mapping = $model_object_data[$model->primary_key_name()];
} else {
//no primary key just a combined key
$new_key_for_mapping = $model->get_index_primary_key_string($model_object_data);
}
$old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_key_for_mapping;
} else {
$matched_items = $model->get_all(array($conditions));
if (!$matched_items) {
//no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck?
$this->_total_update_errors++;
EE_Error::add_error(sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data), http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__);
} else {
$this->_total_updates++;
EE_Error::add_success(sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data)));
}
}
} catch (EE_Error $e) {
$this->_total_update_errors++;
$basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage());
$debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString();
EE_Error::add_error("{$basic_message} | {$debug_message}", __FILE__, __FUNCTION__, __LINE__);
}
return $old_db_to_new_db_mapping;
}