modpluginevent.class.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /**
  11. * Represents a plugin registered for a specific event.
  12. *
  13. * @property int $pluginid The ID of the Plugin that this event is mapped to
  14. * @property string $event The name of this Plugin Event
  15. * @property int $priority The priority of this Event in the chain
  16. * @property int $propertyset The ID of the Property Set that may be attached to this Plugin Event
  17. * @see modPlugin
  18. * @package modx
  19. */
  20. class modPluginEvent extends xPDOObject {
  21. /**
  22. * Overrides xPDOObject::save to fire modX-specific events.
  23. *
  24. * {@inheritDoc}
  25. */
  26. public function save($cacheFlag = null) {
  27. $isNew = $this->isNew();
  28. if ($this->xpdo instanceof modX) {
  29. $this->xpdo->invokeEvent('OnPluginEventBeforeSave',array(
  30. 'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD,
  31. 'pluginEvent' => &$this,
  32. 'cacheFlag' => $cacheFlag,
  33. ));
  34. }
  35. $saved = parent :: save($cacheFlag);
  36. if ($saved && $this->xpdo instanceof modX) {
  37. $this->xpdo->invokeEvent('OnPluginEventSave',array(
  38. 'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD,
  39. 'pluginEvent' => &$this,
  40. 'cacheFlag' => $cacheFlag,
  41. ));
  42. }
  43. return $saved;
  44. }
  45. /**
  46. * Overrides xPDOObject::remove to fire modX-specific events.
  47. *
  48. * {@inheritDoc}
  49. */
  50. public function remove(array $ancestors = array()) {
  51. if ($this->xpdo instanceof modX) {
  52. $this->xpdo->invokeEvent('OnPluginEventBeforeRemove',array(
  53. 'pluginEvent' => &$this,
  54. 'ancestors' => $ancestors,
  55. ));
  56. }
  57. $removed = parent :: remove($ancestors);
  58. if ($removed && $this->xpdo instanceof modX) {
  59. $this->xpdo->invokeEvent('OnPluginEventRemove',array(
  60. 'pluginEvent' => &$this,
  61. 'ancestors' => $ancestors,
  62. ));
  63. }
  64. return $removed;
  65. }
  66. }