* @copyright IZI-Services * @package IZICMS * @version 1.0 */ /** * Data Object */ class IZI_Form_DataObject extends IZI_DataObject { public $id; public $title; public $menu_title; public $url; public $store_in_database; public $send_mail_to_admin; public $send_mail_to_user; public $mail_to_admin_address; public $mail_to_admin_subject; public $mail_to_admin_content; public $mail_to_user_subject; public $mail_to_user_content; public $html; public $success_html; public $success_conversion_url; public $fields_serialized; public $description; public $export_template; public $created; public $updated; public $user_id; private $_excludedFields = array('id', 'form_id', 'export_id', 'extrafields_serialized', 'created', 'updated', 'description', '_objectCount', '_relationCache'); protected $_rowCount; public function __construct() { $this->addRelation("rowCollection", "id", IZI_Form_Row_DataManager::getInstance(), "form_id" ); $this->addRelation("exportCollection", "id", IZI_Form_Export_DataManager::getInstance(), "form_id", "created", "DESC" ); $this->addRelation("userObject", "user_id", IZI_User_DataManager::getInstance() ); parent::__construct( $this ); } public function toString() { return $this->title; } public function __get( $value ) { switch( $value ) { case 'fieldArray': if( $this->fields_serialized == '' ) { // Create default fields based on Row DataObject if fields_serialized is empty -> new form $defaultFieldArray = get_class_vars( 'IZI_Form_Row_DataObject' ); foreach( $defaultFieldArray as $FieldName => $f00 ) { // Remove 'system fields' from Array if( in_array( $FieldName, $this->_excludedFields ) ) { unset( $defaultFieldArray[$FieldName] ); } else { // Set all fields to required $defaultFieldArray[$FieldName] = 1; } } return $defaultFieldArray; } else { return unserialize( $this->fields_serialized ); } break; case 'fieldCount': return ( is_array( $this->fieldArray ) ) ? count( $this->fieldArray ) : 0; break; case 'latestExports': return IZI_Form_Export_DataManager::getInstance()->loadByProperty( 'form_id', $this->id, 0, 10, 'created', 'DESC' ); break; case 'rowCount': return $this->_rowCount ? $this->_rowCount : $this->_rowCount = IZI_Form_Row_DataManager::getInstance()->count( 'form_id', $this->id ); break; // Relations with conditions case 'rowUnexportedCollection': return IZI_Form_Row_DataManager::getInstance()->loadWhere( "`form_id` = '{$this->id}' AND `export_id` = '0'" ); break; case 'rowUnexportedCount': return IZI_Form_Row_DataManager::getInstance()->countWhere( "`form_id` = '{$this->id}' AND `export_id` = '0'" ); break; default: return parent::__get( $value ); break; } } } /** * Data Manager */ class IZI_Form_DataManager extends IZI_DataManagerPagination { private static $_instance; /** * Retrieves the singleton instance * * @return IZI_Name_DataManager Singleton instance */ public static function getInstance() { if ( is_null( self::$_instance ) ) { $className = __CLASS__; self::$_instance = new $className; } return self::$_instance; } public function __construct() { parent::__construct( $this ); } /** * save * * @param object $data_object * @access public * @return void */ public function save ( $data_object ) { if( !$data_object->url ) $data_object->url = IZI_String::hyphenate( $data_object->title ); // Unique url id $url = IZI_String::hyphenate( $data_object->url ); $iteration = 1; while( is_object( $uniqueUrl = self::loadByProperty( 'url', $data_object->url ) ) && $uniqueUrl->length() > 1 ) { $data_object->url = $url . '-' . $iteration++; } if( $data_object->id ) { $data_object->updated = date('Y-m-d H:i:s'); } else { $data_object->created = date('Y-m-d H:i:s'); } // Save the current user ID $data_object->user_id = IZI_CurrentUser::getInstance()->user_id; return parent::save( $data_object ); } } /** * Data Collection */ class IZI_Form_DataCollection extends IZI_DataCollection { public function __construct( $initialData = null ) { parent::__construct( $this, $initialData ); } } ?>