Skip to content

Commit

Permalink
Wip v2.3.0 (#41)
Browse files Browse the repository at this point in the history
* Version 2.2.0
- Update der LazyLoad Library von Version 4.0.0 auf Version 5.3.2
- Neue Funktion mmp::getLazyLoad() zum einbinden der jeweiligen Version der LazyLoad Library (siehe Doku)
- Anpassung der filenamesByBreakpoint
- Anpassung der Doku

* Funktionserweiterung
- Sortierung von Breakpoints
- Bereinigung von media_manager_type beim löschen von Breakpoints
- Bereinigung von media_manager_type_effect beim löschen von Breakpoints
- Anpassung der Doku

* Versions Anpassung

Co-authored-by: [email protected] <!R1e5i7U8SFMKx6ssw3x2Tk>
  • Loading branch information
mschnieder authored Aug 20, 2022
1 parent 3178dd2 commit 7f086f1
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 23 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ für ein Bild zu hinterlegen. Somit besteht die Möglichkeit, verschiedene Aufl
1. Über Installer laden oder ZIP-Datei im AddOn-Ordner entpacken, der Ordner muss `media_manager_plus` heißen.
2. AddOn installieren und aktivieren

## Hinweise
### Löschen von Breakpoints
Sorgt auch gleichzeitig dafür das alle Gruppen Breakpoints des Typs gelöscht werden, jedoch nicht für alt Einträge die bis vor der Version 2.3.0 angelegt wurden.

### Anlegen von Breakpoints
Ab Version 2.3.0 werden beim nachträglichen anlegen von Breakpoints, die entsprechenden Einträge für alle bestehenden Gruppen angelegt.

## Verwendung

Expand Down
48 changes: 47 additions & 1 deletion boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
rex_extension::register('REX_FORM_SAVED', function (rex_extension_point $ep) {
$params = $ep->getParams();
$formParams = $params['form']->getParams();

switch ($formParams['page']) {
case 'media_manager/groups':
switch ($params['form']->isEditMode()) {
Expand Down Expand Up @@ -55,8 +55,54 @@
rex_response::sendRedirect(rex_url::backendPage('media_manager/singletypes'));
}
break;

case 'media_manager/breakpoints':
// add Breakpoint
if(!$params['form']->isEditMode()) {
$sql = rex_sql::factory();
$breakpoints = media_manager_plus::getBreakpoints();
$resolutions = media_manager_plus::getResolutions();
$groupEffects = $sql->getArray('Select * from '.rex::getTablePrefix().'media_manager_type where status = 0 and `group` = 0 and subgroup = 0');

foreach($groupEffects as $group) {
$first = true;
$subgroupId = 0;
foreach ($breakpoints as $breakpoint => $mediaquery) {
if($_POST[$params['form']->getName()]['name'] === $breakpoint) {
$bp = $sql->getArray('Select id from '.rex::getTablePrefix().'media_manager_plus_breakpoints where `name` = ?', [$breakpoint]);
if($first) {
$first = false;
$sql->setQuery('Insert into '.rex::getTablePrefix().'media_manager_type (`status`, `name`, `description`, `group`, `subgroup`, `breakpointId`) VALUES (?,?,?,?,?,?)', [0, $group['name'].'-'.$breakpoint, 'generated [group '.$group['id'].']', $group['id'], $subgroupId, $bp[0]['id']]);
$subgroupId = (int)$sql->getLastId();
}
foreach ($resolutions as $resolution => $factor) {
$sql->setQuery('Insert into ' . rex::getTablePrefix() . 'media_manager_type (`status`, `name`, `description`, `group`, `subgroup`, `breakpointId`) VALUES (?,?,?,?,?,?)', [0, $group['name'].'-' . $breakpoint. '@' . $resolution, 'generated[group '.$group['id'].',subgroup '.$subgroupId.']', $group['id'], $subgroupId, $bp[0]['id']]);
}
}
}
}
}
break;
}
});

rex_extension::register('REX_FORM_DELETED', function (rex_extension_point $ep) {
$params = $ep->getParams();
$formParams = $params['form']->getParams();

switch ($formParams['page']) {
case 'media_manager/breakpoints':
$sql = rex_sql::factory();
$mmtIds = $sql->getArray('Select id from '.rex::getTablePrefix().'media_manager_type where breakpointId='.$formParams['id']);

foreach($mmtIds as $mmtId) {
$sql->setQuery('Delete from ' . rex::getTablePrefix() . 'media_manager_type_effect where type_id=' . $mmtId['id']);
}

$sql->setQuery("Delete from ".rex::getTablePrefix()."media_manager_type where breakpointId=".$formParams['id']);
break;
}
});

//Start - inject media_manager
if (rex_request::get('page') == 'media_manager/types' && rex_request::get('func') == 'copy' && rex_request::get('type_id') != '0') {
Expand Down
23 changes: 23 additions & 0 deletions install.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
<?php
$addon = rex_addon::get('media_manager_plus');


rex_sql_table::get(rex::getTable('media_manager_type'))
->ensureColumn(new rex_sql_column('group', 'int(10)'))
->ensureColumn(new rex_sql_column('subgroup', 'int(10)'))
->ensureColumn(new rex_sql_column('breakpointId', 'int(10)'))
->alter();


rex_sql_table::get(rex::getTable('media_manager_plus_breakpoints'))
->ensureColumn(new rex_sql_column('prio', 'int(10)'))
->ensureColumn(new rex_sql_column('createdate', 'datetime'), 'prio')
->ensureColumn(new rex_sql_column('createuser', 'varchar(255)'), 'createdate')
->ensureColumn(new rex_sql_column('updatedate', 'datetime'), 'createuser')
->ensureColumn(new rex_sql_column('updateuser', 'varchar(255)'), 'updatedate')
->alter();

$s = rex_sql::factory();
$breakpoints = $s->getArray('Select * from '.rex::getTablePrefix().'media_manager_plus_breakpoints order by id');
$i = 1;
foreach($breakpoints as $bp) {
if($bp['prio'] === 0) {
$s->setQuery("Update " . rex::getTablePrefix() . "media_manager_plus_breakpoints set prio=" . $i . " where id=".$bp['id']);
$i++;
}
}
25 changes: 13 additions & 12 deletions install.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
CREATE TABLE IF NOT EXISTS `%TABLE_PREFIX%media_manager_plus_breakpoints` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL DEFAULT '',
`mediaquery` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT IGNORE INTO `%TABLE_PREFIX%media_manager_plus_breakpoints` (`id`, `name`, `mediaquery`) VALUES (1, 'XS', '(max-width: 375px)');
INSERT IGNORE INTO `%TABLE_PREFIX%media_manager_plus_breakpoints` (`id`, `name`, `mediaquery`) VALUES (2, 'S', '(min-width: 376px) and (max-width: 750px)');
INSERT IGNORE INTO `%TABLE_PREFIX%media_manager_plus_breakpoints` (`id`, `name`, `mediaquery`) VALUES (3, 'M', '(min-width: 751px) and (max-width: 1024px)');
INSERT IGNORE INTO `%TABLE_PREFIX%media_manager_plus_breakpoints` (`id`, `name`, `mediaquery`) VALUES (4, 'L', '(min-width: 1025px) and (max-width: 1300px)');
INSERT IGNORE INTO `%TABLE_PREFIX%media_manager_plus_breakpoints` (`id`, `name`, `mediaquery`) VALUES (5, 'XL', '(min-width: 1301px)');
-- CREATE TABLE IF NOT EXISTS `%TABLE_PREFIX%media_manager_plus_breakpoints` (
-- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
-- `name` varchar(30) NOT NULL DEFAULT '',
-- `mediaquery` varchar(255) NOT NULL DEFAULT '',
-- `prio` int(10) unsigned NOT NULL,
-- PRIMARY KEY (`id`)
-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- INSERT IGNORE INTO `%TABLE_PREFIX%media_manager_plus_breakpoints` (`id`, `name`, `mediaquery`, `prio`) VALUES (1, 'XS', '(max-width: 375px)', 1);
-- INSERT IGNORE INTO `%TABLE_PREFIX%media_manager_plus_breakpoints` (`id`, `name`, `mediaquery`, `prio`) VALUES (2, 'S', '(min-width: 376px) and (max-width: 750px)', 2);
-- INSERT IGNORE INTO `%TABLE_PREFIX%media_manager_plus_breakpoints` (`id`, `name`, `mediaquery`, `prio`) VALUES (3, 'M', '(min-width: 751px) and (max-width: 1024px)', 3);
-- INSERT IGNORE INTO `%TABLE_PREFIX%media_manager_plus_breakpoints` (`id`, `name`, `mediaquery`, `prio`) VALUES (4, 'L', '(min-width: 1025px) and (max-width: 1300px)', 4);
-- INSERT IGNORE INTO `%TABLE_PREFIX%media_manager_plus_breakpoints` (`id`, `name`, `mediaquery`, `prio`) VALUES (5, 'XL', '(min-width: 1301px)', 5);
2 changes: 1 addition & 1 deletion package.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package: media_manager_plus
version: '2.2.1'
version: '2.3.0'
author: Friends Of REDAXO
supportpage: github.com/FriendsOfREDAXO/media_manager_plus

Expand Down
18 changes: 12 additions & 6 deletions pages/media_manager.breakpoints.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
$func = rex_request('func', 'string');

if ($func == '') {
$list = rex_list::factory("SELECT `id`, `name`, `mediaquery` FROM `".rex::getTablePrefix()."media_manager_plus_breakpoints` ORDER BY `name` ASC");
$list = rex_list::factory("SELECT `id`, `name`, `mediaquery` FROM `".rex::getTablePrefix()."media_manager_plus_breakpoints` ORDER BY `prio` ASC");
$list->addTableAttribute('class', 'table-striped');
$list->setNoRowsMessage($this->i18n('breakpoints_norowsmessage'));

Expand All @@ -28,17 +28,23 @@
echo $content;
} else if ($func == 'add' || $func == 'edit') {
$id = rex_request('id', 'int');


$form = rex_form::factory(rex::getTablePrefix().'media_manager_plus_breakpoints', '', 'id='.$id);

if ($func == 'edit') {
$formLabel = $this->i18n('breakpoints_formcaption_edit');
} elseif ($func == 'add') {
$formLabel = $this->i18n('breakpoints_formcaption_add');
$form->setEditMode(false);
}

$form = rex_form::factory(rex::getTablePrefix().'media_manager_plus_breakpoints', '', 'id='.$id);

$field = $form->addPrioField('prio');
$field->setLabel($this->i18n('breakpoints_label_prio'));
$field->setAttribute('class', 'selectpicker form-control');
$field->setLabelField('name');

//Start - add name-field
$field = $form->addTextField('name');
$field = $form->addTextField('name', null, ($func == 'edit' ? ['readonly' => true]: []));
$field->setLabel($this->i18n('breakpoints_label_name'));
//End - add name-field

Expand Down
17 changes: 14 additions & 3 deletions pages/media_manager.groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,20 @@
//Start - get groups for this type
$sql = rex_sql::factory();
$groupsByBreakpoints = $sql->getArray('SELECT * FROM `'.rex::getTablePrefix().'media_manager_type` WHERE `group` = ? AND subgroup = 0', [$list->getValue('id')]);

if (!empty($groupsByBreakpoints)) {
foreach ($groupsByBreakpoints as $groupsByBreakpoint) {

$breakpointOrder = $sql->getArray('Select name, prio from '.rex::getTablePrefix().'media_manager_plus_breakpoints order by prio');

$newGroupsByBreakpoint = [];
foreach($breakpointOrder as $bpO) {
foreach($groupsByBreakpoints as $breakpoint) {
if('-'.$bpO['name'] === substr($breakpoint['name'], (strlen($bpO['name']) * -1 - 1))) {
$newGroupsByBreakpoint[] = $breakpoint;
}
}
}

if (!empty($newGroupsByBreakpoint)) {
foreach ($newGroupsByBreakpoint as $groupsByBreakpoint) {
$name .= '<div class="panel panel-default">';
$name .= ' <header class="panel-heading collapsed" data-toggle="collapse" data-target="#collapse-type-'.$groupsByBreakpoint['id'].'-group-'.$groupsByBreakpoint['group'].'-subgroup-'.$groupsByBreakpoint['subgroup'].'">';
$name .= ' <div class="panel-title">';
Expand Down

0 comments on commit 7f086f1

Please sign in to comment.