[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - IWATS - Intelligent Web Agent Ticket System * 4 * http://www.eGroupWare.org * 5 * Written by Drago Bokal <drago DOT bokal AT fmf DOT uni-lj DOT si> * 6 * Joe Stewart <joestewart AT users DOT sourceforge DOT net> * 7 * -------------------------------------------- * 8 * This program is free software; you can redistribute it and/or modify it* 9 * under the terms of the GNU General Public License as published by the * 10 * Free Software Foundation; either version 2 of the License, or (at your * 11 * option) any later version. * 12 \**************************************************************************/ 13 14 /* $ Id: class.et_media.inc.php,v 1.2 2002/10/19 11:11:03 ralfbecker Exp $ */ 15 16 include_once (EGW_INCLUDE_ROOT . '/etemplate/inc/class.so_sql.inc.php'); 17 $GLOBALS['egw_info']['flags']['included_classes']['so_sql'] = True; 18 19 20 /**! 21 @class generic_list 22 @author dragob 23 @abstract given a table and some e-templates enables listing, adding, editing and deleting the entries of the table 24 @discussion How to use generic_list 25 @discussion 1. Create a database table (using eTemplate DBTools). 26 @discussion Table must have an integer primary key. 27 @discussion Table may have an integer foreign key which represent a master-slave relationship 28 @discussion (in a one to many relationship, our table is on the "many" or "slave" side). 29 @discussion 2. Create a list entry template using eTemplate. 30 @discussion Template must contain a set of labels whose Name field must be set to 31 @discussion "${row}[field_name]", where field_name could be any field in the created table 32 @discussion Template must have Edit and Delete buttons, whose Name field must be set 33 @discussion edit[$row_cont[key_field]] and delete[$row_cont[key_field]] 34 @discussion Template may have other command buttons, whose Name field must be set to 35 @discussion command[$row_cont[key_field]] 36 @discussion 3. Create a list template using eTemplate. 37 @discussion Template must have a message row for displaying variable "msg" 38 @discussion Template must use list entry template as a subtemplate, and its Options must be 39 @discussion "entry". 40 @discussion Template must have an Add button whose Name is set to "add". 41 @discussion Template may have other command buttons, whose Name field must be set to 42 @discussion "command" 43 @discussion 4. Create an edit template using eTemplate. 44 @discussion Template must have a message row for displaying variable "msg" 45 @discussion Template must assume the variables will have the names of the table fields. 46 @discussion Template must have a Save button whose Name is set to "save". 47 @discussion Template must have a Cancel button whose Name is set to "cancel". 48 @discussion Template may have other command buttons, whose Name field must be set to 49 @discussion "command" 50 @discussion 5. Create an delete template using eTemplate. 51 @discussion Template must have a message row for displaying variable "msg" 52 @discussion Template must assume the variables will have the names of the table fields. 53 @discussion Template must have a Yes button whose Name is set to "yes". 54 @discussion Template must have a No button whose Name is set to "no". 55 @discussion Template may have other command buttons, whose Name field must be set to 56 @discussion "command" 57 @discussion 6. Create a file class.ui_myclass.inc.php looking like 58 @discussion 59 @discussion include_once(EGW_INCLUDE_ROOT . '/.../inc/class.generic_list.inc.php'); 60 @discussion $GLOBALS['egw_info']['flags']['included_classes']['generic_list'] = True; 61 @discussion 62 @discussion class ui_myclass extends generic_list 63 @discussion { 64 @discussion 65 @discussion function ui_myclass() 66 @discussion { 67 @discussion parent::create('my_application', 'my_table', 68 @discussion 'ui_myclass', 'key_field', 'my_list_template', 69 @discussion 'my_edit_template', 'my_add_template', 'my_delete_template', 70 @discussion 'master_fk_field'); 71 @discussion } 72 @discussion 73 @discussion } 74 @discussion 7. If the list or edit templates contain optional command buttons, 75 @discussion override the edit_elt method 76 @discussion function edit_elt($content='',$msg = '') 77 @discussion { 78 @discussion if (isset($content['my_command1'])) { 79 @discussion //process my_command1; 80 @discussion } 81 @discussion else if (isset($content['my_command2'])) { 82 @discussion //process my_command2; 83 @discussion } 84 @discussion else { 85 @discussion parent::edit_elt($content,$msg); 86 @discussion } 87 @discussion } 88 @discussion 8. If the delete templates contain optional command buttons, 89 @discussion override the delete_elt method in a similar fashion. 90 @discussion 91 @discussion 9. If any of the templates contain select lists, 92 @discussion override the get_sel_fields method. 93 @discussion 94 @discussion function get_sel_fields($content,$template) 95 @discussion { 96 @discussion if ($template==$this->edit_template) { 97 @discussion return( 98 @discussion array( // the options for our selectboxes for states 99 @discussion 'field_name1' => array( 100 @discussion 'key1'=>'value1', 101 @discussion 'key2'=>'value2', 102 @discussion 'key3'=>'value3' 103 @discussion ), 104 @discussion 'field_name2' => array( 105 @discussion 'key1'=>'value1', 106 @discussion 'key2'=>'value2', 107 @discussion 'key3'=>'value3' 108 @discussion ) 109 @discussion ) 110 @discussion ); 111 @discussion } 112 @discussion return array(); 113 @discussion } 114 @discussion 115 @discussion 10. If any of the templates contains fields that are not table fields, 116 @discussion override the preprocess_content method. This is useful if some integer 117 @discussion foreign key fields are to be replaced with their string descriptors. 118 @discussion 119 @discussion function preprocess_content($content,$template) 120 @discussion { 121 @discussion if ($template==$this->list_template) { 122 @discussion $content+=array( 123 @discussion 'new_field1'=>'value1', 124 @discussion 'new_field2'=>'value2', 125 @discussion 'new_field3'=>'value3' 126 @discussion ); 127 @discussion } 128 @discussion else if ($template==$this->edit_template) { 129 @discussion $content+=array( 130 @discussion ... 131 @discussion ); 132 @discussion } 133 @discussion return $content; 134 @discussion } 135 @discussion} 136 @discussion 11. If your table is in a master-slave relationship to some other, call 137 @discussion your class using some code similar to: 138 @discussion 139 @discussion ExecMethod('my_application.my_class.list_all', 140 @discussion array('master_key_field'=>master_key_value)); 141 @discussion exit; 142 @discussion 12. If your table is not in a master-slave relationship to some other, call 143 @discussion your class using some code similar to: 144 @discussion 145 @discussion ExecMethod('my_application.my_class.list_all'); 146 @discussion exit; 147 */ 148 149 class generic_list_bo 150 { 151 152 var $so; 153 154 function check_master($content) 155 { 156 return $this->so->check_master($content); 157 } 158 159 function get_master_array() 160 { 161 return $this->so->get_master_array($content); 162 } 163 164 function get_master_id() 165 { 166 return $this->so->get_master_id(); 167 } 168 169 function get_id_array($master) 170 { 171 return $this->so->get_id_array($master); 172 } 173 174 function process_content(&$content) 175 { 176 return $this->so->process_content($content); 177 } 178 179 function read_id($content) 180 { 181 return $this->so->read_id($content); 182 } 183 184 function set_button_id($content,$btn) 185 { 186 list($key,$value)=each($content[$btn]); 187 $this->so->read_id($key); 188 return $this->so->get_id_array(False); 189 } 190 191 function save($keys='') 192 { 193 return $this->so->save($keys); 194 } 195 196 function delete($keys) 197 { 198 return $this->so->delete($keys); 199 } 200 201 function get_data() 202 { 203 return $this->so->get_data(); 204 } 205 206 function list_elts() 207 { 208 $elts=$this->so->list_elts(); 209 210 if (!is_array($elts) || !count($elts)) 211 { 212 $content = array( 213 'msg' => lang('There is nothing to list.') 214 ); 215 } 216 else { 217 reset($elts); // create array with all matches, indexes starting with 1 218 for ($row=0; list($key,$data) = each($elts); ++$row) 219 { 220 $entry[$row] = $data; 221 } 222 $content = array( 223 'msg' => lang('There are %1 elements in the list.',count($elts)), 224 'entry' => $entry 225 ); 226 } 227 228 return $content; 229 } 230 } 231
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |