Chris@0: setValues((array) $values); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getId() { Chris@0: return isset($this->lid) ? $this->lid : NULL; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setId($lid) { Chris@0: $this->lid = $lid; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getVersion() { Chris@0: return isset($this->version) ? $this->version : NULL; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setVersion($version) { Chris@0: $this->version = $version; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getPlurals() { Chris@18: return explode(PoItem::DELIMITER, $this->getString()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setPlurals($plurals) { Chris@18: $this->setString(implode(PoItem::DELIMITER, $plurals)); Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getStorage() { Chris@0: return isset($this->storage) ? $this->storage : NULL; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setStorage($storage) { Chris@0: $this->storage = $storage; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setValues(array $values, $override = TRUE) { Chris@0: foreach ($values as $key => $value) { Chris@0: if (property_exists($this, $key) && ($override || !isset($this->$key))) { Chris@0: $this->$key = $value; Chris@0: } Chris@0: } Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getValues(array $fields) { Chris@0: $values = []; Chris@0: foreach ($fields as $field) { Chris@0: if (isset($this->$field)) { Chris@0: $values[$field] = $this->$field; Chris@0: } Chris@0: } Chris@0: return $values; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getLocations($check_only = FALSE) { Chris@0: if (!isset($this->locations) && !$check_only) { Chris@0: $this->locations = []; Chris@0: foreach ($this->getStorage()->getLocations(['sid' => $this->getId()]) as $location) { Chris@0: $this->locations[$location->type][$location->name] = $location->lid; Chris@0: } Chris@0: } Chris@0: return isset($this->locations) ? $this->locations : []; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function addLocation($type, $name) { Chris@0: $this->locations[$type][$name] = TRUE; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function hasLocation($type, $name) { Chris@0: $locations = $this->getLocations(); Chris@0: return isset($locations[$type]) ? !empty($locations[$type][$name]) : FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function save() { Chris@0: if ($storage = $this->getStorage()) { Chris@0: $storage->save($this); Chris@0: } Chris@0: else { Chris@0: throw new StringStorageException('The string cannot be saved because its not bound to a storage: ' . $this->getString()); Chris@0: } Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function delete() { Chris@0: if (!$this->isNew()) { Chris@0: if ($storage = $this->getStorage()) { Chris@0: $storage->delete($this); Chris@0: } Chris@0: else { Chris@0: throw new StringStorageException('The string cannot be deleted because its not bound to a storage: ' . $this->getString()); Chris@0: } Chris@0: } Chris@0: return $this; Chris@0: } Chris@0: Chris@0: }