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 #84

Open
wants to merge 11 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
2 changes: 1 addition & 1 deletion assets/order_entries.publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
};
}();

$(document).on('ready.orderentries', function() {
$(function () {
Symphony.Extensions.OrderEntries.init();
});

Expand Down
12 changes: 8 additions & 4 deletions content/content.save.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once(TOOLKIT . '/class.jsonpage.php');

Class contentExtensionOrder_entriesSave extends JSONPage{

public function view(){
$field_id = General::sanitize($_POST['field']);
$items = $_POST['items'];
Expand All @@ -16,7 +16,11 @@ public function view(){

$where = '';

$field = FieldManager::fetch($field_id);
$field = (new FieldManager)
->select()
->field($field_id)
->execute()
->next();
$filterableFields = explode(',', $field->get('filtered_fields'));
$section_id = $field->get('parent_section');

Expand Down Expand Up @@ -98,8 +102,8 @@ public function view(){
* @param array $entry_id
*/
Symphony::ExtensionManager()->notifyMembers('EntriesPostOrder', '/publish/', array('entry_id' => array_keys($items)));

$this->_Result['success'] = __('Sorting complete');
}

}
188 changes: 129 additions & 59 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
private $field_id = 0;
private $direction = 'asc';
private $dsFilters;

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -35,7 +35,7 @@ public function getSubscribedDelegates(){
)
);
}

/**
* Save the Datasource Filter Context so it can be used for ordering
*/
Expand Down Expand Up @@ -91,14 +91,22 @@ public function prepareIndex($context) {
$callback = Symphony::Engine()->getPageCallback();

if($callback['driver'] == 'publish' && $callback['context']['page'] == 'index') {

// Fetch sort settings for this section (sort field ID and direction)
$section_id = SectionManager::fetchIDFromHandle($callback['context']['section_handle']);

// Fetch sorting field
if($section_id) {
$section = SectionManager::fetch($section_id);
$field = FieldManager::fetch($section->getSortingField());
$section = (new SectionManager)
->select()
->section($section_id)
->execute()
->next();
$field = (new FieldManager)
->select()
->field($section->getSortingField())
->execute()
->next();

// Check sorting field
if($field && $field->get('type') == 'order_entries') {
Expand All @@ -115,7 +123,7 @@ public function prepareIndex($context) {
}
}
}

/**
* Force manual sorting
*/
Expand All @@ -127,7 +135,7 @@ public function adjustTable($context) {

if($callback['driver'] == 'publish' && $callback['context']['page'] == 'index') {
$contents = $context['oPage']->Contents->getChildren();

// check every child, since the
// form may not always be the first element
foreach ($contents as $child) {
Expand All @@ -143,7 +151,11 @@ public function adjustTable($context) {
$table->setAttribute('data-order-entries-force', 'true');
}

$field = FieldManager::fetch($this->field_id);
$field = (new FieldManager)
->select()
->field($this->field_id)
->execute()
->next();

if ($field && $field->get('show_column') == 'no'){

Expand All @@ -156,19 +168,23 @@ public function adjustTable($context) {
$entry_id = str_replace('id-', '', $tr->getAttribute('id'));

if ($entry_id){
$entry = current(EntryManager::fetch($entry_id));
$entry = current((new EntryManager)
->select()
->entry($entry_id)
->execute()
->next());
$data = $entry->getData($this->field_id);
$order = $field->getParameterPoolValue($data);
$tr->setAttribute('data-order',$order);
}
}

break;
}
}
}
}

/**
* Add components for manual entry ordering
*/
Expand Down Expand Up @@ -217,14 +233,18 @@ public function resetPagination() {
Symphony::Configuration()->set('pagination_maximum_rows', $this->pagination_maximum_rows, 'symphony');
}
}

/**
* {@inheritDoc}
*/
public function uninstall() {
Symphony::Database()->query("DROP TABLE `tbl_fields_order_entries`");
return Symphony::Database()
->drop('tbl_fields_order_entries')
->ifExists()
->execute()
->success();
}

/**
* {@inheritDoc}
*/
Expand All @@ -233,50 +253,77 @@ public function update($previousVersion = false) {

// Prior version 1.6
if(version_compare($previousVersion, '1.6', '<')) {
$status[] = Symphony::Database()->query("
ALTER TABLE `tbl_fields_order_entries`
ADD `force_sort` enum('yes','no')
DEFAULT 'no'
");
$status[] = Symphony::Database()
->alter('tbl_fields_order_entries')
->add([
'force_sort' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
])
->execute()
->success();
}

// Prior version 1.8
if(version_compare($previousVersion, '1.8', '<')) {
$status[] = Symphony::Database()->query("
ALTER TABLE `tbl_fields_order_entries`
ADD `hide` enum('yes','no')
DEFAULT 'no'
");
$status[] = Symphony::Database()
->alter('tbl_fields_order_entries')
->add([
'hide' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
])
->execute()
->success();
}

// Prior version 2.1.4
if(version_compare($previousVersion, '2.1.4', '<')) {
$status[] = Symphony::Database()->query("
ALTER TABLE `tbl_fields_order_entries`
ADD `disable_pagination` enum('yes','no')
DEFAULT 'yes'
");
$status[] = Symphony::Database()
->alter('tbl_fields_order_entries')
->add([
'disable_pagination' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
])
->execute()
->success();
}

// Prior version 2.2
if(version_compare($previousVersion, '2.2', '<')) {
$status[] = Symphony::Database()->query("
ALTER TABLE `tbl_fields_order_entries`
ADD `filtered_fields` varchar(255) DEFAULT NULL
");

$fields = Symphony::Database()->fetchCol('field_id',"SELECT field_id FROM `tbl_fields_order_entries`");
$status[] = Symphony::Database()
->alter('tbl_fields_order_entries')
->add([
'filtered_fields' => [
'type' => 'varchar(255)',
'null' => true,
],
])
->execute()
->success();

$fields = Symphony::Database()
->select(['field_id'])
->from('tbl_fields_order_entries')
->execute()
->column('field_id');

foreach ($fields as $key => $field) {
$status[] = Symphony::Database()->query("
ALTER TABLE `tbl_entries_data_{$field}`
DROP INDEX `entry_id`
");

$status[] = Symphony::Database()->query("
ALTER TABLE `tbl_entries_data_{$field}`
ADD UNIQUE `unique`(`entry_id`)
");
$status[] = Symphony::Database()
->alter('tbl_entries_data_' . $field)
->dropIndex('entry_id')
->addKey([
'entry_id' => 'unique',
])
->execute()
->success();
}
}

Expand All @@ -288,23 +335,46 @@ public function update($previousVersion = false) {
return true;
}
}

/**
* {@inheritDoc}
*/
public function install() {
return Symphony::Database()->query("
CREATE TABLE `tbl_fields_order_entries` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`force_sort` enum('yes','no') default 'no',
`hide` enum('yes','no') default 'no',
`disable_pagination` enum('yes','no') default 'no',
`filtered_fields` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `field_id` (`field_id`)
) TYPE=MyISAM
");
return Symphony::Database()
->create('tbl_fields_order_entries')
->ifNotExists()
->fields([
'id' => [
'type' => 'int(11)',
'auto' => true,
],
'field_id' => 'int(11)',
'force_sort' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
'hide' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
'disable_pagination' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
'filtered_fields' => [
'type' => 'varchar(255)',
'null' => true,
],
])
->keys([
'id' => 'primary',
'field_id' => 'unique',
])
->execute()
->success();
}

}
7 changes: 6 additions & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<extension id="order_entries" status="released" xmlns="http://symphony-cms.com/schemas/extension/1.0">
<name>Order Entries</name>
<name>Field: Order Entries</name>
<description lang="en">Allow drag-and-drop re-ordering of entries.</description>
<repo type="github">https://github.com/symphonists/order_entries</repo>
<types>
Expand All @@ -18,6 +18,11 @@
</author>
</authors>
<releases>
<release version="3.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
- Replace deprecated method fetch() by select()
</release>
<release version="2.3.7" date="2016-11-17" min="2.5" max="2.x.x">
- Removed inline script injection (#83)
</release>
Expand Down
Loading