Doctrine : how to manipulate a collection?

I'd rather pass Doctrine_Query between methods: action public function executeShow(sfWebRequest $request) { $this->user = $this->getRoute()->getObject(); $this->websites = $this->getUser()->getWebsites(true); } //user public function getWebsites($top_ranked = false) { $q = Doctrine_Query::create() ->from('Website w') ->where('w. User_id =? ', $this->getId()); if ($top_ranked) { $q = Doctrine::getTable('Website')->addTopRankedQuery($q); } return $q->execute(); } //WebsiteTable public function addTopRankedQuery(Doctrine_Query $q) { $alias = $q->getRootAlias(); $q->orderBy($alias'.

Nb_votes DESC') ->limit(5) return $q }.

I'd rather pass Doctrine_Query between methods: //action public function executeShow(sfWebRequest $request) { $this->user = $this->getRoute()->getObject(); $this->websites = $this->getUser()->getWebsites(true); } //user public function getWebsites($top_ranked = false) { $q = Doctrine_Query::create() ->from('Website w') ->where('w. User_id =? ', $this->getId()); if ($top_ranked) { $q = Doctrine::getTable('Website')->addTopRankedQuery($q); } return $q->execute(); } //WebsiteTable public function addTopRankedQuery(Doctrine_Query $q) { $alias = $q->getRootAlias(); $q->orderBy($alias'.

Nb_votes DESC') ->limit(5) return $q }.

Thanks. I thought it was possible to alter a doctrine collection. – Tristan Jan 10 at 9:19.

If getTopRanked() is a method in your user model, then you would access it with $this->user->getTopRanked().

In your case $this->user->Websites contains ALL user websites. As far as I know there's no way to filter existing doctrine collection (unless you will iterate through it and choose interesting elements). I'd simply implement getTopRankedWebsites() method in the User class: class User extends BaseUser { public function getTopRankedWebsites() { WebsiteTable::getTopRankedByUserId($this->getId()); } } And add appropriate query in the WebsiteTable: class WebsiteTable extends Doctrine_Table { public function getTopRankedByUserId($userId) { return Doctrine_Query::create() ->from('Website w') ->where('w.

User_id =? ', array($userId)) ->orderBy('w. Nb_votes DESC') ->limit(5) ->execute(); } }.

You can also use the getFirst() function $this->user->Websites->getTopRanked()->getFirst() doctrine-project.org/api/orm/1.2/doctrin...).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions