Esempio n. 1
0
 /**
  * Saves the data member into the Mongo collection
  */
 public function save()
 {
     if (!$this->_isPersistable) {
         throw new ZFE_Model_Mongo_Exception("Can not save a non-persistable instance");
     }
     $collection = static::getCollection();
     $data = $this->_data;
     if (isset($this->_id)) {
         $data = array_merge(array('_id' => $this->_id), $data);
     }
     // Remove from model if value is null
     foreach ($data as $key => $val) {
         if (is_null($val)) {
             unset($data[$key]);
         }
     }
     $collection->save($data);
     $this->_id = $data['_id'];
     unset($data['_id']);
     $this->_data = $data;
     // Remove from cache after saving
     $class = get_called_class();
     unset(self::$_cache[$class][(string) $this->getIdentifier()]);
     $objectId = (string) $this->_id;
     if (isset(static::$_refCache[$objectId])) {
         unset(static::$_refCache[$objectId]);
     }
     // Run on*Updated functions on changed fields and clear it
     foreach ($this->_changedFields as $fld => $oldValues) {
         $fn = ZFE_Util_String::toCamelCase("on-" . $fld . "-updated");
         if (method_exists($this, $fn)) {
             $this->{$fn}($oldValues);
         }
     }
     $this->_changedFields = array();
 }
Esempio n. 2
0
 /**
  * The magic getter. It checks for the specific getter function,
  * and whether the given key is a translated entry.
  */
 public function __get($key)
 {
     // Check if a user-defined getter method exists,
     // and use that immediately
     $getter = "_" . ZFE_Util_String::toCamelCase("get_" . strtolower($key));
     if (method_exists($this, $getter)) {
         return $this->{$getter}();
     }
     // Check the simple cases, and return these immediately
     if (!isset($this->_data[$key])) {
         return null;
     }
     if (!in_array($key, static::$translations)) {
         return $this->_data[$key];
     }
     // The key is a translatable data entry, so we try figuring out
     // the language to use
     $lang = $this->_lang;
     if (!isset($this->_data[$key][$lang])) {
         $languages = array_keys($this->_data[$key]);
         $lang = $languages[0];
     }
     return $this->_data[$key][$lang];
 }