diff --git a/extension.driver.php b/extension.driver.php index d194d68..fc1f693 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -3,17 +3,29 @@ Class extension_Email_Field extends Extension{ public function uninstall(){ - Symphony::Database()->query("DROP TABLE `tbl_fields_email`"); + return Symphony::Database() + ->drop('tbl_fields_email') + ->ifExists() + ->execute() + ->success(); } public function install(){ - return Symphony::Database()->query(" - CREATE TABLE `tbl_fields_email` ( - `id` int(11) unsigned NOT NULL auto_increment, - `field_id` int(11) unsigned NOT NULL, - PRIMARY KEY (`id`), - KEY `field_id` (`field_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - "); + return Symphony::Database() + ->create('tbl_fields_email') + ->ifNotExists() + ->fields([ + 'id' => [ + 'type' => 'int(11)', + 'auto' => true, + ], + 'field_id' => 'int(11)', + ]) + ->keys([ + 'id' => 'primary', + 'field_id' => 'key', + ]) + ->execute() + ->success(); } } diff --git a/extension.meta.xml b/extension.meta.xml index f9d880d..ebff7f2 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -13,6 +13,10 @@ + + - Update for Symphony 4.x + - Code refactoring for Database and EQFA + - Minor updates to method signatures for forward compatibility diff --git a/fields/field.email.php b/fields/field.email.php index e54b0e5..14b25f4 100644 --- a/fields/field.email.php +++ b/fields/field.email.php @@ -6,27 +6,40 @@ public function __construct(){ parent::__construct(); + $this->entryQueryFieldAdapter = new EntryQueryFieldAdapter($this); + $this->_name = __('Email'); $this->_required = true; $this->set('required', 'no'); } - + /*------------------------------------------------------------------------- Setup: -------------------------------------------------------------------------*/ public function createTable(){ - return Symphony::Database()->query( - "CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') . "` ( - `id` int(11) unsigned NOT NULL auto_increment, - `entry_id` int(11) unsigned NOT NULL, - `value` varchar(255) default NULL, - PRIMARY KEY (`id`), - KEY `entry_id` (`entry_id`), - KEY `value` (`value`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" - ); + return Symphony::Database() + ->create('tbl_entries_data_' . $this->get('id')) + ->ifNotExists() + ->fields([ + 'id' => [ + 'type' => 'int(11)', + 'auto' => true, + ], + 'entry_id' => 'int(11)', + 'value' => [ + 'type' => 'varchar(255)', + 'null' => true, + ], + ]) + ->keys([ + 'id' => 'primary', + 'entry_id' => 'key', + 'value' => 'key', + ]) + ->execute() + ->success(); } /*------------------------------------------------------------------------- @@ -35,13 +48,13 @@ public function createTable(){ private function __applyValidationRule($data) { include(TOOLKIT . '/util.validators.php'); - $rule = (isset($validators['email']) + $rule = (isset($validators['email']) ? $validators['email'] : '/^\w(?:\.?[\w%+-]+)*@\w(?:[\w-]*\.)+?[a-z]{2,}$/i'); return General::validateString($data, $rule); } - + /*------------------------------------------------------------------------- Settings: @@ -50,21 +63,31 @@ private function __applyValidationRule($data) { public function displaySettingsPanel(XMLElement &$wrapper, $errors = null) { parent::displaySettingsPanel($wrapper, $errors); - $div = new XMLElement('div', NULL, array('class' => 'two columns')); - $this->appendRequiredCheckbox($div); - $this->appendShowColumnCheckbox($div); - $wrapper->appendChild($div); + // Hide Validator field + if(count($wrapper->getChildren()) == 7) { + $wrapper->removeChildAt(4); + $wrapper->removeChildAt(5); + } else { + $wrapper->removeChildAt(3); + $wrapper->removeChildAt(4); + } } - public function commit(){ - if(!parent::commit()) return false; + public function commit() { + // Bypass current parent (fieldInput) + // use the default implementation from the abstract class + if(!Field::commit()) { + return false; + } $id = $this->get('id'); - if($id === false) return false; + if($id === false) { + return false; + } $fields = array(); $fields['field_id'] = $id; - + return FieldManager::saveSettings($id, $fields); } @@ -72,9 +95,9 @@ public function commit(){ Publish: -------------------------------------------------------------------------*/ - public function checkPostFieldData($data, &$message, $entry_id=NULL){ + public function checkPostFieldData($data, &$message, $entry_id = null){ - $message = NULL; + $message = null; if($this->get('required') == 'yes' && strlen($data) == 0){ $message = __("'%s' is a required field.", array($this->get('label'))); @@ -89,8 +112,8 @@ public function checkPostFieldData($data, &$message, $entry_id=NULL){ return self::__OK__; } - - public function processRawFieldData($data, &$status, &$message=null, $simulate = false, $entry_id = null) { + + public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null) { $status = self::__OK__; if (strlen(trim($data)) == 0) return array(); @@ -125,7 +148,7 @@ public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = fal AND t{$field_id}_{$this->_key}.value = '{$value}' "; } - } + } else { if (!is_array($data)) $data = array($data);