Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Symphony 4.x #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 4 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
</author>
</authors>
<releases>
<release version="2.0.0" date="TBA" min="4.0.0" max="4.x.x" php-min="5.6.x" php-max="7.x.x">
- Update for Symphony 4.x
- Code refactoring for Database and EQFA
</release>
<release version="1.2.1" date="2013-02-25" min="2.3">
- Minor updates to method signatures for forward compatibility
</release>
Expand Down
75 changes: 49 additions & 26 deletions fields/field.email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/*-------------------------------------------------------------------------
Expand All @@ -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:
Expand All @@ -50,31 +63,41 @@ 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);
}

/*-------------------------------------------------------------------------
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')));
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand Down