[TYPO3-mvc] How to sort objectstorage
Thomas Mammitzsch
thomas at visualworx.de
Thu Mar 28 14:34:40 CET 2013
hi,
i'm not sure if i get it right.
Wouldn't it be?
Notepad <-> Company m:n
Company <-> Tag m:n
Then you iterate over each company of the Notepad and store the tag f.e.
in an array at runtime if it not already exists in that array. After
that you can sort that array and return it. like that:
class Notepad {
.......
public function getTags() {
$tags = array();
foreach($this->getCompanies() as $company) {
foreach($company->getTags() as $tag) {
if(!in_array($tag, $tags) {
array_push($tags, $tag)
}
}
}
//do some sorting
return $tags;
}
regards, Thomas
On 28.03.2013 12:27, Stefan Kruse wrote:
> Hi Thomas,
>
> i think so easy ist in my case not. I try to explain. I have an notepad
> extension. There I can save companies on a notepad. For every company on a
> notepad I can save tags. Maybe my database relation is not correct, I have a
> m:n relation (notepad:tag). Now I need all Tags where all companies are used
> with, to make a navigation with all tags. For this case, atm, I retrieve all
> companies on the notepad from repository, and get the tags. Then I store
> them in the objectStorage. The problem here is, that the sorting of the
> objectStorage is like:
>
> company1 => Tag1
> company1 => Tag2
> company2 => Tag1
> company2 => Tag2
> company2 => Tag3
>
> But I need it sorted by name like Tag1, Tag2, Tag3 etc.
>
> Maybe you or someone knows a better way how to make a tag system. Like I say
> maybe I can make my database relation better?
>
> Thanks Stefan
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
More information about the TYPO3-project-typo3v4mvc
mailing list