Advertisement
BenjaminS

TYPO3: Page Model & Repository

Sep 24th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.43 KB | None | 0 0
  1. ###! MODEL !###
  2. <?php
  3. namespace RSM\RsmContent\Domain\Model;
  4.  
  5. /***************************************************************
  6.  *  Copyright notice
  7.  *
  8.  *  (c) 2013 Benjamin Serfhos <serfhos@rsm.nl>, Erasmus University
  9.  *
  10.  *  All rights reserved
  11.  *
  12.  *  This script is part of the TYPO3 project. The TYPO3 project is
  13.  *  free software; you can redistribute it and/or modify
  14.  *  it under the terms of the GNU General Public License as published by
  15.  *  the Free Software Foundation; either version 3 of the License, or
  16.  *  (at your option) any later version.
  17.  *
  18.  *  The GNU General Public License can be found at
  19.  *  http://www.gnu.org/copyleft/gpl.html.
  20.  *
  21.  *  This script is distributed in the hope that it will be useful,
  22.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  23.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24.  *  GNU General Public License for more details.
  25.  *
  26.  *  This copyright notice MUST APPEAR in all copies of the script!
  27.  ***************************************************************/
  28.  
  29. /**
  30.  * Model: Default Page
  31.  *
  32.  * @package RSM\RsmContent\Domain\Model
  33.  */
  34. class Page extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
  35.  
  36.     /**
  37.      * Title
  38.      *
  39.      * @var string
  40.      */
  41.     protected $title;
  42.  
  43.     /**
  44.      * Doktypes
  45.      *
  46.      * @var integer
  47.      */
  48.     protected $doktype;
  49.  
  50.     /**
  51.      * @var integer
  52.      */
  53.     protected $sorting;
  54.  
  55.     /**
  56.      * Parent
  57.      *
  58.      * @var \RSM\RsmContent\Domain\Model\Page
  59.      * @lazy
  60.      */
  61.     protected $parent;
  62.  
  63.     /**
  64.      * Children
  65.      *
  66.      * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\RSM\RsmContent\Domain\Model\Page>
  67.      * @lazy
  68.      */
  69.     protected $children;
  70.  
  71.     /**
  72.      * Meta: Description
  73.      *
  74.      * @var string
  75.      */
  76.     protected $description = '';
  77.  
  78.     /**
  79.      * Meta: Keywords
  80.      *
  81.      * @var string
  82.      */
  83.     protected $keywords = '';
  84.  
  85.     /**
  86.      * Initialize object
  87.      *
  88.      * @return void
  89.      */
  90.     public function initializeObject() {
  91.         $this->children = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
  92.     }
  93.  
  94.     /**
  95.      * Returns the Title
  96.      *
  97.      * @return string
  98.      */
  99.     public function getTitle() {
  100.         return $this->title;
  101.     }
  102.  
  103.     /**
  104.      * Returns the Children
  105.      *
  106.      * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
  107.      */
  108.     public function getChildren() {
  109.         if ($this->children instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
  110.             $this->children->_loadRealInstance();
  111.         }
  112.         return $this->children;
  113.     }
  114.  
  115.     /**
  116.      * Returns the Description
  117.      *
  118.      * @return string
  119.      */
  120.     public function getDescription() {
  121.         return $this->description;
  122.     }
  123.  
  124.     /**
  125.      * Returns the Doktype
  126.      *
  127.      * @return int
  128.      */
  129.     public function getDoktype() {
  130.         return $this->doktype;
  131.     }
  132.  
  133.     /**
  134.      * Returns the Sorting
  135.      *
  136.      * @return int
  137.      */
  138.     public function getSorting() {
  139.         return $this->sorting;
  140.     }
  141.  
  142.     /**
  143.      * Returns the Keywords
  144.      *
  145.      * @return string
  146.      */
  147.     public function getKeywords() {
  148.         return $this->keywords;
  149.     }
  150.  
  151.     /**
  152.      * Returns the Parent
  153.      *
  154.      * @return \RSM\RsmContent\Domain\Model\Page
  155.      */
  156.     public function getParent() {
  157.         if ($this->parent instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
  158.             $this->parent->_loadRealInstance();
  159.         }
  160.         return $this->parent;
  161.     }
  162.  
  163. }
  164. ?>
  165.  
  166.  
  167. ###! REPOSITORY !###
  168. <?php
  169. namespace RSM\RsmContent\Domain\Repository;
  170.  
  171. /***************************************************************
  172.  *  Copyright notice
  173.  *
  174.  *  (c) 2013 Benjamin Serfhos <serfhos@rsm.nl>, Erasmus University
  175.  *
  176.  *  All rights reserved
  177.  *
  178.  *  This script is part of the TYPO3 project. The TYPO3 project is
  179.  *  free software; you can redistribute it and/or modify
  180.  *  it under the terms of the GNU General Public License as published by
  181.  *  the Free Software Foundation; either version 3 of the License, or
  182.  *  (at your option) any later version.
  183.  *
  184.  *  The GNU General Public License can be found at
  185.  *  http://www.gnu.org/copyleft/gpl.html.
  186.  *
  187.  *  This script is distributed in the hope that it will be useful,
  188.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  189.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  190.  *  GNU General Public License for more details.
  191.  *
  192.  *  This copyright notice MUST APPEAR in all copies of the script!
  193.  ***************************************************************/
  194.  
  195. /**
  196.  * Repository: Pages
  197.  *
  198.  * @package RSM\RsmContent\Domain\Repository
  199.  */
  200. class PageRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
  201.  
  202.     /**
  203.      * Find pages by given ordering in list
  204.      *
  205.      * @param array $items
  206.      * @return array
  207.      */
  208.     public function findByList(array $items) {
  209.         $orderedPages = array();
  210.         if (!empty($items)) {
  211.             $query = $this->createQuery();
  212.             $query->getQuerySettings()->setRespectStoragePage(FALSE);
  213.             $query->getQuerySettings()->setRespectSysLanguage(FALSE);
  214.  
  215.             $query->matching(
  216.                 $query->in('uid', $items)
  217.             );
  218.             $results = $query->execute();
  219.             if ($results) {
  220.                 foreach ($results as $page) {
  221.                     $key = array_search($page->getUid(), $items, TRUE);
  222.                     $orderedPages[$key] = $page;
  223.                 }
  224.             }
  225.             ksort($orderedPages);
  226.         }
  227.         return $orderedPages;
  228.     }
  229.  
  230. }
  231.  
  232. ?>
  233.  
  234. ###! ext_typoscript_setup.txt !###
  235. config.tx_extbase {
  236.     persistence {
  237.         classes {
  238.             RSM\RsmContent\Domain\Model\Page {
  239.                 mapping {
  240.                     tableName = pages
  241.                     columns {
  242.                         pid.mapOnProperty = parent
  243.  
  244.                         # load children from uid
  245.                         uid {
  246.                             mapOnProperty = children
  247.                             config {
  248.                                 type = select
  249.                                 foreign_table = pages
  250.                                 foreign_field = pid
  251.                                 foreign_sortby = sorting
  252.                             }
  253.                         }
  254.                     }
  255.                 }
  256.             }
  257.         }
  258.     }
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement