public function manageAction($id = null) { $this->permission('manage'); $this->language->load("clinic_specifications"); $model = new \modules\clinic\models\Clinic_specifications(); $branches = new \modules\clinic\models\Clinic_branches(); $clinic_specification_branches = new \modules\clinic\models\Clinic_specification_branches(false); $clinic_specification_branches->_select = 'clinic_branch_id'; if ($id) { $model->clinic_specification_id = $id; } $model->language_id = $this->language->getDefaultLanguage(); $model->set('specification', $this->input->post('specification')); $model->set('description', $this->input->post('description')); if ($sid = $model->save()) { if ($id) { $clinic_specification_branches->clinic_specification_id = $id; $clinic_specification_branches->delete(); } foreach ($this->input->post('branches') as $branch) { $clinic_specification_branches->clinic_specification_id = $sid; $clinic_specification_branches->clinic_branch_id = $branch; $clinic_specification_branches->save(); } Uri_helper::redirect("management/clinic_specifications"); } return $this->render('clinic_specifications/manage', ['item' => $id ? $model->get() : null, 'branches' => $branches->get(), 'selected_branches' => Form_helper::objToDropdown($clinic_specification_branches->get(), 'clinic_branch_id', 'clinic_branch_id')]); }