modevent.class.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. include_once (strtr(realpath(dirname(__FILE__)), '\\', '/') . '/../modevent.class.php');
  11. /**
  12. * @package modx
  13. * @subpackage mysql
  14. */
  15. class modEvent_mysql extends modEvent {
  16. public static function listEvents(xPDO &$xpdo, $plugin, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) {
  17. $c = $xpdo->newQuery('modEvent');
  18. $count = $xpdo->getCount('modEvent',$c);
  19. $c->select($xpdo->getSelectColumns('modEvent','modEvent'));
  20. $c->select(array(
  21. 'IF(ISNULL(modPluginEvent.pluginid),0,1) AS enabled',
  22. 'modPluginEvent.priority AS priority',
  23. 'modPluginEvent.propertyset AS propertyset',
  24. ));
  25. $c->leftJoin('modPluginEvent','modPluginEvent','
  26. modPluginEvent.event = modEvent.name
  27. AND modPluginEvent.pluginid = '.$plugin.'
  28. ');
  29. $c->where($criteria);
  30. foreach($sort as $field=> $dir) {
  31. $c->sortby($xpdo->getSelectColumns('modEvent','modEvent','',array($field)),$dir);
  32. }
  33. if ((int) $limit > 0) {
  34. $c->limit((int) $limit, (int) $offset);
  35. }
  36. return array(
  37. 'count'=> $count,
  38. 'collection'=> $xpdo->getCollection('modEvent',$c)
  39. );
  40. }
  41. }