当前位置: 首页>>代码示例>>PHP>>正文


PHP entity::get_right_relationships方法代码示例

本文整理汇总了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;
	} // }}}
开发者ID:natepixel,项目名称:reason_package,代码行数:81,代码来源:admin_actions.php


注:本文中的entity::get_right_relationships方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。