insert() public static method

Insert an item
public static insert ( array $item ) : integer
$item array The data of the record to insert.
return integer
Beispiel #1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('street')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->isCorrect()) {
             // build item
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['street'] = $this->frm->getField('street')->getValue();
             $item['number'] = $this->frm->getField('number')->getValue();
             $item['zip'] = $this->frm->getField('zip')->getValue();
             $item['city'] = $this->frm->getField('city')->getValue();
             $item['country'] = $this->frm->getField('country')->getValue();
             // define coordinates
             $coordinates = BackendLocationModel::getCoordinates($item['street'], $item['number'], $item['city'], $item['zip'], $item['country']);
             // define latitude and longitude
             $item['lat'] = $coordinates['latitude'];
             $item['lng'] = $coordinates['longitude'];
             // insert the item
             $item['id'] = BackendLocationModel::insert($item);
             // everything is saved, so redirect to the overview
             if ($item['lat'] && $item['lng']) {
                 // trigger event
                 BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             }
             // redirect
             $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $item['id'] . '&report=added&var=' . urlencode($item['title']));
         }
     }
 }