ATK /utils/class.atktriggerlistener.inc

Language PHP Lines 92
MD5 Hash dd2e9fc8b374ba89c9e7beaa0b14e2f2
Repository https://github.com/ibuildingsnl/ATK.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
  /**
   * This file is part of the Achievo ATK distribution.
   * Detailed copyright and licensing information can be found
   * in the doc/COPYRIGHT and doc/LICENSE files which should be
   * included in the distribution.
   *
   * @package atk
   * @subpackage utils
   *
   * @copyright (c)2005 Ibuildings.nl BV
   * @license http://www.achievo.org/atk/licensing ATK Open Source License
   *
   * @version $Revision: 4362 $
   * $Id$
   */

  /**
   * The atkTriggerListener base class for handling trigger events on records.
   *
   * The most useful purpose of the atkTriggerListener is to serve as a base
   * class for custom trigger listeners. Extend this class and implement
   * postUpdate, preDelete etc. functions that will automatically be called
   * when such a trigger occurs. For more flexibility, override only
   * the notify($trigger, $record) method which catches every trigger. 
   * Using atkNode::addListener you can add listeners that catch evens such as 
   * records updates and additions.
   * This is much like the classic atk postUpdate/postAdd triggers, only much
   * more flexible.
   *
   * @author Martin Roest <martin@ibuildings.nl>
   * @author Peter C. Verhage <peter@achievo.org>
   * @package atk
   * @subpackage utils
   */
  class atkTriggerListener
  {
    /**
     * The owning node of the listener.
     * @access private
     * @var atkNode
     */
    var $m_node = NULL;

    /**
     * Base constructor.
     * 
     * @return atkTriggerListener
     */
    function atkTriggerListener()
    {
    }

    /**
     * Set the owning node of the listener.
     *
     * When using atkNode::addListener to add a listener to a node it is not
     * necessary to call this method as addListener will do that for you.
     *
     * @param atkNode $node The node to set as owner
     */
    function setNode(&$node)
    {
      $this->m_node = &$node;
    }

    /**
     * Notify the listener of any action on a record.
     *
     * This method is called by the framework for each action called on a
     * node. Depending on the actionfilter passed in the constructor, the
     * call is forwarded to the actionPerformed($action, $record) method.
     *
     * @param String $trigger The trigger being performed
     * @param array $record The record on which the trigger is performed
     * @param string $mode The mode (add/update)
     * @return boolean Result of operation.
     */
    function notify($trigger, &$record, $mode=NULL)
    {
      if (method_exists($this, $trigger))
      {
        atkdebug("Call listener ".get_class($this)." for trigger $trigger on ".$this->m_node->atkNodeType()." (".$this->m_node->primaryKey($record).")");        
        return $this->$trigger($record, $mode);
      }
      else 
      {
        return true;
      }
    }
  }
?>
Back to Top