NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/ClearWFSFilter/ClearWFSFilter.widget.php

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * ClearWFSFilter Widget Class
4  *
5  * @project     Chameleon
6  * @revision    $Id: ClearWFSFilter.widget.php,v 1.9 2004/10/14 18:19:09 pspencer Exp $
7  * @purpose     Clear the active layer's WFS filter if found.
8  * @author      DM Solutions Group (dev@dmsolutions.ca)
9  * @copyright
10  * <b>Copyright (c) 2003, DM Solutions Group Inc.</b>
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */
29
30 include_once(dirname(__FILE__)."/../Widget.php");
31 include_once(dirname(__FILE__)."/../Button.php");
32
33 /**
34  * ClearWFSFilter
35  *
36  * @desc Display a widget that clears the active layer's WFS filter.
37  */
38 class ClearWFSFilter extends CWCWidget
39 {
40     var $moButton;
41
42     /**
43      * ExpressionBuilder
44      *
45      * Constctor method for the ExpressionBuilder
46      */
47     function ClearWFSFilter()
48     {
49         // set the language file
50         $this->mszLanguageResource = dirname(__FILE__)."/ClearWFSFilter.dbf";
51         
52         parent::CWCWidget();
53
54         $this->moButton = new CWCButton( $this );
55
56         // set the description for this widget
57         $this->szWidgetDescription = <<<EOT
58 The ClearWFSFilter widget clears the WFS filter from the active layer and deletes
59 the temporary annotation layer.
60 EOT;
61         $this->mnMaturityLevel = MATURITY_BETA;
62
63     }
64
65     function InitDefaults()
66     {
67         parent::InitDefaults();
68         //this widget should never belong to a toolset
69         $this->maParams["TOOLSET"] = "";
70         $this->moButton->InitDefaults();
71         $this->moButton->SetOnClick('clickClearWFSFilter');
72     }
73
74     /**
75      * SetMap
76      *
77      * Set the map session and create a navigation tool.
78      */
79     function SetMap($oMapSession)
80     {
81         $this->moMapObject = $oMapSession;
82     }
83
84
85     function GetJavascriptInitFunctions()
86     {
87         return $this->moButton->GetJavascriptInitFunctions();
88     }
89
90     function GetJavascriptVariables()
91     {
92         return $this->moButton->GetJavascriptVariables();
93     }
94
95         function GetJavascriptOnLoadFunctions()
96     {
97         return $this->moButton->GetJavascriptOnLoadFunctions();
98     }
99
100     function GetJavascriptIncludeFunctions()
101     {
102         return $this->moButton->GetJavascriptIncludeFunctions();
103     }
104
105     /**
106      * GetHTMLHiddenVariables
107      */
108     function GetHTMLHiddenVariables()
109     {
110         // initialize return array
111         $aReturn = $this->moButton->GetHTMLHiddenVariables();
112         
113         // set default value for the filter check
114         $szFilterSet = ( isset( $_SESSION['expr_build_filter_set'] ) &&
115                         $_SESSION['expr_build_filter_set'] == '1' ) ? '1' : '0';       
116         
117         // setup the variables
118         $szVariable = "WFS_CLEAR_FILTER";
119         $szValue = " <INPUT TYPE=hidden NAME=$szVariable VALUE=\"\">\n";
120         $aReturn[$szVariable] = $szValue;
121         $szVariable = "WFS_CLEAR_FILTER_ISSET";
122         $szValue = ' <INPUT TYPE=hidden NAME='.$szVariable.' VALUE="'.$szFilterSet."\">\n";
123         $aReturn[$szVariable] = $szValue;
124
125         // return array of hidden variables
126         return $aReturn;
127     }
128
129     /**
130      * ParseURL
131      *
132      */
133     function  ParseURL()
134     {
135         $this->moButton->ParseURL();
136         
137         // process the clear WFS filter request
138         if ( $this->isVarSet("WFS_CLEAR_FILTER") &&
139              $this->getVar("WFS_CLEAR_FILTER") == 1 )
140         {
141             // get the layer object
142             $nCount = $this->moMapObject->oMap->numlayers;
143             for ( $i=0; $i<$nCount; $i++ )
144             {
145                 // get next layer
146                 $oLayer = $this->moMapObject->oMap->getlayer( $i );
147
148                 // if metadata is set then clear
149                 if ( $oLayer->getmetadata("selected") == 1 &&
150                      strlen( trim( $oLayer->getmetadata("wfs_filter" ) ) ) > 0 )
151                     $oLayer->removeMetaData( "wfs_filter" );
152                     
153                 // delete annotation layer
154                 if ( $oLayer->name == 'ExpressionBuilderAnnotation' )
155                 {
156                     $oLayer->set( 'status', MS_DELETE );
157                 }
158                 
159                 // clear the session variable
160                 $_SESSION['expr_build_filter_set'] = '0';
161
162                 if( isset($_SESSION['expr_build_origin_layer']) &&
163                     $oLayer->name == $_SESSION['expr_build_origin_layer'] )
164                 {
165                     $oTmpLayer = $this->moMapObject->oMap->getLayerByName(
166                         'ExpressionBuilderAnnotation' );
167                     if( $oTmpLayer &&
168                         $oTmpLayer->getmetadata('selected') == 1 )
169                     {
170                         $oLayer->setmetadata( 'selected', 1 );
171                         $oTmpLayer->setmetadata( 'selected', 0 );
172                     }
173                 }
174             }
175         }
176
177         // return success
178         return true;
179     }
180
181     /**
182      * GetJavascriptFunctions
183      *
184      * Build and return the array of functions needed in the
185      * widget.
186      */
187     function GetJavascriptFunctions()
188     {
189         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
190           $bCWCJSAPI = 1;
191         else
192           $bCWCJSAPI = 0;
193
194         $aReturn = $this->moButton->GetJavascriptFunctions();//array();
195
196         // Add code to clear filter
197         $szJsFunctionName = "clickClearWFSFilter";
198         $szNoFilterMessage = $this->moMLT->get( "1", "There is no filter to clear." );
199         $szWarningMessage = $this->moMLT->get( "0", "You are about to clear the WFS ".
200             "filter.  Do you wish to continue?" );
201         $szFunction = <<<EOT
202 /**
203  * {$szJsFunctionName}
204  * Clear the WFS filter
205  */
206 function {$szJsFunctionName}()
207 {
208     // give message if there is nothing to delete
209     if ( {$this->mszHTMLForm}.WFS_CLEAR_FILTER_ISSET.value == 1 )
210     {
211     
212         // warn the user that they are about to clear the filter
213         if ( confirm( "{$szWarningMessage}" ) )
214         {
215             // set the hidden form vars
216             {$this->mszHTMLForm}.WFS_CLEAR_FILTER.value = 1;
217         
218             // submit the form
219             {$this->mszHTMLForm}.submit();
220         }
221     }
222     else
223     {
224         alert('{$szNoFilterMessage}');
225     }
226             
227     // return
228     return;
229 }
230 EOT;
231
232         $aReturn[$szJsFunctionName] = $szFunction;
233
234         // return the array of functions
235         return $aReturn;
236     }
237
238     /**
239      * DrawPublish
240      *
241      * Return the HTML code using the name in the map file and the
242      * parameters of the CWC tag.
243      */
244     function DrawPublish()
245     {
246         if (!$this->mbVisible)
247             return "<!-- clickClearWFSFilter widget hidden -->";
248
249         $szResult = $this->moButton->DrawPublish();
250         return $szResult;
251     }
252 }
253
254
255 ?>
256
Note: See TracBrowser for help on using the browser.