本文整理汇总了PHP中entity::get_right_relationships方法的典型用法代码示例。如果您正苦于以下问题:PHP entity::get_right_relationships方法的具体用法?PHP entity::get_right_relationships怎么用?PHP entity::get_right_relationships使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类entity
的用法示例。
在下文中一共展示了entity::get_right_relationships方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/** duplicate_entity( $id, $dup_relationships = true, $maintain_dates = false, $overrides = array() ) {{{
* Duplicates entity with id = $id.
*
* Specifically, copies all fields of an entity to a new id. If dup_relationships
* is true, also copies all relationships, replacing the old id with the new inserted one.
*
* @param $id ID of entity to duplicate
* OR an entity object to duplicate
* @param $dup_relationships Bool that determines whether to duplicate relationships or not
* @param $maintain_dates Bool that determines whether to
* @param $overrides array of field => value pairs to override any values for the new entity
* @return the new, duplicated entity id
*/
function duplicate_entity( $id, $dup_relationships = true, $maintain_dates = false, $overrides = array() )
{
// get all values and structure from existing object
if( is_object( $id ) AND get_class( $id ) == 'entity' )
$e = $id;
else
$e = new entity( $id );
// get the site that owns this entity
$site = $e->get_owner();
// get the tables used by this type/entity
$tables = get_entity_tables_by_id( $e->id() );
//! start of new code (see commented note below)
$ignored_fields = array( 'id', 'name', 'type', 'last_edited_by' );
if( !$maintain_dates )
{
$ignored_fields[] = 'last_modified';
$ignored_fields[] = 'creation_date';
}
// Don't ignore values set as overrides
foreach ($ignored_fields as $key => $val)
if (isset($overrides[$val])) unset ($ignored_fields[$key]);
// convert values of entity to tabled-array structure, make sure to ignore proper fields
$values = values_to_tables( $tables, array_merge( $e->get_values(), $overrides ), $ignored_fields );
// create new entity record
$new_entity_id = create_entity(
$site->id(),
$e->get_value('type'),
$e->get_value('last_edited_by'),
$e->get_value('name'),
$values
);
// copy relationships
if( $dup_relationships )
{
// make new left relationships
$left_rels = $e->get_left_relationships();
foreach( $left_rels AS $rel_type => $rel_obj )
{
if( is_int( $rel_type ) )
{
foreach( $rel_obj AS $r )
create_relationship( $new_entity_id, $r->id(), $rel_type );
}
}
// make new right relationships
$right_rels = $e->get_right_relationships();
foreach( $right_rels AS $rel_type => $rel_obj )
{
if( is_int( $rel_type ) )
{
foreach( $rel_obj AS $r )
create_relationship( $r->id(), $new_entity_id, $rel_type );
}
}
}
// return the new entity
return $new_entity_id;
} // }}}