/** * Controller view to update any instance-specific options for a given template. * * Usually consists of just access permissions and display template, but more options could come in the future. */ public function instance_movedown(){ $view = $this->getView(); $request = $this->getPageRequest(); if(!\Core\user()->checkAccess('p:/core/widgets/manage')){ return View::ERROR_ACCESSDENIED; } $instance = WidgetInstanceModel::Construct($request->getParameter(0)); if(!$instance->exists()){ return View::ERROR_NOTFOUND; } if(!$request->isPost()){ return View::ERROR_BADREQUEST; } // Figure out which instance is this one -1. $otherCriteria = [ 'site = ' . $instance->get('site'), 'template = ' . ($instance->get('template') === null ? 'NULL' : $instance->get('template')), 'page_baseurl = ' . ($instance->get('page_baseurl') === null ? 'NULL' : $instance->get('page_baseurl')), 'widgetarea = ' . $instance->get('widgetarea'), 'weight = ' . ($instance->get('weight') + 1), ]; $other = WidgetInstanceModel::Find($otherCriteria, 1); if(!$other){ \Core\set_message('Widget is already in the bottom position!', 'error'); } else{ $other->set('weight', $other->get('weight') - 1); $instance->set('weight', $instance->get('weight') + 1); $other->save(); $instance->save(); } \Core\go_back(); }