本文整理汇总了PHP中EEM_Base::related_settings_for方法的典型用法代码示例。如果您正苦于以下问题:PHP EEM_Base::related_settings_for方法的具体用法?PHP EEM_Base::related_settings_for怎么用?PHP EEM_Base::related_settings_for使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EEM_Base
的用法示例。
在下文中一共展示了EEM_Base::related_settings_for方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _save_related_info
/**
* Automatically finds the related model info from the form, if present, and
* save the relations indicated
* @type string $relation_name
* @return bool
* @throws EE_Error
*/
protected function _save_related_info($relation_name)
{
$relation_obj = $this->_model->related_settings_for($relation_name);
if ($relation_obj instanceof EE_Belongs_To_Relation) {
//there is just a foreign key on this model pointing to that one
$this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name);
} elseif ($relation_obj instanceof EE_Has_Many_Relation) {
//then we want to consider all of its currently-related things.
//if they're in this list, keep them
//if they're not in this list, remove them
//and lastly add all the new items
throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', "event_espresso")));
} elseif ($relation_obj instanceof EE_HABTM_Relation) {
//delete everything NOT in this list
$normalized_input_value = $this->get_input_value($relation_name);
if ($normalized_input_value && is_array($normalized_input_value)) {
$where_query_params = array($relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value));
} else {
$where_query_params = array();
}
$this->_model_object->_remove_relations($relation_name, $where_query_params);
foreach ($normalized_input_value as $id) {
$this->_model_object->_add_relation_to($id, $relation_name);
}
}
return TRUE;
}