developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #1071: ticket_1071.diff

File ticket_1071.diff, 3.6 KB (added by bricet, 12 years ago)

Patch to introduced 3 new methods

Line 
1diff -r 9ffb4169618e lib/jelix/CREDITS
2--- a/lib/jelix/CREDITS Mon Mar 22 11:26:39 2010 +0100
3+++ b/lib/jelix/CREDITS Mon Mar 22 17:26:10 2010 +0100
4@@ -298,6 +301,8 @@
5 
6 Brice Tence (aka brayce)
7  - small testapp bug solved about missing tables (#1064)
8+ - added clear(), getInstancesCount() and destroyAllInstances() to jForms
9 
10 Thanks for all users, especially those who reported bugs. :-)
11 
12diff -r 9ffb4169618e lib/jelix/forms/jForms.class.php
13--- a/lib/jelix/forms/jForms.class.php  Mon Mar 22 11:26:39 2010 +0100
14+++ b/lib/jelix/forms/jForms.class.php  Mon Mar 22 17:26:10 2010 +0100
15@@ -118,6 +118,55 @@
16     }
17 
18     /**
19+     * get an existing instance of a form, and clear all its data
20+     *
21+     * @param string $formSel the selector of the xml jform file
22+     * @param string $formId  the id of the form (if you use multiple instance of a form)
23+     */
24+    static public function clear($formSel,$formId=null){
25+        global $gJCoord;
26+        if($formId === null)  $formId = self::DEFAULT_ID;
27+        if(is_array($formId)) $formId = serialize($formId);
28+       
29+        // normalize the selector to avoid conflict in session
30+        $sel = new jSelectorForm($formSel);
31+        $formSel = $sel->toString();
32+
33+        if(isset($_SESSION['JFORMS'][$formSel][$formId])){
34+            $_SESSION['JFORMS'][$formSel][$formId]->clear();
35+        }
36+
37+        return self::get($formSel,$formId);
38+    }
39+
40+    /**
41+     * get the number of reference counts of a jForm
42+     *
43+     * @param string $formSel the selector of the xml jform file
44+     * @param string $formId  the id of the form (if you use multiple instance of a form)
45+     */
46+    static public function getInstancesCount($formSel,$formId=null){
47+        global $gJCoord;
48+        if($formId === null)  $formId = self::DEFAULT_ID;
49+        if(is_array($formId)) $formId = serialize($formId);
50+       
51+        // normalize the selector to avoid conflict in session
52+        $sel = new jSelectorForm($formSel);
53+        $formSel = $sel->toString();
54+
55+        if(isset($_SESSION['JFORMS'][$formSel][$formId])){
56+            if( isset($_SESSION['JFORMS'][$formSel][$formId]->refcount) ) {
57+                return $_SESSION['JFORMS'][$formSel][$formId]->refcount;
58+            } else {
59+                return 1;
60+            }
61+        } else {
62+            return 0;
63+        }
64+    }
65+
66+
67+    /**
68      * destroy a form in the session
69      *
70      * use it after saving data of a form, and if you don't want to re-display the form.
71@@ -146,6 +195,33 @@
72     }
73 
74     /**
75+     * destroy all instances of a form in the session
76+     *
77+     * @param string $formSel the selector of the xml jform file
78+     * @param string $formId  the id of the form (if you use multiple instance of a form)
79+     */
80+    static public function destroyAllInstances($formSel='', $formId=null){
81+        if(!isset($_SESSION['JFORMS'])) return;
82+        if($formSel=='') {
83+            foreach($_SESSION['JFORMS'] as $sel=>$f) {
84+                self::destroyAllInstances($sel,$formId);
85+            }
86+        } else {
87+            if($formId === null)  $formId = self::DEFAULT_ID;
88+            if(is_array($formId)) $formId = serialize($formId);
89+
90+            // normalize the selector to avoid conflict in session
91+            $sel = new jSelectorForm($formSel);
92+            $formSel = $sel->toString();
93+
94+            if(isset($_SESSION['JFORMS'][$formSel][$formId])){
95+                unset($_SESSION['JFORMS'][$formSel][$formId]);
96+            }
97+        }
98+    }
99+
100+
101+    /**
102      * destroy all form which are too old and unused
103      * @param integer $life the number of second of a life of a form
104      */