Exemplo n.º 1
0
 /**
  *
  */
 public function toHtmlLastEditor()
 {
     $event = $this->toObject();
     if ($event->current() != null) {
         return $html = '<strong>Last update:</strong> ' . substr(Sydney_Tools::getDate($event->current()->timestamp), 0, -3) . ' by ' . $event->current()->fname . ' ' . $event->current()->lname . '';
     }
 }
Exemplo n.º 2
0
 /**
  * Editing a row from a table this is typically used in the service controller combined with
  * the YUI datatable, forms and helpers
  *
  * @param String $modelName Model to affect name
  * @param String $formName Form class containing the data
  * @param array $addToRequest Associative array of fields => values to add to the request (to be inserted)
  * @param array $m2mtables Array containing the list of m2m tables to update example: array('FormelementsFormfilters','FormelementsFormvalidators') the values are coming from a subform (usually a list of checkboxes)
  * @return Int The row ID we just update or created
  */
 protected function _editfieldAction($modelName, $formName, $addToRequest = array(), $m2mtables = array())
 {
     $p = $this->getRequest()->getPost();
     $resp = array('Error...', 0);
     $msgs = array();
     $odata = array();
     $form = new $formName();
     if (!$form->isValid($p)) {
         $msgs = $form->getMessages();
         $odata = $p;
         $resp = array('Error in the form', 0);
     } else {
         if (count($addToRequest) > 0) {
             foreach ($addToRequest as $k => $v) {
                 $p[$k] = $v;
             }
         }
         $sDB = new $modelName();
         if (isset($p['id']) && preg_match('/^[0-9]{1,50}$/', $p['id'])) {
             $rows = $sDB->find($p['id']);
             if (count($rows) == 1) {
                 $row = $rows[0];
             } else {
                 $resp = array('Error data not found', 0);
             }
         } else {
             $row = $sDB->createRow();
             $isNewEntry = true;
         }
         if ($row) {
             foreach ($p as $k => $v) {
                 //if (isset($row->$k) && $k != 'id') $row->$k = $v;
                 // interface with GTP system has needed the id on datas,
                 // this is the most easy way to get the id
                 if (isset($row->{$k})) {
                     switch ($k) {
                         case substr($k, -4) == 'Date':
                             $row->{$k} = Sydney_Tools::getDate($v, Zend_Date::ISO_8601);
                             break;
                         default:
                             $row->{$k} = $v;
                             break;
                     }
                 }
             }
             try {
                 $rowId = $row->save();
                 $resp = array('OK', 1);
                 $odata = $row->toArray();
             } catch (Exception $e) {
                 $msgs = $e->getMessage();
                 $resp = array($msgs, 0);
             }
             if (method_exists($row->getTable(), 'getGtpInterface')) {
                 $gtp = $row->getTable()->getGtpInterface();
             }
         }
     }
     // update potential m2m links
     if ($form->isValid($p) && $rowId > 0 && count($m2mtables) > 0) {
         // $this->view->debug = array();
         // update the m to m tables
         foreach ($m2mtables as $v) {
             if (class_exists($v)) {
                 $subform = new $v();
                 if (method_exists($subform, 'formsUpdate')) {
                     call_user_func(array($subform, 'formsUpdate'), $p);
                 } else {
                     if (isset($p[$v])) {
                         $dt = $p[$v];
                     } else {
                         $dt = array();
                     }
                     $tblns = preg_split('/_/', $subform->getTableName());
                     if (count($tblns) == 2) {
                         $subform->delete($sDB->getTableName() . "_id = '" . $rowId . "' ");
                         foreach ($dt as $dtEl) {
                             $inserts = array();
                             $inserts[$sDB->getTableName() . '_id'] = $rowId;
                             foreach ($tblns as $lmn) {
                                 if (!isset($inserts[$lmn . '_id'])) {
                                     $inserts[$lmn . '_id'] = $dtEl;
                                 }
                             }
                             // options if any
                             $paramField = 'param-' . $v . '-' . $dtEl;
                             if (isset($p[$paramField]) && in_array('voptions', $subform->fieldsNames)) {
                                 $inserts['voptions'] = $p[$paramField];
                             }
                             $rinm = $subform->insert($inserts);
                             // $this->view->debug[] = array($v , $inserts, $rinm );
                         }
                     }
                 }
                 // END IF METHOD EXIST
             }
         }
     }
     $this->view->timeout = 4;
     $this->view->modal = false;
     $this->view->ResultSet = array('errors' => $msgs, 'entry' => $odata);
     $this->view->message = $resp[0];
     $this->view->status = $resp[1];
     if (is_object($gtp)) {
         if ($gtp->getProcess()->hasError()) {
             // rollback of insert action when gtp error
             if ($isNewEntry && $rowId) {
                 $rollBackObject = new $modelName();
                 $rollBackObject->delete('id = ' . $rowId, false);
             }
             $this->view->timeout = 6;
             $this->view->status = 0;
             $this->view->message = 'GTP ERROR: ' . $gtp->getProcess()->getErrorDescription();
             $this->view->ResultSet = array('errors' => 'GTP ERROR: ' . $gtp->getProcess()->getErrorDescription(), 'entry' => $odata);
             $this->view->ResultSet['gtp']['error_code'] = $gtp->getProcess()->getError();
             $this->view->ResultSet['gtp']['error_description'] = $gtp->getProcess()->getErrorDescription();
         }
     }
     return $rowId;
 }