Entity System - Property Factory

What is Property Entity Factory? Property entity factory is the PHP class wrapper for building a property entity object based on data from a property post data. The class will build all relevant type entity, field entities and attribute entities related to a single post entry.

It is recommended to use Property Factory object when trying to Edit, Delete, Save and Display a single property post.

The object will also provide a factory method for building display markup for front end display, metabox field display and search field display. Use the VTCore_Property_Entity_Property::BuildFieldDisplayObject Method when building object.

Why use property factory? The factory provides easy grouping for all different kind of fields and attributes based on a single property post and property type, without this object, you will need to invoke different kind of field classes and attributes when trying to perform updating, deleting and displaying value from each of fields and attributes.

Relation to Post object The plugin will automatically create the property factory object when a post is loaded, this is done via hook action the_post. The global object $post if invoked correctly should have $post->property injected into it and will have the full property factory object in it.

Example on using the factory

 * Assuming that we are in the property post type loop
global $post;

if (isset($post->property) && is_a($post->property, 'VTCore_Property_Entity_Property')) {

  // Try to render all available fields, display mode

  // Try to render all available attributes, display mode

  // Grab property_location field search object
  $object = $post->property->buildFieldDisplayObject('property_location', array(), 'search');

 * try to manually initiated the factory for post id 1
$factory = new VTCore_Property_Entity_Property(array('id' => 1));

// Initialize Fields, attributes and types

// Load the stored _property_metadata for the current post

// Alter the metadata value, 2 is a dummy tax term
  ->mutate('meta.fields.property_status.status', 2); 

// Save the fields, attributes, type back to database

// Save the post _property_metadata back to database