/** * Common method to handle apply and save tasks * * @return boolean Returns true on success */ protected final function applySave() { // Load the model $model = $this->getThisModel(); if (!$model->getId()) { $model->setIDsFromRequest(); } $id = $model->getId(); $data = $this->input->getData(); if (!$this->onBeforeApplySave($data)) { return false; } // Set the layout to form, if it's not set in the URL if (is_null($this->layout)) { $this->layout = 'form'; } // Do I have a form? $model->setState('form_name', 'form.' . $this->layout); $status = $model->save($data); if ($status && $id != 0) { JResponse::setHeader('Status', '201 Created', true); // Try to check-in the record if it's not a new one $status = $model->checkin(); if ($status) { $status = $this->onAfterApplySave(); } } $this->input->set('id', $model->getId()); if (!$status) { // Redirect on error $id = $model->getId(); if ($customURL = $this->input->get('returnurl', '', 'string')) { $customURL = base64_decode($customURL); } if (!empty($customURL)) { $url = $customURL; } elseif ($id != 0) { $url = 'index.php?option=' . $this->component . '&view=' . $this->view . '&task=edit&id=' . $id . $this->getItemidURLSuffix(); } else { $url = 'index.php?option=' . $this->component . '&view=' . $this->view . '&task=add' . $this->getItemidURLSuffix(); } $this->setRedirect($url, '<li>' . implode('</li><li>', $model->getErrors()) . '</li>', 'error'); return false; } else { $session = JFactory::getSession(); $session->set($model->getHash() . 'savedata', null); return true; } }
/** * Common method to handle apply and save tasks * * @return boolean Returns true on success */ protected final function applySave() { // Load the model $model = $this->getThisModel(); if (!$model->getId()) { $model->setIDsFromRequest(); } $id = $model->getId(); $data = $this->input->getData(); $this->onBeforeApplySave($data); $status = $model->save($data); if ($status && $id != 0) { JResponse::setHeader('Status', '201 Created', true); // Try to check-in the record if it's not a new one $status = $model->checkin(); if ($status) { $status = $this->onAfterApplySave(); } } $this->input->set('id', $model->getId()); if (!$status) { // Redirect on error $id = $model->getId(); if ($customURL = $this->input->get('returnurl', '', 'string')) { $customURL = base64_decode($customURL); } $url = !empty($customURL) ? $customURL : 'index.php?option=' . $this->component . '&view=' . $this->view . '&task=edit&id=' . $id; $this->setRedirect($url, '<li>' . implode('</li><li>', $model->getErrors()), 'error') . '</li>'; return false; } else { $session = JFactory::getSession(); $session->set($model->getHash() . 'savedata', null); return true; } }