7
This is not a solution but a temporary patch.Define your objects a subclass of ModuleXoopsObject class... this way it is possible to set a column value to NULL...
abstract class ModuleXoopsObject extends XoopsObject {
/**
* @var moduleHelper
* @access private
*/
private $moduleHelper = null;
/**
* constructor
*/
public function __construct()
{
$this->moduleHelper = XmfModuleHelper::getHelper('module');
$this->db = XoopsDatabaseFactory::getDatabaseConnection();
//
parent::__construct();
}
/**
* assign a value to a variable (also null is allowed)
*
* @access public
* @param string $key name of the variable to assign
* @param mixed $value value to assign
* @param bool $not_gpc
*/
public function setVar($key, $value, $not_gpc = false)
{
if (!empty($key) && isset($value) && isset($this->vars[$key])) {
$this->vars[$key]['value'] =& $value;
$this->vars[$key]['not_gpc'] = $not_gpc;
$this->vars[$key]['changed'] = true;
$this->setDirty();
}
if (!empty($key) && is_null($value) && isset($this->vars[$key])) {
$this->vars[$key]['value'] = null;
$this->vars[$key]['not_gpc'] = $not_gpc;
$this->vars[$key]['changed'] = false;
$this->setDirty();
}
}
}
abstract class ModuleXoopsObjectHandler extends XoopsPersistableObjectHandler
{
/**
* @var moduleHelper
* @access private
*/
private $moduleHelper = null;
/**
* @param null|object $db
*/
public function __construct($db = null, $table = '', $className = '', $keyName = '', $identifierName = '')
{
parent::__construct($db, $table, $className, $keyName, $identifierName);
$this->moduleHelper = XmfModuleHelper::getHelper('module');
}
/**
* insert an object into the database
*
* @param XoopsObject $object {@link XoopsObject} reference to object
* @param bool $force flag to force the query execution despite security settings
* @return mixed object ID
*/
public function insert(XoopsObject $object, $force = true)
{
$ret = parent::insert($object, $force);
// handle null values
$queryFunc = empty($force) ? 'query' : 'queryF';
$vars = $object->getVars();
foreach ($vars as $key => $value) {
if (is_null($value['value'])) {
$sql = "UPDATE `{$this->table}` SET `{$key}` = NULL WHERE `{$this->keyName}` = {$this->db->quote($object->getVar($this->keyName))}";
if (!$result = $this->db->{$queryFunc}($sql)) {
//return false;
}
}
}
return $ret;
}
}