Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $newIdSequence = trim(SpoonFilter::getPostValue('new_id_sequence', null, '', 'string'));
     // list id
     $ids = (array) explode(',', rtrim($newIdSequence, ','));
     // loop id's and set new sequence
     foreach ($ids as $i => $id) {
         // build item
         $id = (int) $id;
         // change sequence
         $item['sequence'] = $i + 1;
         // update sequence
         if (BackendAddressesModel::existsGroup($id)) {
             BackendAddressesModel::updateGroup($id, $item);
         }
     }
     // success output
     $this->output(self::OK, null, 'sequence updated');
 }
Example #2
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;
             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']);
         }
     }
 }