/** * Do some conversions for some types */ public function __set($key, $val) { // If it is a Mongo entity, convert it to its reference if ($val instanceof ZFE_Model_Mongo) { $val = $val->getReference(); } // If it is a DateTime, convert it to MongoDate if ($val instanceof DateTime) { $val = new MongoDate($val->getTimestamp()); } // If it is an array of Mongo entities or DateTimes if (is_array($val)) { $_val = array(); foreach ($val as $i => $v) { if ($v instanceof ZFE_Model_Mongo) { $v = $v->getReference(); } if ($v instanceof DateTime) { $v = new MongoDate($v->getTimestamp()); } $_val[$i] = $v; } $val = $_val; } parent::__set($key, $val); }
/** * Do some conversions for some types */ public function __set($key, $val) { // If it is a Mongo entity, convert it to its reference if ($val instanceof ZFE_Model_Mongo) { $val = $val->getReference(); } // If it is a DateTime, convert it to MongoDate if ($val instanceof DateTime) { $val = new MongoDate($val->getTimestamp()); } // If it is an array of Mongo entities or DateTimes if (is_array($val)) { $_val = array(); foreach ($val as $i => $v) { if ($v instanceof ZFE_Model_Mongo) { $v = $v->getReference(); } if ($v instanceof DateTime) { $v = new MongoDate($v->getTimestamp()); } $_val[$i] = $v; } $val = $_val; } $doCompare = !in_array($this->_status, array(self::STATUS_INITIALIZING, self::STATUS_IMPORT)); // Do not use $this->$key here because $val is already translated so we don't need // back-translate from $this::__get if ($doCompare) { $oldValue = parent::__get($key); } parent::__set($key, $val); if ($doCompare && $oldValue !== $val) { if (!isset($this->_changedFields[$key])) { $this->_changedFields[$key] = array(); } $this->_changedFields[$key][] = $oldValue; } }