Bonjour,
en fait j'ai du mal à comprendre l'utilité de ça
Citation :if (!$obj->isDirty()) {
$obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith
return true;
}
cette condition vient du code suivant
Citation : /**
* insert a new object in the database
*
* @param object $obj reference to the object
* @param bool $force whether to force the query execution despite security settings
* @param bool $checkObject check if the object is dirty and clean the attributes
* @return bool FALSE if failed, TRUE if already present and unchanged or successful
*/
function insert(&$obj, $force = false, $checkObject = true)
{
if ($checkObject != false) {
if (!is_object($obj)) {
echo '<br><h1>Error, not object</h1>';
return false;
}
/**
* @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
*/
if (!is_a($obj, $this->className)) {
$obj->setErrors(get_class($obj).' Differs from '.$this->className);
return false;
}
if (!$obj->isDirty()) {
$obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith
return true;
}
}
if (!$obj->cleanVars()) {
foreach($obj->getErrors() as $oneerror) {
echo '<br /><h2>'.$oneerror.'</h2>';
}
return false;
}
foreach ($obj->cleanVars as $k => $v) {
if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
$cleanvars[$k] = intval($v);
} elseif ( is_array( $v ) ) {
$cleanvars[ $k ] = $this->db->quoteString( implode( ',', $v ) );
} else {
$cleanvars[$k] = $this->db->quoteString($v);
}
}
if(isset($cleanvars['dohtml'])) { // Modification Hervé to be able to use dohtml
unset($cleanvars['dohtml']);
}
if ($obj->isNew()) {
if (!is_array($this->keyName)) {
if ($cleanvars[$this->keyName] < 1) {
$cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq');
}
}
$sql = 'INSERT INTO '.$this->table.' ('.implode(',', array_keys($cleanvars)).') VALUES ('.implode(',', array_values($cleanvars)) .')';
} else {
$sql = 'UPDATE '.$this->table.' SET';
foreach ($cleanvars as $key => $value) {
if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
continue;
}
if (isset($notfirst) ) {
$sql .= ',';
}
$sql .= ' '.$key.' = '.$value;
$notfirst = true;
}
if (is_array($this->keyName)) {
$whereclause = '';
$vnb = count($this->keyName);
for ($i = 0; $i < $vnb; $i++) {
if ($i > 0) {
$whereclause .= ' AND ';
}
$whereclause .= $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
}
}
else {
$whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
}
$sql .= ' WHERE '.$whereclause;
}
if (false != $force) {
$result = $this->db->queryF($sql);
} else {
$result = $this->db->query($sql);
}
if (!$result) {
return false;
}
if ($obj->isNew() && !is_array($this->keyName)) {
$obj->assignVar($this->keyName, $this->db->getInsertId());
}
return true;
}
Merci
++