Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###! MODEL !###
- <?php
- namespace RSM\RsmContent\Domain\Model;
- /***************************************************************
- * Copyright notice
- *
- * (c) 2013 Benjamin Serfhos <serfhos@rsm.nl>, Erasmus University
- *
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
- /**
- * Model: Default Page
- *
- * @package RSM\RsmContent\Domain\Model
- */
- class Page extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
- /**
- * Title
- *
- * @var string
- */
- protected $title;
- /**
- * Doktypes
- *
- * @var integer
- */
- protected $doktype;
- /**
- * @var integer
- */
- protected $sorting;
- /**
- * Parent
- *
- * @var \RSM\RsmContent\Domain\Model\Page
- * @lazy
- */
- protected $parent;
- /**
- * Children
- *
- * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\RSM\RsmContent\Domain\Model\Page>
- * @lazy
- */
- protected $children;
- /**
- * Meta: Description
- *
- * @var string
- */
- protected $description = '';
- /**
- * Meta: Keywords
- *
- * @var string
- */
- protected $keywords = '';
- /**
- * Initialize object
- *
- * @return void
- */
- public function initializeObject() {
- $this->children = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
- }
- /**
- * Returns the Title
- *
- * @return string
- */
- public function getTitle() {
- return $this->title;
- }
- /**
- * Returns the Children
- *
- * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
- */
- public function getChildren() {
- if ($this->children instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
- $this->children->_loadRealInstance();
- }
- return $this->children;
- }
- /**
- * Returns the Description
- *
- * @return string
- */
- public function getDescription() {
- return $this->description;
- }
- /**
- * Returns the Doktype
- *
- * @return int
- */
- public function getDoktype() {
- return $this->doktype;
- }
- /**
- * Returns the Sorting
- *
- * @return int
- */
- public function getSorting() {
- return $this->sorting;
- }
- /**
- * Returns the Keywords
- *
- * @return string
- */
- public function getKeywords() {
- return $this->keywords;
- }
- /**
- * Returns the Parent
- *
- * @return \RSM\RsmContent\Domain\Model\Page
- */
- public function getParent() {
- if ($this->parent instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
- $this->parent->_loadRealInstance();
- }
- return $this->parent;
- }
- }
- ?>
- ###! REPOSITORY !###
- <?php
- namespace RSM\RsmContent\Domain\Repository;
- /***************************************************************
- * Copyright notice
- *
- * (c) 2013 Benjamin Serfhos <serfhos@rsm.nl>, Erasmus University
- *
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
- /**
- * Repository: Pages
- *
- * @package RSM\RsmContent\Domain\Repository
- */
- class PageRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
- /**
- * Find pages by given ordering in list
- *
- * @param array $items
- * @return array
- */
- public function findByList(array $items) {
- $orderedPages = array();
- if (!empty($items)) {
- $query = $this->createQuery();
- $query->getQuerySettings()->setRespectStoragePage(FALSE);
- $query->getQuerySettings()->setRespectSysLanguage(FALSE);
- $query->matching(
- $query->in('uid', $items)
- );
- $results = $query->execute();
- if ($results) {
- foreach ($results as $page) {
- $key = array_search($page->getUid(), $items, TRUE);
- $orderedPages[$key] = $page;
- }
- }
- ksort($orderedPages);
- }
- return $orderedPages;
- }
- }
- ?>
- ###! ext_typoscript_setup.txt !###
- config.tx_extbase {
- persistence {
- classes {
- RSM\RsmContent\Domain\Model\Page {
- mapping {
- tableName = pages
- columns {
- pid.mapOnProperty = parent
- # load children from uid
- uid {
- mapOnProperty = children
- config {
- type = select
- foreign_table = pages
- foreign_field = pid
- foreign_sortby = sorting
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement