Beispiel #1
0
 /**
  * Process a request from the Editor client-side to get / set data.
  *  @param array $data Typically $_POST or $_GET as required by what is sent by Editor
  *  @return self
  */
 public function process($data)
 {
     $this->_processData = $data;
     $this->_formData = isset($data['data']) ? $data['data'] : null;
     $this->_db->transaction();
     try {
         $this->_prepJoin();
         if (!isset($data['action'])) {
             /* Get data */
             $this->_out = array_merge($this->_out, $this->_get(null, $data));
         } else {
             if ($data['action'] == "remove") {
                 /* Remove rows */
                 $this->_remove($data);
             } else {
                 /* Create or edit row */
                 $valid = $this->validate($this->_out['fieldErrors'], $data);
                 // Global validation - if you want global validation - do it here
                 // $this->_out['error'] = "";
                 if ($valid) {
                     if ($data['action'] == "create") {
                         $this->_out['row'] = $this->_insert();
                     } else {
                         $this->_out['row'] = $this->_update($data['id']);
                     }
                 }
             }
         }
         $this->_db->commit();
     } catch (\Exception $e) {
         // Error feedback
         $this->_out['error'] = $e->getMessage();
         $this->_db->rollback();
     }
     // Tidy up the reply
     if (count($this->_out['fieldErrors']) === 0) {
         unset($this->_out['fieldErrors']);
     }
     if (isset($data['action']) && count($this->_out['data']) === 0) {
         unset($this->_out['data']);
     }
     if ($this->_out['error'] === '') {
         unset($this->_out['error']);
     }
     // Not required in the Editor libraries
     unset($this->_out['id']);
     return $this;
 }
Beispiel #2
0
 /**
  * Process a request from the Editor client-side to get / set data.
  *  @param array $data Typically $_POST or $_GET as required by what is sent by Editor
  *  @return self
  */
 public function process($data)
 {
     $this->_processData = $data;
     $this->_formData = isset($data['data']) ? $data['data'] : null;
     if ($this->_transaction) {
         $this->_db->transaction();
     }
     try {
         $this->_prepJoin();
         if (!isset($data['action'])) {
             /* Get data */
             $this->_out = array_merge($this->_out, $this->_get(null, $data));
         } else {
             if ($data['action'] == "upload") {
                 /* File upload */
                 $this->_upload($data);
             } else {
                 if ($data['action'] == "remove") {
                     /* Remove rows */
                     $this->_remove($data);
                     $this->_fileClean();
                 } else {
                     /* Create or edit row */
                     // Pre events so they can occur before the validation
                     foreach ($data['data'] as $id => $values) {
                         if ($data['action'] == 'create') {
                             $this->_trigger('preCreate', $values);
                         } else {
                             $id = str_replace($this->_idPrefix, '', $id);
                             $this->_trigger('preEdit', $id, $values);
                         }
                     }
                     // Validation
                     $valid = $this->validate($this->_out['fieldErrors'], $data);
                     // Global validation - if you want global validation - do it here
                     // $this->_out['error'] = "";
                     if ($valid) {
                         foreach ($data['data'] as $id => $values) {
                             $d = $data['action'] == "create" ? $this->_insert($values) : $this->_update($id, $values);
                             if ($d !== null) {
                                 $this->_out['data'][] = $d;
                             }
                         }
                     }
                     $this->_fileClean();
                 }
             }
         }
         if ($this->_transaction) {
             $this->_db->commit();
         }
     } catch (\Exception $e) {
         // Error feedback
         $this->_out['error'] = $e->getMessage();
         if ($this->_transaction) {
             $this->_db->rollback();
         }
     }
     // Tidy up the reply
     if (count($this->_out['fieldErrors']) === 0) {
         unset($this->_out['fieldErrors']);
     }
     if ($this->_out['error'] === '') {
         unset($this->_out['error']);
     }
     if (count($this->_out['ipOpts']) === 0) {
         unset($this->_out['ipOpts']);
     }
     return $this;
 }