Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to apply default sorting for child objects of the type Tx_Extbase_Persistence_ObjectStorage
/**
*
*
* @package nboevents
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class Tx_Nboevents_Domain_Repository_EventRepository extends Tx_Extbase_Persistence_Repository {
/**
* defaultOrderings
*
* @var array
*/
protected $defaultOrderings = array(
'date' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING,
);
/**
* findByCourse
*
* @param $uid
* @return
*/
public function findByCourse($course = 0, $limit = 99) {
$now = time();
$query = $this->createQuery();
$query->matching(
$query->logicalAnd(
$query->equals('course', $course),
$query->greaterThanOrEqual('date', $now)
)
);
$query->setLimit((integer)$limit);
$posts = $query->execute();
return $posts;
}
}
/**
* Returns the events
*
* @return Tx_Extbase_Persistence_ObjectStorage<Tx_Nboevents_Domain_Model_Event> $events
*/
public function getEvents() {
$eventRepository = t3lib_div::makeInstance('Tx_Nboevents_Domain_Repository_EventRepository');
return $eventRepository->findByCourse($this->getUid());
}
/**
* Returns the next event
*
* @return Tx_Extbase_Persistence_ObjectStorage<Tx_Nboevents_Domain_Model_Event> $events
*/
public function getNextevent() {
$eventRepository = t3lib_div::makeInstance('Tx_Nboevents_Domain_Repository_EventRepository');
return $eventRepository->findByCourse($this->getUid(), 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment