public function saveItem($input) { $form = new AppForm(); $form = $input; $values = $form->getValues(); $update = false; if (isset($this->request->post['id'])) { $id = $this->request->post['id']; $update = true; } else { $id = 0; } try { if ($update) { $this->items->update($id, $values); } else { $id = $this->items->insert($values); } } catch (DibiException $e) { $this->flashMessage('Error! ' . $e->getMessage(), 'err'); } $this->cleanCache('application/system', 'categories'); $this->flashMessage('Item has been saved.', 'ok'); if ($form['save']->isSubmittedBy()) { $this->redirect('edit', array('id' => $id)); } elseif ($form['add']->isSubmittedBy()) { $this->redirect('add'); } else { $this->redirect('default'); } }
/** * Simple update * * @param array $data * */ public function update($data = NULL) { if ($data) { $this->object()->extend($data); } else { $data = $this->getData(); } if (isset($data[$this->primary])) { unset($data[$this->primary]); } event('Db_ORM.update', $this, $data); if ($result = $this->db->update($this->table, $data, array($this->primary => $this->{$this->primary}))) { $this->cache($this->{$this->primary}, FALSE, array(), 0); } return $result; }
/** * Perform update on start document to save this relationship */ protected function update() { if (!$this->hasUniqueIndex() || $this->isNew()) { return false; } $property = Relationship::REL_PREFIX . $this->getType(); // add id of end document and each properties for update set. foreach ($this->getProperties(false) as $key => $value) { $properties[$property . '.$.' . $key] = $value; } // Select de relationship by end document id and collection name // It's have to be unique per relation type $criteria = $this->getUniqueIndex(); unset($properties['_id']); unset($properties['_collection']); unset($properties['_class']); $update = ['$set' => $properties]; $result = $this->start_doc->update($criteria, $update); if ($result === true) { $this->toggleProperties(); } return $result; }
public function update($id, $values) { return $this->gateway->update($this->getSingleUrl($id), $values); }
/** * testFactureFournisseurUpdate * * @param Object $localobject Supplier invoice * @return int * * @depends testFactureFournisseurFetch * The depends says test is run only if previous is ok */ public function testFactureFournisseurUpdate($localobject) { global $conf, $user, $langs, $db; $conf = $this->savconf; $user = $this->savuser; $langs = $this->savlangs; $db = $this->savdb; $localobject->note = 'New note after update'; $result = $localobject->update($user); print __METHOD__ . " id=" . $localobject->id . " result=" . $result . "\n"; $this->assertLessThan($result, 0); return $localobject; }
/** * testCompanyBankAccountOther * * @param Object $localobject Bank account * @return int * * @depends testCompanyBankAccountFetch * The depends says test is run only if previous is ok */ public function testCompanyBankAccountOther($localobject) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject->owner='New owner'; $result=$localobject->update($user); print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); return $localobject->id; }
/** * Function called when a Dolibarrr business event is done. * All functions "run_trigger" are triggered if file * is inside directory core/triggers * * @param string $action Event action code * @param Object $object Object * @param User $user Object user * @param Translate $langs Object langs * @param conf $conf Object conf * @return int <0 if KO, 0 if no triggered ran, >0 if OK */ public function run_trigger($action, $object, $user, $langs, $conf) { // Put here code you want to execute when a Dolibarr business events occurs. // Data and type of action are stored into $object and $action // Users if ($action === 'PROJECT_CREATE') { if (empty($object->array_options['options_color'])) { dol_include_once('/scrumboard/lib/scrumboard.lib.php'); $object->array_options['options_color'] = '#' . scrumboard_random_color(); $object->update($user, 1); } dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id); } else { if ($action === 'TASK_CREATE') { if (!empty($conf->global->SCRUM_ADD_TASKS_TO_GRID)) { $object->array_options['options_grid_use'] = 1; $object->update($user, 1); } dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id); } } return 0; }
/** * Function called when a Dolibarrr business event is done. * All functions "run_trigger" are triggered if file * is inside directory core/triggers * * @param string $action Event action code * @param Object $object Object * @param User $user Object user * @param Translate $langs Object langs * @param conf $conf Object conf * @return int <0 if KO, 0 if no triggered ran, >0 if OK */ public function run_trigger($action, $object, $user, $langs, $conf) { // Put here code you want to execute when a Dolibarr business events occurs. // Data and type of action are stored into $object and $action // Users if ($action === 'PROJECT_CREATE') { if (empty($object->array_options['options_color'])) { dol_include_once('/scrumboard/lib/scrumboard.lib.php'); $object->array_options['options_color'] = '#' . scrumboard_random_color(); $object->update($user, 1); } dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id); } else { if ($action === 'TASK_CREATE') { if (!empty($conf->global->SCRUM_ADD_TASKS_TO_GRID)) { $object->array_options['options_grid_use'] = 1; $object->update($user, 1); $object->insertExtraFields(); } dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id); } else { if ($action === 'ACTION_CREATE' || $action == 'ACTION_MODIFY') { $fk_task = 0; $object->fetchObjectLinked(); if (!empty($object->linkedObjectsIds['task'])) { $row = each($object->linkedObjectsIds['task']); $fk_task = $row[1]; } $fk_project_task = GETPOST('fk_project_task'); if (!empty($fk_project_task)) { list($fk_project, $fk_task) = explode('_', $fk_project_task); if (!empty($fk_task)) { if (!empty($object->linkedObjectsIds['task'])) { $object->updateObjectLinked($fk_task, 'task'); } else { $object->add_object_linked('task', $fk_task); } } } /*var_dump($object); exit('!'); */ } } } return 0; }