/** * Removes the given user from the channel, if he is a reader. * If he is the last reader, the channel will be completely deleted. * * @param GenericORMapperDataObject $User The user which should be removed from the list of readers. * * @return AbstractMessageChannel Returns itself (fluent-interface) * @throws \BadFunctionCallException */ public function removeReader(GenericORMapperDataObject &$User) { if ($this->getDataComponent() === null) { throw new \BadFunctionCallException('[MessageChannel::removeReader()] DataComponent is not set, if the object was not loaded by ORM, you need to set it manually!'); } if ($this->getDataComponent()->isAssociated('User2MessageChannel', $User, $this)) { // If this user is the last reader, we delete the channel completely if (count($this->getReaders()) === 1) { $this->delete(); } else { // remove unread-relations $this->setReadForUser($User); // check if channel is in a folder from the given user and remove it from there if necessary $crit = new GenericCriterionObject(); $crit->addRelationIndicator('User2PostboxFolder', $User); /* @var $folder AbstractPostboxFolder */ $folder = $this->loadRelatedObject('PostboxFolder2MessageChannel', $crit); if ($folder !== null) { $folder->removeChannel($this); } // finally remove the relation between user and channel $this->getDataComponent()->deleteAssociation('User2MessageChannel', $User, $this); } } return $this; }
/** * Try to load an existing attribute. If possible, merge the attributes to not * generate new objects in database. Otherwise return a new generic domain object. * * @param Entry $domEntry The entry domain object. * @param string $name The name of the generic attribute to return. * * @return GenericDomainObject The attribute's data layer representation. * * @author Christian Achatz * @version * Version 0.1, 06.05.2009<br /> */ private function getGenericAttribute(Entry $domEntry, $name) { // try to load $entry = new GenericDomainObject('Entry'); $entry->setProperty('EntryID', $domEntry->getId()); $crit = new GenericCriterionObject(); $crit->addPropertyIndicator('Name', $name); $crit->addRelationIndicator('Attribute2Language', $this->getCurrentLanguage()); $attributes = $this->orm->loadRelatedObjects($entry, 'Entry2LangDepValues', $crit); if (isset($attributes[0])) { return $attributes[0]; } return new GenericDomainObject('Attribute'); }
/** * Resolves the appropriate user from the given auth token. * * @param UmgtAuthToken $token The current auth token. * * @return UmgtUser|null The corresponding user or null if the user cannot be found. */ public function loadUserByAuthToken(UmgtAuthToken $token) { $crit = new GenericCriterionObject(); $crit->addRelationIndicator('User2AuthToken', $token); $crit->addRelationIndicator('Application2User', $this->getCurrentApplication()); return $this->getORMapper()->loadObjectByCriterion('User', $crit); }