]> git.andy128k.dev Git - ipf.git/commitdiff
admin model listeners
authorAndrey Kutejko <andy128k@gmail.com>
Sun, 29 Dec 2013 15:53:24 +0000 (17:53 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Sun, 29 Dec 2013 15:53:24 +0000 (17:53 +0200)
ipf/admin/model.php

index 7b76a94cce01f79f4cda04d93c4d81497c460ac9..a0c069b4a1c1407d7b0a04787f171f1b13913176 100644 (file)
@@ -343,6 +343,37 @@ class DateHierarchyListFilter extends BaseListFilter {
     }
 }
 
+class IPF_Admin_ModelListener
+{
+    public function beforeEdit($o)
+    {
+        $this->beforeChange($o);
+    }
+
+    public function beforeAdd($o)
+    {
+        $this->beforeChange($o);
+    }
+
+    public function beforeChange($o)
+    {
+    }
+
+    public function afterEdit($o)
+    {
+        $this->afterChange($o);
+    }
+
+    public function afterAdd($o)
+    {
+        $this->afterChange($o);
+    }
+
+    public function afterChange($o)
+    {
+    }
+}
+
 class IPF_Admin_Model
 {
     static $models = array();
@@ -387,6 +418,7 @@ class IPF_Admin_Model
     var $inlineInstances = array();
     var $perPage = 50;
     public $hidden = false;
+    public $modelListeners = array();
 
     public function __construct($modelName)
     {
@@ -608,24 +640,33 @@ class IPF_Admin_Model
 
     protected function _beforeEdit($o)
     {
+        foreach ($this->modelListeners as $l)
+            $l->beforeEdit($o);
         $this->_beforeChange($o);
     }
 
     protected function _beforeAdd($o)
     {
+        foreach ($this->modelListeners as $l)
+            $l->beforeAdd($o);
         $this->_beforeChange($o);
     }
 
-    protected function _beforeChange($o){
+    protected function _beforeChange($o)
+    {
     }
 
     protected function _afterEdit($o)
     {
+        foreach ($this->modelListeners as $l)
+            $l->afterEdit($o);
         $this->_afterChange($o);
     }
 
     protected function _afterAdd($o)
     {
+        foreach ($this->modelListeners as $l)
+            $l->afterAdd($o);
         $this->_afterChange($o);
     }