/** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone * * @return int New id of clone */ public function createFromClone($fromid) { dol_syslog(__METHOD__, LOG_DEBUG); global $user; $error = 0; $object = new Skeleton_Class($this->db); $this->db->begin(); // Load source object $object->fetch($fromid); // Reset object $object->id = 0; // Clear fields // ... // Create clone $result = $object->create($user); // Other options if ($result < 0) { $error++; $this->errors = $object->errors; dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } // End if (!$error) { $this->db->commit(); return $object->id; } else { $this->db->rollback(); return -1; } }
$action = GETPOST('action', 'alpha'); $backtopage = GETPOST('backtopage'); $myparam = GETPOST('myparam', 'alpha'); $search_field1 = GETPOST("search_field1"); $search_field2 = GETPOST("search_field2"); // Protection if external user if ($user->societe_id > 0) { //accessforbidden(); } if (empty($action) && empty($id) && empty($ref)) { $action = 'list'; } // Load object if id or ref is provided as parameter $object = new Skeleton_Class($db); if (($id > 0 || !empty($ref)) && $action != 'add') { $result = $object->fetch($id, $ref); if ($result < 0) { dol_print_error($db); } } // Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('skeleton')); $extrafields = new ExtraFields($db); /******************************************************************* * ACTIONS * * Put here all code to do according to value of "action" parameter ********************************************************************/ $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
/** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone * @return int New id of clone */ function createFromClone($fromid) { global $user, $langs; $error = 0; $object = new Skeleton_Class($this->db); $this->db->begin(); // Load source object $object->fetch($fromid); $object->id = 0; $object->statut = 0; // Clear fields // ... // Create clone $result = $object->create($user); // Other options if ($result < 0) { $this->error = $object->error; $error++; } if (!$error) { } // End if (!$error) { $this->db->commit(); return $object->id; } else { $this->db->rollback(); return -1; } }