<?php
namespace Moto\Application\Pages; use Moto\Application\Model; use Moto\Application\Model\AbstractModel; use Moto; class PageProperties extends AbstractModel { public $meta; public $menu; public $blocks; public $custom_code; protected $_fields = array( 'meta' => array(), 'menu' => array(), 'blocks' => array(), 'custom_code' => array(), 'template' => array( 'default' => null ), 'password' => array( 'default' => null ), 'role_id' => array( 'default' => null ), 'feature_media' => array( 'default' => "{}", 'type' => 'object', ), 'show_comments' => array( 'default' => true ) ); protected $_skipDefaults = true; public function __construct() { $this->meta = new PagePropertiesMeta(); $this->menu = new PagePropertiesMenu(); $this->blocks = new PagePropertiesBlocks(); $this->custom_code = new PagePropertiesCustomCode(); parent::__construct(); } public function exchangeArray($data) { if (is_string($data)) $data = json_decode($data, true); parent::exchangeArray($data); } public function setFromArray($data) { if (is_string($data)) $data = json_decode($data, true); return parent::setFromArray($data); } public function getData($skipVirtual = false) { $data = parent::getData($skipVirtual); if (empty($data['meta'])) unset($data['meta']); if (empty($data['menu'])) unset($data['menu']); if (empty($data['blocks'])) unset($data['blocks']); if (empty($data['custom_code'])) unset($data['custom_code']); return $data; } public function __clone() { $this->meta = clone $this->meta; $this->menu = clone $this->menu; $this->blocks = clone $this->blocks; $this->custom_code = clone $this->custom_code; } public function getCodeInjection($section, $default = '') { if (!Moto\Features::isEnabled('engine_code_injection', true)) { return $default; } if (!empty($this->custom_code->{$section})) { return $this->custom_code->{$section}; } return $default; } public function hasPassword() { return (!empty($this->password)); } public function getPassword() { if (!empty($this->password)) { return base64_decode($this->password); } return null; } } 