diff --git a/htdocs/blocktype/lib.php b/htdocs/blocktype/lib.php index 5cf1c8fbf1a12836a1811921d90fc9793c0d45b0..a29b2c313b2a97d4695d86847260bd1e30de784f 100644 --- a/htdocs/blocktype/lib.php +++ b/htdocs/blocktype/lib.php @@ -839,10 +839,6 @@ class BlockInstance { private $row; private $column; private $order; - private $canmoveleft; - private $canmoveright; - private $canmoveup; - private $canmovedown; private $maxorderincolumn; private $artefacts = array(); private $temp = array(); @@ -1150,7 +1146,6 @@ class BlockInstance { global $USER; safe_require('blocktype', $this->get('blocktype')); - $movecontrols = array(); $this->inedit = true; $blocktypeclass = generate_class_name('blocktype', $this->get('blocktype')); try { @@ -1193,45 +1188,6 @@ class BlockInstance { $js = ''; $css = ''; } - - if (!defined('JSON') && !$jsreply) { - if ($this->get('canmoveleft')) { - $movecontrols[] = array( - 'column' => $this->get('column') - 1, - 'order' => $this->get('order'), - 'title' => $title == '' ? get_string('movethisblockleft', 'view') : get_string('moveblockleft', 'view', "'$title'"), - 'arrow' => "icon icon-long-arrow-alt-left", - 'dir' => 'left', - ); - } - if ($this->get('canmovedown')) { - $movecontrols[] = array( - 'column' => $this->get('column'), - 'order' => $this->get('order') + 1, - 'title' => $title == '' ? get_string('movethisblockdown', 'view') : get_string('moveblockdown', 'view', "'$title'"), - 'arrow' => 'icon icon-long-arrow-alt-down', - 'dir' => 'down', - ); - } - if ($this->get('canmoveup')) { - $movecontrols[] = array( - 'column' => $this->get('column'), - 'order' => $this->get('order') - 1, - 'title' => $title == '' ? get_string('movethisblockup', 'view') : get_string('moveblockup', 'view', "'$title'"), - 'arrow' => 'icon icon-long-arrow-alt-up', - 'dir' => 'up', - ); - } - if ($this->get('canmoveright')) { - $movecontrols[] = array( - 'column' => $this->get('column') + 1, - 'order' => $this->get('order'), - 'title' => $title == '' ? get_string('movethisblockright', 'view') : get_string('moveblockright', 'view', "'$title'"), - 'arrow' => 'icon icon-long-arrow-alt-right', - 'dir' => 'right', - ); - } - } } $configtitle = $title == '' ? call_static_method($blocktypeclass, 'get_title') : $title; @@ -1245,7 +1201,6 @@ class BlockInstance { $smarty->assign('column', $this->get('column')); $smarty->assign('order', $this->get('order')); $smarty->assign('blocktype', $this->get('blocktype')); - $smarty->assign('movecontrols', $movecontrols); $smarty->assign('configurable', call_static_method($blocktypeclass, 'has_instance_config')); $smarty->assign('configure', $configure); // Used by the javascript to rewrite the block, wider. $smarty->assign('configtitle', $configtitle); diff --git a/htdocs/js/views.js b/htdocs/js/views.js index 7442aac71b076243b82ac696870d38608fe0f229..c9b28fc3db719ab1ec319d4082ce8a2e2b562cc3 100644 --- a/htdocs/js/views.js +++ b/htdocs/js/views.js @@ -275,16 +275,10 @@ // Rewrite the delete buttons to be ajax rewriteDeleteButtons(); - // Show the keyboard-accessible ajax move buttons - rewriteMoveButtons(); - // Setup the 'add block' dialog setupPositionBlockDialog(); - showColumnBackgroundsOnSort(); - makeNewBlocksDraggable(); - makeExistingBlocksSortable(); $(workspace).show(); @@ -357,7 +351,6 @@ sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) { $(category).html(data.data); makeNewBlocksDraggable(); - showColumnBackgroundsOnSort(); // the column has changed size, pass on to listeners $(window).trigger('colresize'); @@ -429,7 +422,6 @@ $('.blocktype-drag').draggable({ start: function(event, ui) { - showColumnBackgrounds(); $(window).trigger('colresize'); }, helper: function(event) { @@ -445,8 +437,6 @@ }, connectToSortable: '.js-col-row .column .column-content', stop: function(event, ui) { - // see also showColumnBackgroundsOnSort for clicking in place without dragging - hideColumnBackgrounds(); }, appendTo: 'body' }); @@ -489,75 +479,6 @@ } } - function makeExistingBlocksSortable() { - - // Make existing and new blocks sortable - $('.column .column-content').sortable({ - handle: '.js-heading', - items: '.js-blockinstance', - cursorAt: {left: 100, top: 10}, - connectWith: '.js-col-row .column .column-content', - placeholder: 'block-placeholder', - tolerance: "pointer", - activate: function(event, ui) { - // Fix for dragging blocks to narrow divs: - // Wide elements must be centred on narrow divs to make droppable. - // This is not always evident to the user. - // Instead set a standard small width when starting to sort. - // Dynamically setting width on over event doesn't work, as - // Sortable seems to cache helper proportions. - // Also if height of dragging block is greater than height - // row(s) above it then it can't be dropped in that row. - // Could use a custom version of Sortable in future? - ui.helper.width(200); - ui.helper.height('auto'); - }, - beforeStop: function(event, ui) { - - var whereTo = getBlockinstanceCoordinates(ui.helper); - - if (ui.helper.find('.blocktype-radio').length) { - - addNewBlock(whereTo, ui.helper.find('input.blocktype-radio').val()); - $('.ui-draggable-dragging').remove(); - - } else { - //move existing block - var uihId = ui.helper.attr('id'), - blockinstanceId = uihId.substr(uihId.lastIndexOf('_') + 1); - - moveBlock(whereTo, blockinstanceId); - } - - window.setTimeout(function(){ - $(window).trigger('colresize'); - }, 300); - - }, - - update: function(event, ui) { - $('.js-col-row .column-content').each(function() { - $(this).css('min-height', ''); - }); - }, - - start: function(event, ui) { - // Fix for dragging blocks to narrow divs: - // Wide elements must be centred on narrow divs to make droppable. - // This is not always evident to the user. - // Instead set a standard small width when starting to sort. - // Dynamically setting width on over event doesn't work, as - // Sortable seems to cache helper proportions. - // Also if height of dragging block is greater than height - // row(s) above it then it can't be dropped in that row. - // Could use a custom version of Sortable in future? - ui.helper.width($(this).outerWidth()); - ui.helper.height($(this).find('.drag-handle').outerHeight()); - } - }); - - } // end of makeNewBlocksSortable() - function cellChanged() { $(this).closest('.js-cell-chooser').find('.active').removeClass('active'); @@ -629,25 +550,6 @@ }); } - function showColumnBackgrounds() { - $('.js-col-row .column-content').addClass('block-drop-on', 100); - } - - function hideColumnBackgrounds() { - $('.js-col-row .column-content').removeClass('block-drop-on', 500); - } - - function showColumnBackgroundsOnSort() { - $('.blockinstance .blockinstance-header, .blocktype-list .blocktype').on("mousedown", function() { - showColumnBackgrounds(); - }); - - $('.blockinstance .blockinstance-header, .blocktype-list .blocktype').on("mouseup", function() { - hideColumnBackgrounds(); - }); - } - - function insertBlockStub(newblock, whereTo) { var columnContent = $('#row_'+whereTo['row']+'_column_'+whereTo['column']).find('div.column-content'); if (whereTo['order'] == 1) { @@ -755,84 +657,6 @@ }); } - /* - * Shows all keyboard-accessible ajax move buttons - */ - function rewriteMoveButtons() { - rewriteMoveButton(workspace.find('.keyboardmovebutton')); - } - - /* - * Shows and sets up one keyboard-accessible ajax move button - * - */ - function rewriteMoveButton(button) { - - button.removeClass('d-none'); - - button.on('click', function(e) { - e.stopPropagation(); - e.preventDefault(); - - computeColumnInputs($('#newblock')); - - var self = $(this), - addblockdialog = $('#newblock').removeClass('d-none'); - prevcell = self.closest('.column-content'), - order = prevcell.children().index(self.closest('.blockinstance')), - row = workspace.find('.js-col-row').index(self.closest('.js-col-row')), - column = self.closest('.js-col-row').children().index(self.closest('.column')), - radio = addblockdialog.find('.cell-chooser').children().eq(row).find('input').eq(column), - changefunction = function() { - if (radio.prop('checked')) { - $('#newblock_position option').eq(order + 1).remove(); - } - }; - - - radio.on('change', changefunction); - radio.prop('checked', true).trigger('change'); - - $('#newblock_position').prop('selectedIndex', order); - - addblockdialog.one('dialog.end', function(event, options) { - if (options.saved) { - var blockinstanceId = self.attr('data-id'), - newcell, - currentblock, - lastindex; - - moveBlock(options, blockinstanceId); - - newcell = workspace.find('.js-col-row').eq(options['row'] - 1) - .find('.column-content').eq(options['column'] - 1); - - currentblock = self.closest('.blockinstance'); - lastindex = newcell.children().length; - - if (newcell[0] == prevcell[0]) { - lastindex -= 1; - } - - newcell.append(currentblock); - options['order'] -= 1; - if (options['order'] < lastindex) { - newcell.children().eq(options['order']).before(newcell.children().last()); - } - } - - radio.off('change', changefunction); - self.trigger("focus"); - }); - - addblockdialog.find('h4.modal-title').text(self.attr('alt')); - - addblockdialog.find('.deletebutton').trigger("focus"); - - keytabbinginadialog(addblockdialog, addblockdialog.find('.deletebutton'), addblockdialog.find('.cancel')); - }); - } - function computeColumnInputs(dialog) { var inputcontainer = dialog.find('.blockinstance-content #newblock_cellchooser_container'), result = $('
').addClass('cell-chooser js-cell-chooser'), @@ -911,7 +735,6 @@ if (data.data.html) { $('#blockinstance_' + instanceId + ' .blockinstance-content').html(data.data.html); } - hideColumnBackgrounds(); }); } diff --git a/htdocs/lang/en.utf8/error.php b/htdocs/lang/en.utf8/error.php index 7f44088cdcf4f1a95ffb47f7c05fc4c09661493b..a018be2151e22cbf24cf0c7394d53f616992c3fc 100644 --- a/htdocs/lang/en.utf8/error.php +++ b/htdocs/lang/en.utf8/error.php @@ -108,7 +108,6 @@ $string['notinthesamegroup'] = 'You cannot view this user\'s profile because you $string['notinthesameinstitution'] = 'You cannot view this user\'s profile because you are not members of the same institution.'; $string['notinstitutionmember'] = 'You cannot view this page because you are not a member of the institution to which this page belongs.'; $string['invalidlayoutselection'] = 'You tried to select a layout that doesn\'t exist.'; -$string['invalidnumrows'] = 'You have tried to create a layout with more than the allowed maximum number of rows. (This should not be possible; please notify your site\'s administrator.)'; $string['previewimagegenerationfailed'] = 'Sorry, there was a problem generating the preview image.'; $string['viewtemplatenotfound'] = 'Default page template not found.'; @@ -126,8 +125,6 @@ $string['invalidviewaction'] = 'Invalid page control action: %s'; $string['invaliduser'] = 'Invalid user selected'; $string['missingparamblocktype'] = 'Try selecting a block type to add first.'; -$string['missingparamcolumn'] = 'Missing column specification'; -$string['missingparamrow'] = 'Missing row specification'; $string['missingparamorder'] = 'Missing order specification'; $string['missingparamid'] = 'Missing id'; diff --git a/htdocs/lang/en.utf8/view.php b/htdocs/lang/en.utf8/view.php index 33a059a5236469303fba3851a8358d49879dcd5c..228203c7228679e59ed74a74d1413292105c045f 100644 --- a/htdocs/lang/en.utf8/view.php +++ b/htdocs/lang/en.utf8/view.php @@ -326,14 +326,6 @@ $string['add'] = 'Add'; $string['addcolumn'] = 'Add column'; $string['remove'] = 'Remove'; $string['removecolumn'] = 'Remove this column'; -$string['moveblockleft'] = "Move %s block left"; -$string['movethisblockleft'] = "Move this block left"; -$string['moveblockdown'] = "Move %s block down"; -$string['movethisblockdown'] = "Move this block down"; -$string['moveblockup'] = "Move %s block up"; -$string['movethisblockup'] = "Move this block up"; -$string['moveblockright'] = "Move %s block right"; -$string['movethisblockright'] = "Move this block right"; $string['moveblock2'] = 'Move block'; $string['moveblock'] = 'Move %s block'; $string['movethisblock'] = 'Move this block'; @@ -350,7 +342,6 @@ $string['celltitle'] = 'Cell'; $string['basicoptions'] = 'Basic options'; $string['advancedoptions'] = 'Advanced options'; -$string['changecolumnlayoutfailed'] = 'Could not change the column layout. Someone else may have been editing the layout at the same time. Please try again later.'; $string['Row'] = 'Row'; $string['layoutpreviewimage'] = 'Layout preview image'; @@ -368,8 +359,6 @@ $string['column'] = 'column'; $string['row'] = 'row'; $string['columns'] = 'columns'; $string['rows'] = 'rows'; -$string['cantaddcolumn'] = 'You cannot add any more columns to this page.'; -$string['cantremovecolumn'] = 'You cannot remove the last column from this page.'; $string['blocktypecategory.external'] = 'External'; $string['blocktypecategory.fileimagevideo'] = 'Media'; diff --git a/htdocs/lib/view.php b/htdocs/lib/view.php index bc6cfa2d1ecc2da9224a5f1a7697cff10db07022..6eaefb468ba213a7fcfceeac47c04dcb80837e18 100644 --- a/htdocs/lib/view.php +++ b/htdocs/lib/view.php @@ -45,8 +45,6 @@ class View { private $theme; private $rows; private $columns; - private $dirtyrows; // for when we change stuff - private $dirtycolumns; // now includes reference to row [row][column] private $tags; private $categorydata; private $template; @@ -311,8 +309,6 @@ class View { $this->atime = time(); $this->rows = array(); $this->columns = array(); - $this->dirtyrows = array(); - $this->dirtycolumns = array(); $this->oldcolumnsperrow = $this->get('columnsperrow'); // set only for existing views - _create provides default value // Ignore if the constructor is called with deleted set to true @@ -2062,8 +2058,6 @@ class View { case 'configureblockinstance': // requires action_configureblockinstance_id_\d_column_\d_order_\d case 'acsearch': // requires action_acsearch_id_\d case 'moveblockinstance': // requires action_moveblockinstance_id_\d_row_\d_column_\d_order_\d - case 'addcolumn': // requires action_addcolumn_\d_row_\d_before_\d - case 'removecolumn': // requires action_removecolumn_\d_row_\d_column_\d case 'changetheme': break; default: @@ -2190,11 +2184,7 @@ class View { $rowdata = array(); // make sure we've already built up the structure for ($i = 1; $i <= $this->numrows; $i++) { - $force = false; - if (array_key_exists($i, $this->dirtycolumns) || array_key_exists($i, $this->dirtyrows)) { - $force = true; - } - $this->build_column_datastructure($i, $force); + $this->build_column_datastructure($i); $rowdata[$i] = $this->columns[$i]; } return $rowdata; @@ -2206,12 +2196,8 @@ class View { * @return mixed array */ public function get_column_datastructure($row=1, $column=0) { - // make sure we've already built up the structure - $force = false; - if (isset($this->dirtycolumns[$row]) && array_key_exists($column, $this->dirtycolumns[$row])) { - $force = true; - } - $this->build_column_datastructure($row, $force); + + $this->build_column_datastructure($row); if (empty($column)) { return $this->columns[$row]; @@ -2395,9 +2381,7 @@ class View { 'order' => $values['order'], ) ); - $this->shuffle_cell($values['row'], $values['column'], $values['order']); $bi->commit(); - $this->dirtycolumns[$values['row']][$values['column']] = 1; if ($values['returndata'] === 'id') { return $bi->get('id'); @@ -2432,7 +2416,7 @@ class View { if (!$bi->get('view')) { $bi->set('view', $this->get('id')); } - $this->shuffle_cell($bi->get('row'), $bi->get('column'), $bi->get('order')); + $bi->commit(); } @@ -2454,9 +2438,7 @@ class View { } db_begin(); $bi->delete(); - $this->shuffle_cell($bi->get('row'), $bi->get('column'), null, $bi->get('order')); db_commit(); - $this->dirtycolumns[$bi->get('row')][$bi->get('column')] = 1; } /** @@ -2613,52 +2595,9 @@ class View { if ($bi->get('view') != $this->get('id')) { throw new AccessDeniedException(get_string('blocknotinview', 'view', $bi->get('id'))); } - db_begin(); - // moving within the same column and row - if ($bi->get('row') == $values['row'] && $bi->get('column') == $values['column']) { - if ($values['order'] == $bi->get('order') + 1 || $values['order'] == $bi->get('order') -1) { - // we're switching two, it's a bit different - // set the one we're moving to out of range (to 0) - // double quotes required for field names to avoid exception - set_field_select('block_instance', 'order', 0, '"view" = ? AND "row" = ? AND "column" = ? AND "order" = ?', array($this->get('id'), $values['row'], $values['column'], $values['order']) ); - // set the new order - set_field_select('block_instance', 'order', $values['order'], '"view" = ? AND "row" = ? AND "column" = ? AND "order" = ?', array($this->get('id'), $values['row'], $values['column'], $bi->get('order')) ); - // move the old one back to where the moving one was. - set_field_select('block_instance', 'order', $bi->get('order'), '"view" = ? AND "row" = ? AND "column" = ? AND "order" = ?', array($this->get('id'), $values['row'], $values['column'], 0) ); - // and set it in the object for good measure. - $bi->set('order', $values['order']); - } - else if ($values['order'] == $this->get_current_max_order($values['row'], $values['column'])) { - // moving to the very bottom - set_field_select('block_instance', 'order', 0, '"view" = ? AND "row" = ? AND "column" = ? AND "order" = ?', array($this->get('id'), $values['row'], $values['column'], $bi->get('order')) ); - $this->shuffle_helper('order', 'down', '>=', $bi->get('order'), '"column" = ? AND "row" = ?', array($bi->get('column'), $values['row'])); - set_field_select('block_instance', 'order', $values['order'], '"order" = ? AND "view" = ? AND "row" = ? AND "column" = ?', array(0, $this->get('id'), $values['row'], $values['column'])); - $bi->set('order', $values['order']); - } - else { - $this->shuffle_cell($values['row'], $bi->get('column'), $values['order'], $bi->get('order')); - } - } - // moving to another column - else { - // first figure out if we've asked to add it somewhere sensible - // eg if we're moving a low down block into an empty column - $newmax = $this->get_current_max_order($values['row'], $values['column']); - if ($values['order'] > $newmax+1) { - $values['order'] = $newmax+1; - } - // remove it from the old column - $this->shuffle_cell($bi->get('row'), $bi->get('column'), null, $bi->get('order')); - // and make a hole in the new column - $this->shuffle_cell($values['row'], $values['column'], $values['order']); - } - $bi->set('column', $values['column']); - $bi->set('row', $values['row']); - $bi->set('order', $values['order']); + $bi->commit(); - $this->dirtycolumns[$values['row']][$bi->get('column')] = 1; - $this->dirtycolumns[$values['row']][$values['column']] = 1; - db_commit(); + // Because embedly externalvideo blocks have their original content changed // by the cdn.embedly.com/widgets/platform.js file to use iframe data the info // is lost on block move so we need to referesh the block with its original content @@ -2880,323 +2819,6 @@ class View { return $bi->render_editing(true); } - /** - * adds a column to a view - * - * @param array $values parameters for this function - * before => int column to insert the new column before - * returndata => boolean whether to return the html - * for the new column or not (ajax requests need this) - * - */ - public function addcolumn($values) { - - if (!array_key_exists('before', $values) || empty($values['before']) || !array_key_exists('row', $values) || empty($values['row'])) { - throw new ParamOutOfRangeException(get_string('missingparamcolumn', 'error')); - } - - $columnsperrow = $this->get('columnsperrow'); - $columnsthisrow = clone $columnsperrow[$values['row']]; - $thisrownumcolumns = $columnsperrow[$values['row']]->columns; - - // simple check for valid number of columns - $newlayouts = get_records_sql_array('SELECT vlc.id - FROM {view_layout_columns} vlc - WHERE vlc.columns = ?', array($thisrownumcolumns + 1) ); - - if (!$newlayouts) { - throw new ParamOutOfRangeException(get_string('cantaddcolumn', 'view')); - } - db_begin(); - - $columnsthisrow->columns = $thisrownumcolumns + 1; - $columnsperrow[$values['row']] = $columnsthisrow; - $this->set('columnsperrow', $columnsperrow); //set makes dirty=1, which enables commit; numcolumnsperrrow used as check by layout submit function - - if ($values['before'] != ($thisrownumcolumns + 1)) { - $this->shuffle_helper('column', 'up', '>=', $values['before'], 'row = ?', array($values['row'])); - } - $this->set('layout', null); - $this->commit(); - $currentrowcolumns = $columnsperrow[$values['row']]->columns; - for ($i = $values['before']; $i <= $currentrowcolumns; $i++) { - $this->dirtycolumns[$values['row']][$i] = 1; - } - - $this->columns[$values['row']][$currentrowcolumns] = null; // set the key - db_commit(); - if ($values['returndata']) { - return $this->build_column($values['row'], $values['before'], true); - } - } - - - /** - * removes an entire column and redistributes its blocks - * - * @param array $values parameters for this function - * column => int column to remove - * - */ - public function removecolumn($values) { - if (!array_key_exists('column', $values) || empty($values['column']) || !array_key_exists('row', $values) || empty($values['row'])) { - throw new ParamOutOfRangeException(get_string('missingparamcolumn', 'error')); - } - if (!array_key_exists('removerow', $values)) { - $values['removerow'] = false; - } - $columnsperrow = $this->get('columnsperrow'); - $numcolumnsthisrow = clone $columnsperrow[$values['row']]; - $thisrownumcolumns = $columnsperrow[$values['row']]->columns; - - if (!$values['removerow']) { - // simple check for valid number of columns - $newlayouts = get_records_sql_array('SELECT vlc.id - FROM {view_layout_columns} vlc - WHERE vlc.columns = ?', array($thisrownumcolumns - 1) ); - if (!$newlayouts) { - throw new ParamOutOfRangeException(get_string('cantremovecolumn', 'view')); - } - } - else if ($thisrownumcolumns == 0) { - throw new ParamOutOfRangeException(get_string('cantremovecolumn', 'view')); - } - - db_begin(); - $numcolumns = $thisrownumcolumns - 1; - - // if removing row, move blocks to previous row - if ($values['removerow']) { - $prevrownumcolumns = $columnsperrow[$values['row']-1]->columns; - $prevrowcolumnmax = array(); // keep track of where we're at in each column - $currentcol = 1; - if ($blocks = $this->get_column_datastructure($values['row'], $values['column'])) { - // we have to rearrange them first - foreach ($blocks['blockinstances'] as $block) { - if ($currentcol > $prevrownumcolumns) { - $currentcol = 1; - } - if (!array_key_exists($currentcol, $prevrowcolumnmax)) { - $prevrowcolumnmax[$currentcol] = $this->get_current_max_order($values['row']-1, $currentcol); - } - $this->shuffle_cell($values['row']-1, $currentcol, $prevrowcolumnmax[$currentcol]+1); - $block->set('row', $values['row']-1); - $block->set('column', $currentcol); - $block->set('order', $prevrowcolumnmax[$currentcol]+1); - $block->commit(); - $prevrowcolumnmax[$currentcol]++; - $currentcol++; - } - } - } - else { - $columnmax = array(); // keep track of where we're at in each column - $currentcol = 1; - if ($blocks = $this->get_column_datastructure($values['row'], $values['column'])) { - // we have to rearrange them first - foreach ($blocks['blockinstances'] as $block) { - if ($currentcol > $numcolumns) { - $currentcol = 1; - } - if ($currentcol == $values['column']) { - $currentcol++; // don't redistrubute blocks here! - } - if (!array_key_exists($currentcol, $columnmax)) { - $columnmax[$currentcol] = $this->get_current_max_order($values['row'], $currentcol); - } - $this->shuffle_cell($values['row'], $currentcol, $columnmax[$currentcol]+1); - $block->set('row', $values['row']); - $block->set('column', $currentcol); - $block->set('order', $columnmax[$currentcol]+1); - $block->commit(); - $columnmax[$currentcol]++; - $currentcol++; - } - } - } - - $this->set('layout', null); - $numcolumnsthisrow->columns = $thisrownumcolumns - 1; - $columnsperrow[$values['row']] = $numcolumnsthisrow; - $this->set('columnsperrow', $columnsperrow); //set makes dirty=1, which enables commit; columnsperrrow used as check by layout submit function - // now shift all blocks one left and we're done - $this->shuffle_helper('column', 'down', '>', $values['column'], 'row = ?', array($values['row'])); - $this->commit(); - db_commit(); - unset($this->columns[$values['row']]); // everything has changed - } - /** - * adds a row to a view - * - * @param array $values parameters for this function - * before => int row to insert the new row before - * returndata => boolean whether to return the html - * for the new row or not (ajax requests need this) - * - */ - public function addrow($values) { - - if (!array_key_exists('before', $values) || empty($values['before']) || !array_key_exists('newlayout', $values) || empty($values['newlayout'])) { - throw new ParamOutOfRangeException(get_string('exceededmaxrows', 'error')); - } - - if ($values['before'] > self::$maxlayoutrows) { - throw new ParamOutOfRangeException(get_string('invalidnumrows', 'error')); - } - - $columnsperrow = $this->get('columnsperrow'); - - db_begin(); - $this->set('numrows', $this->get('numrows') + 1); - if ($values['before'] != ($this->get('numrows'))) { - $this->shuffle_helper('row', 'up', '>=', $values['before']); - } - $this->set('layout', null); - - $layoutrows = $this->get_layoutrows(); - $newrowcolumnsindex = $layoutrows[$values['newlayout']][$values['before']]; - $newrownumcolumns = self::$layoutcolumns[$newrowcolumnsindex]->columns; - - $columnsperrow[$values['before']] = (object)array('row' => $values['before'], 'columns' => $newrownumcolumns); - $this->set('columnsperrow', $columnsperrow); //set makes dirty=1, which enables commit; columnsperrrow used as check by layout submit function - - $this->commit(); - // @TODO this could be optimised by actually moving the keys around, - // but I don't think there's much point as the objects aren't persistent - // unless we're in ajax land, in which case it would be an optimisation - for ($i = $values['before']; $i <= $this->get('numrows'); $i++) { - $this->dirtyrows[$i] = 1; - } - $this->rows[$this->get('numrows')] = null; // set the key - db_commit(); - if ($values['returndata']) { - return $this->build_row($values['before'], true); // MK follow up - AJAX - } - } - - /** - * removes an entire row and redistributes its blocks - * - * @param array $values parameters for this function - * row => int row to remove - * - */ - public function removerow($values) { - // $layoutrows declared in layout.php - global $SESSION; - - if (!array_key_exists('row', $values) || empty($values['row'])) { - throw new ParamOutOfRangeException(get_string('missingparamrow', 'error')); - } - - db_begin(); - // for each column, call removecolumn - // first retrieve number of columns in row - $layoutrows = $this->get_layoutrows(); - $layout = $values['layout']; - $thisrownumcolumns = $layout->rows[$values['row']]['columns']; - - for ($i = $thisrownumcolumns; $i > 0 ; $i--) { - $this->removecolumn(array('row' => $values['row'], 'column' => $i, 'removerow' => true)); - } - - // check for sucessful removal of columns - $dbcolumns = get_field('view_rows_columns', 'columns', 'view', $this->get('id'), 'row', $values['row']); - - if ($dbcolumns != 0) { - db_rollback(); - $SESSION->add_error_msg(get_string('changecolumnlayoutfailed', 'view')); - redirect(get_config('wwwroot') . 'view/editlayout.php?id=' . $this->get('id') . ($new ? '&new=1' : '')); - } - - $this->set('numrows', $this->get('numrows') - 1); - $this->set('layout', null); - - $columnsperrow = $this->get('columnsperrow'); - unset($columnsperrow[$values['row']]); - $this->set('columnsperrow', $columnsperrow); //set makes dirty=1, which enables commit; columnsperrrow used as check by layout submit function - - $this->commit(); - db_commit(); - unset($this->rows[$values['row']]); - } - /** - * helper function for re-ordering block instances within a cell row x column - * @param int $row the row - * @param int $column the column of the cell to re-order - * @param int $insert the order we need to insert - * @param int $remove the order we need to move out of the way - */ - private function shuffle_cell($row, $column, $insert=0, $remove=0) { - /* - inserting something in the middle from somewhere else (insert and remove) - we're either reshuffling after a delete, (no insert), - inserting something in the middle out of nowhere (no remove) - */ - // inserting and removing - if (!empty($remove)) { - // move it out of range (set to 0) - set_field_select('block_instance', 'order', 0, '"order" = ? AND "view" = ? AND "row" = ? AND "column" = ?', array($remove, $this->get('id'), $row, $column)); - if (!empty($insert)) { - // shuffle everything - if ($insert > $remove) { - $this->shuffle_helper('order', 'down', '>=', $remove, '"order" <= ? AND "row" = ? AND "column" = ?', array($insert, $row, $column)); - } - else { - $this->shuffle_helper('order', 'up', '>=', $insert, '"row" = ? AND "column" = ?', array($row, $column)); - // shuffle everything down - $this->shuffle_helper('order', 'down', '>', $remove, '"row" = ? AND "column" = ?', array($row, $column)); - } - // now move it back - set_field_select('block_instance', 'order', $insert, '"order" = ? AND "view" = ? AND "row" = ? AND "column" = ?', array(0, $this->get('id'), $row, $column)); - } - else { - // shuffle everything down - $this->shuffle_helper('order', 'down', '>', $remove, '"row" = ? AND "column" = ?', array($row, $column)); - } - } - else if (!empty($insert)) { - // shuffle everything up - $this->shuffle_helper('order', 'up', '>=', $insert, '"row" = ? AND "column" = ?', array($row, $column)); - } - } - - private function shuffle_helper($field, $direction, $operator, $value, $extrawhere='', $extravalues='') { - - /* - * We need to use execute_sql here because ADODB naturally - * wants to convert "order+1" into string fields. - * - * Additionally, we need to move a set of rows in step, and - * sign-switching is one way to do that without violating constraints. - */ - - if (empty($extrawhere)) { - $extrawhere = ''; - } - else { - $extrawhere = ' AND ' . $extrawhere; - } - if (empty($extravalues) || !is_array($extravalues) || count($extravalues) == 0) { - $extravalues = array(); - } - - // first move them one but switch to negative - $sql = 'UPDATE {block_instance} - SET "' . $field .'" = (-1 * ("' . $field . '") ' . (($direction == 'up') ? '-' : '+') . ' 1) - WHERE "view" = ? AND "' . $field . '"' . $operator . ' ? ' . $extrawhere; - - execute_sql($sql, array_merge(array($this->get('id'), $value), $extravalues)); - - // and now flip to positive again - $sql = 'UPDATE {block_instance} - SET "' . $field . '" = ("' . $field . '" * -1) - WHERE "view" = ? AND "' . $field . '" < 0 ' . $extrawhere; - - execute_sql($sql, array_merge(array($this->get('id')), $extravalues)); - - } - /** * returns the current max block position within a column */ diff --git a/htdocs/theme/raw/templates/view/blocktypecontainerediting.tpl b/htdocs/theme/raw/templates/view/blocktypecontainerediting.tpl index f2ec5a05bf630bd080afb1f131d8ecd0d461d987..c5aab3fb4c62fe76d3ba56a5ac71c1368c8274b2 100644 --- a/htdocs/theme/raw/templates/view/blocktypecontainerediting.tpl +++ b/htdocs/theme/raw/templates/view/blocktypecontainerediting.tpl @@ -12,11 +12,6 @@ - {foreach from=$movecontrols item=item} - - {/foreach} {if $configurable && !$configure}