Beispiel #1
0
 /**
  * insert/update & upload
  */
 protected function _updateData($data = array(), $conf = null)
 {
     l($data, __METHOD__ . ' data');
     l($conf, __METHOD__ . ' conf');
     $row = $res = false;
     if (!empty($data['id'])) {
         $where = $this->getAdapter()->quoteInto('id = ?', $data['id']);
         $res = $this->update($data, $where);
         $row = $this->getById($data['id']);
         // NB! get updated row always!
     } else {
         if (!empty($conf['test'])) {
             $res = 1;
             //TEST!
         } else {
             $res = $this->_insertData($data);
         }
         if ($res) {
             $row = $this->getById($res);
         }
     }
     l($row->toArray(), __METHOD__ . ' row_as_array');
     $notify = isset($conf['notify']) ? $conf['notify'] : true;
     if ($notify) {
         if ($res) {
             $this->setN(FrontEnd::getMsg(array('update', 'ok')), 'success');
         } else {
             $this->setN(FrontEnd::getMsg(array('update', 'fail')), 'errors');
         }
     }
     #d($row);
     $upload = isset($conf['upload']) ? $conf['upload'] : true;
     if ($row && $upload) {
         if (FrontEnd::isUpload()) {
             $resu = $row->upload();
             #d($res);
             if ($resu) {
                 Zend_Registry::set('uploaded', $resu);
             } else {
                 $upload_critical = isset($conf['upload_critical']) ? $conf['upload_critical'] : false;
                 // todo: hide broken record!
                 if ($upload_critical) {
                     $row->flag_status = 0;
                     $row->save();
                     $res = false;
                 }
             }
         }
     }
     // particular post-update manipulations
     #d($row);
     if ($row) {
         $res = $row->_postUpdate();
     }
     l($res, __METHOD__ . ' RES');
     return $row;
 }