/** * Toggle a billboard between published and unpublished. We're looking for an array of ID's to publish/unpublish * * @param $publish: 1 to publish and 0 for unpublish * @return void */ protected function toggle($publish = 1) { // Check for request forgeries Request::checkToken(['get', 'post']); // Incoming (we're expecting an array) $ids = Request::getVar('cid', array()); if (!is_array($ids)) { $ids = array($ids); } // Loop through the IDs foreach ($ids as $id) { // Load the billboard $row = Billboard::oneOrFail($id); // Only alter items not checked out or checked out by 'me' if (!$row->isCheckedOut()) { $row->set('published', $publish); if (!$row->save()) { App::abort(500, $row->getError()); return; } // Check it back in $row->checkin(); } else { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_BILLBOARDS_ERROR_CHECKED_OUT'), 'warning'); return; } } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); }
/** * Toggle a billboard between published and unpublished. * We're looking for an array of ID's to publish/unpublish * * @return void */ public function stateTask() { // Check for request forgeries Request::checkToken(['get', 'post']); if (!User::authorise('core.edit.state', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming (we're expecting an array) $ids = Request::getVar('cid', array()); if (!is_array($ids)) { $ids = array($ids); } $publish = $this->getTask() == 'publish' ? 1 : 0; // Loop through the IDs foreach ($ids as $id) { // Load the billboard $row = Billboard::oneOrFail($id); // Only alter items not checked out or checked out by 'me' if (!$row->isCheckedOut()) { $row->set('published', $publish); if (!$row->save()) { App::abort(500, $row->getError()); } // Check it back in $row->checkin(); } else { Notify::warning(Lang::txt('COM_BILLBOARDS_ERROR_CHECKED_OUT')); } } // Redirect $this->cancelTask(); }