EModal_Model_Theme


Description Description


Source Source

File: includes/importer/easy-modal-v2/model/theme.php

class EModal_Model_Theme extends EModal_Model {
	protected $_class_name = 'EModal_Model_Theme';
	protected $_table_name = 'em_themes';
	protected $meta;
	protected $_default_fields = array(
		'id'        => null,
		'name'      => 'Default',
		'created'   => '0000-00-00 00:00:00',
		'modified'  => '0000-00-00 00:00:00',
		'is_system' => 0,
		'is_trash'  => 0
	);

	public function __construct( $id = null ) {
		parent::__construct( $id );
		$this->load_meta();

		return $this;
	}

	public function __get( $key ) {
		if ( $key == 'meta' ) {
			return $this->meta;
		} else {
			return parent::__get( $key );
		}
	}

	public function save() {
		if ( ! $this->id ) {
			$this->created = date( 'Y-m-d H:i:s' );
		}
		$this->modified = date( 'Y-m-d H:i:s' );
		parent::save();
		$this->meta->theme_id = $this->id;
		$this->meta->save();
	}

	public function load_meta() {
		if ( empty( $this->meta ) ) {
			$this->meta = new EModal_Model_Theme_Meta( $this->id );
		}

		return $this->meta;
	}

	public function as_array() {
		$array         = parent::as_array();
		$array['meta'] = $this->meta->as_array();

		return $array;
	}

	public function set_fields( array $data ) {
		if ( ! empty( $data['meta'] ) ) {
			$this->meta->set_fields( $data['meta'] );
			unset( $data['meta'] );
		}
		parent::set_fields( $data );
	}
}


Top ↑

Methods Methods


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.