/** * Set or update a preference * * @param string $name The preference name * @param string $value The value to assign to the preference * @param int|string|object $expires default null The expiry as a UNIX timestamp, \DateTime string or \DateTime object. null means never. * @param int $index default null If an indexed preference, set a specific index number. * @return \Oss2\Doctrine2\WithPreferences An instance of this object for fluid interfaces. */ public function setPreference($name, $value, $expires = null, $index = null) { $pref = $this->loadPreference($name, $index); if (is_int($expires)) { $expires = new \DateTime(date('Y-m-d H:i:s', $expires)); } elseif (is_string($expires)) { $expires = new \DateTime($expires); } if ($pref) { $pref->setValue($value); $pref->setExpiresAt($expires); $pref->setIx($index); return $this; } $pref = $this->_createPreferenceEntity($this); $pref->setName($name); $pref->setValue($value); $pref->setCreatedAt(new \DateTime()); $pref->setExpiresAt($expires); $pref->setIx($index); \D2EM::persist($pref); return $this; }