Exemplo n.º 1
0
 /**
  * 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;
             $item['id'] = BackendAddressesModel::insertGroup($item);
             if (isset($fields["addresses"])) {
                 //--Get all the users
                 $addresses = $fields["addresses"]->getValue();
                 foreach ($addresses as $value) {
                     $userGroup = array();
                     $userGroup["group_id"] = $item['id'];
                     $userGroup["address_id"] = $value;
                     //--Add user to the group
                     BackendAddressesModel::insertAddressToGroup($userGroup);
                 }
             }
             BackendModel::triggerEvent($this->getModule(), 'after_add_group', $item);
             $this->redirect(BackendModel::createURLForAction('groups') . '&report=added&highlight=row-' . $item['id']);
         }
     }
 }