Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/domain/description/attribute/composite.php
<?php

class AnDomainDescriptionAttributeComposite extends AnDomainDescriptionAttributeAbstract
{
	/**
	 * 
	 */
	protected $_custom_class;
	
	/**
	 * 
	 */
	protected $_initialize_params;
	
	/**
	 * 
	 */
	protected $_is_model;
	
	/**
	 * 
	 * @return 
	 * @param $options Object[optional]
	 */
	public function __construct($options=array())
	{
		$this->_custom_class 	  = $options['class'];
				
		$this->_initialize_params = $options['initialize_with'];
		
		$this->_is_model 		  = isset($options['model']);
		
		$default = array(
            'default' => $this->_is_model || array_key_exists('default', $options) ? null : KFactory::tmp( $this->_custom_class )
        ); 
		
		$options = array_merge($default, $options);
		
		parent::__construct($options);
	}
	
	public function validatePresenceOf($value)
	{
		return true;
	}
	
	/**
	 * 
	 * 
	 * @return 
	 * @param $value Object
	 */
	public function serialize($value)
	{	
		if ( $this->_is_model ) {
			$values = $value->_properties;
		} else
			$values = $value ? $value->serialize() : array();
				
		foreach($this->_initialize_params as $param => $field) {
			$fields[$field] = @$values[$param];
		}
		return $fields;
	}
	
	/**
	 * 
	 * @return 
	 * @param $data Object
	 */	
	public function materialize($data)
	{
		$options = array();
		
		foreach($this->_initialize_params as $param => $field) {
			$key = str_replace('.','_',$field);
			$options[$param] = @$data[$key];
		}
		
		if  ( $this->_is_model ) {
			$instance = KFactory::get('lib.anahita.domain.factory.mapper')->get($this->_custom_class)->getInstance(true);	
			$instance->_properties = $options;
			$instance->awakeFromFetch();
			$instance->markClean();
		} else {		
			$instance = KFactory::tmp($this->_custom_class, $options);
		}
		return $instance;
	}
	
	public function getTableFields()
	{
		return array_values($this->_initialize_params);
	}
	
	public function getTableValues($value)
	{
		if ( is_object($value) ) {	
			$values = $value->serialize();
			foreach($this->_initialize_params as $param => $field) {
				if ( !isset($values[$param]) ) $values[$param] = null;
			}
			return array_values($values);
		} else {
			
			$null_array = array();
			$max 		= count($this->_initialize_params);
			$i			= 0;
			while($i++ < $max)
				$null_array[] = null;
				
			return $null_array;
		}
	}
			
	/**
	 * 
	 * @return 
	 */
	public function getAttrTree()
	{  
		$fields = array();
		foreach($this->_initialize_params as $param => $field) {			
			$fields[$param] = $field;
		}
		$fields = array($this->getName() => $fields);
		return $fields;
	}
}
Return current item: Anahita Social Engine