/** * Execute the action */ public function execute() { $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendAddressesModel::existsGroup($this->id)) { parent::execute(); $this->record = (array) BackendAddressesModel::getGroup($this->id); BackendAddressesModel::deleteGroup($this->id); BackendAddressesModel::deleteAddressesFromGroup($this->id); BackendModel::triggerEvent($this->getModule(), 'after_delete_group', array('id' => $this->id)); $this->redirect(BackendModel::createURLForAction('groups') . '&report=deleted&var=' . urlencode($this->record['title'])); } else { $this->redirect(BackendModel::createURLForAction('groups') . '&error=non-existing'); } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); $fields['title']->isFilled(BL::err('FieldIsRequired')); $this->meta->validate(); if ($this->frm->isCorrect()) { $item['meta_id'] = $this->meta->save(); $item['title'] = $fields['title']->getValue(); $item['parent_id'] = $fields['group']->getValue() != 0 ? $fields['group']->getValue() : null; BackendAddressesModel::updateGroup($this->id, $item); $item['id'] = $this->id; if (isset($fields["addresses"])) { //--Delete addresses for that group BackendAddressesModel::deleteAddressesFromGroup($this->id); //--Get all the users $addresses = $fields["addresses"]->getValue(); foreach ($addresses as $value) { $addressGroup = array(); $addressGroup["group_id"] = $this->id; $addressGroup["address_id"] = $value; //--Add user to the group BackendAddressesModel::insertAddressToGroup($addressGroup); } } BackendModel::triggerEvent($this->getModule(), 'after_edit_group', $item); $this->redirect(BackendModel::createURLForAction('groups') . '&report=edited&highlight=row-' . $item['id']); } } }