[TYPO3-german] Extbase Sortierung zieht nicht

Johannes C. Schulz info at enzephalon.de
Tue Jul 7 08:45:28 CEST 2015


Hallo

Ich habs selber herausgefunden.
Das injecten von Repositories im Model scheint nicht zu gehen. Ich habe nun
im Getter

/**
	 * Returns the persons
	 *
	 * @return
\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EnzephaloN\Accreditation\Domai
n\Model\Person> $persons
	 */
	public function getPersons() {
            		$objectManager =
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\O
bject\\ObjectManager');
            		$personRepository =
$objectManager->get('EnzephaloN\\Accreditation\\Domain\\Repository\\PersonRe
pository');
            		$persons =
$personRepository->findByAccreditation($this);
            		return $persons->toArray();
	}

Das funtkioniert - hoffentlich ohne hässliche Seiteneffekte.

Johannes

-----Ursprüngliche Nachricht-----
Von: typo3-german-bounces at lists.typo3.org
[mailto:typo3-german-bounces at lists.typo3.org] Im Auftrag von Johannes C.
Schulz
Gesendet: Dienstag, 7. Juli 2015 08:20
An: 'German TYPO3 Userlist'
Betreff: Re: [TYPO3-german] Extbase Sortierung zieht nicht

Hallo Till

Danke für Deine Antwort.
Leider steh ich noch n bissl aufm Schlauch - vielleicht hilfst Du mir
nochmal kurz.

Accreditation-Model:
/**
	 * personRepository
	 *
	 * @var \EnzephaloN\Accreditation\Domain\Repository\PersonRepository
	 * @inject
	 */
	protected $personRepository = NULL;
/**
	 * Returns the persons
	 *
	 * @return
\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EnzephaloN\Accreditation\Domai
n\Model\Person> $persons
	 */
	public function getPersons() {
            		$persons =
$this->personsRepository->findByAccreditation($this);
            		return $persons->toArray();
            	}

PersonsRepository:
/**
     *
     * define the default ordering of the persons
     */
    protected $defaultOrderings = array( 'accid' =>
\TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING );
    
    /**
         * 
         * @param
\EnzephaloN\Accreditation\Domain\Model\Accreditation$accreditation
         * @return array
         */
        public function
findByAccreditation(\EnzephaloN\Accreditation\Domain\Model\Accreditation
$accreditation){
            $query = $this->createQuery();  
            $query->setOrderings = $this->defaultOrderings;
            $query->matching($query->equals('accreditation',
$accreditation->getUid()));
            return $query->execute();
	}

Bekomme ne Fehlermeldung, daß ich im Model findByAccreditation auf ein
Non-Object anwende :-(

Was mache ich falsch?

Johannes



-----Ursprüngliche Nachricht-----
Von: typo3-german-bounces at lists.typo3.org
[mailto:typo3-german-bounces at lists.typo3.org] Im Auftrag von
g4-lisz at tonarchiv.ch
Gesendet: Montag, 6. Juli 2015 18:02
An: German TYPO3 Userlist
Betreff: Re: [TYPO3-german] Extbase Sortierung zieht nicht

Hi Johannes,

dafür gibt es leider bis heute keine einheitliche Lösung für die Sortierung
bei Object-Strrages.
Das Sortieren nach Uid geschieht auch eher zufällig, bzw. hängt von der
DB-Engine ab und in welcher Reihenfolge sie die Zeilen zurück liefert...

Entweder sortierst Du die Objekte mit einer entsprechenden PHP-Funktion oder
Du schreibst eine eigene eigene find-Methode im entsprechenden Repository,
die im Getter des referenzierenden Objekts aufgerufen wird.
Beides unschön, aber eine andere Lösung habe ich bisher nicht gefunden.
Bei letzterer Variante musst Du toArray() auf das Resultat der find-Methode
anwenden, da der Getter sonst einen falschen Typen zurück liefert.

Also so was:

public function getChildren() {

    $children = $this->childRepository->findByMother($this);
    return $children->toArray();
}

Grüße,
Till

On 07/06/2015 10:29 AM, Johannes C. Schulz wrote:
> Hallo TYPO3-Freunde
>
>  
>
> Ich habe eine Extension wo ich gerne Unterobjekte nicht nach „uid“ 
> sondern nach dem Integer-Feld „accid“ sortieren lassen würde – sowohl 
> im Frontend als auch im Backend.
>
> Doch der Eintrag:
>
>  
>
> /**
>
> * The repository for Types
>
> */
>
> class PersonRepository extends
> \TYPO3\CMS\Extbase\Persistence\Repository {
>
>     /**
>
>      *
>
>      * define the default ordering of the persons
>
>      */
>
>     protected $defaultOrderings = array( 'accid' => 
> \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING );
>
> }
>
>  
>
> im entsprechenden Kind-Objekt-Repository hat keine Wirkung. Das 
> Kind-Objekt ist ein ObjectStorage.
>
>  
>
> Wir kann ich in Front- und Backend die Sortierung definieren?
>
>  
>
> Typo3 6.2.12.
>
>  
>
> Johannes
>
> _______________________________________________
> TYPO3-german mailing list
> TYPO3-german at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-german

_______________________________________________
TYPO3-german mailing list
TYPO3-german at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-german


_______________________________________________
TYPO3-german mailing list
TYPO3-german at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-german




More information about the TYPO3-german mailing list