[TYPO3-mvc] How to cope with anonymous FE user entries

Bastian Waidelich bastian at typo3.org
Mon Mar 12 12:03:44 CET 2012


Thomas Hucke wrote:

Hi Thomas,

> I write an extension (th_rating) to do ratings of any object.
> [...]
> No I reached a request to allow anonymous ratings (
> http://forge.typo3.org/issues/34436 ).
> How can I model that?

> Obviously extbase needs a valid FE user to handle a create-action.

No, only if you expect a Tx_Extbase_Domain_Model_FrontendUser the 
specified uid needs to belong to a valid FE user record.

What about s.th. like:

class Tx_YourExt_Domain_Model_Voter extends 
Tx_Extbase_DomainObject_AbstractEntity {

	/**
	 * The voter of this object
	 *
	 * @var Tx_Extbase_Domain_Model_FrontendUser
	 * @lazy
	 */
	protected $frontendUser;

	public function isAnonymous() {
		return $this->frontendUser === NULL;
	}

	public function getFrontendUser() {
		// ...
	}

	public function setFrontendUser(Tx_Extbase_Domain_Model_FrontendUser 
$frontendUser) {
		// ...
	}
}


And then

// ...

/**
  * The voter of this object
  *
  * @var Tx_YourExt_Domain_Model_Voter
  * @lazy
  */
protected $voter;

/**
  * Sets the voter of this vote
  *
  * @param Tx_YourExt_Domain_Model_Voter $voter
  * @return void
  */
public function setVoter(Tx_YourExt_Domain_Model_Voter $voter) {
	$this->voter = $voter;
}

/**
  * Returns the voter of this vote
  *
  * @return Tx_YourExt_Domain_Model_Voter
  */
public function getVoter() {
	return $this->voter;
}

// ...

in your vote Domain Model?

Bastian


More information about the TYPO3-project-typo3v4mvc mailing list