├── .gitignore ├── README.md ├── application ├── config │ └── datamapper.php ├── datamapper │ ├── array.php │ ├── csv.php │ ├── htmlform.php │ ├── json.php │ ├── nestedsets.php │ ├── rowindex.php │ ├── simplecache.php │ └── translate.php ├── helpers │ └── inflector_helper.php ├── language │ ├── ca │ │ └── datamapper_lang.php │ ├── english │ │ └── datamapper_lang.php │ ├── es │ │ └── datamapper_lang.php │ ├── fr │ │ └── datamapper_lang.php │ ├── it │ │ └── datamapper_lang.php │ ├── nl │ │ └── datamapper_lang.php │ └── pt_BR │ │ └── datamapper_lang.php ├── libraries │ └── datamapper.php ├── models │ └── _template.php ├── third_party │ └── datamapper │ │ ├── bootstrap.php │ │ └── system │ │ ├── DB.php │ │ ├── DB_driver.php │ │ ├── Lang.php │ │ └── Loader.php └── views │ └── dmz_htmlform │ ├── form.php │ ├── row.php │ └── section.php ├── examples ├── application │ ├── config │ │ ├── autoload.php │ │ └── datamapper.php │ ├── controllers │ │ ├── admin.php │ │ ├── bugs.php │ │ ├── login.php │ │ ├── logout.php │ │ ├── users.php │ │ └── welcome.php │ ├── helpers │ │ └── utilities_helper.php │ ├── language │ │ └── english │ │ │ ├── model_bug_lang.php │ │ │ ├── model_category_lang.php │ │ │ ├── model_comment_lang.php │ │ │ ├── model_group_lang.php │ │ │ ├── model_status_lang.php │ │ │ └── model_user_lang.php │ ├── libraries │ │ └── login_manager.php │ ├── models │ │ ├── bug.php │ │ ├── category.php │ │ ├── comment.php │ │ ├── group.php │ │ ├── status.php │ │ └── user.php │ ├── sql │ │ ├── data │ │ │ ├── category.csv │ │ │ ├── group.csv │ │ │ └── status.csv │ │ ├── mysql │ │ │ ├── bugs.sql │ │ │ ├── bugs_categories.sql │ │ │ ├── bugs_users.sql │ │ │ ├── categories.sql │ │ │ ├── comments.sql │ │ │ ├── dependencies_dependents.sql │ │ │ ├── groups.sql │ │ │ ├── statuses.sql │ │ │ └── users.sql │ │ ├── mysqli │ │ │ ├── bugs.sql │ │ │ ├── bugs_categories.sql │ │ │ ├── bugs_users.sql │ │ │ ├── categories.sql │ │ │ ├── comments.sql │ │ │ ├── dependencies_dependents.sql │ │ │ ├── groups.sql │ │ │ ├── statuses.sql │ │ │ └── users.sql │ │ ├── postgre │ │ │ ├── bugs.sql │ │ │ ├── bugs_categories.sql │ │ │ ├── bugs_users.sql │ │ │ ├── categories.sql │ │ │ ├── comments.sql │ │ │ ├── dependencies_dependents.sql │ │ │ ├── groups.sql │ │ │ ├── statuses.sql │ │ │ └── users.sql │ │ └── tabledroplist.txt │ └── views │ │ ├── admin │ │ ├── index.php │ │ ├── init.php │ │ └── reset.php │ │ ├── bugs │ │ ├── edit.php │ │ ├── list.php │ │ ├── paging.php │ │ ├── search.php │ │ └── view.php │ │ ├── login.php │ │ ├── template_footer.php │ │ ├── template_header.php │ │ ├── users │ │ ├── delete.php │ │ ├── edit.php │ │ └── index.php │ │ └── welcome │ │ └── index.php ├── css │ └── style.css └── img │ ├── bg.png │ ├── cc.png │ ├── favicon.png │ ├── header-logo.jpg │ ├── icon │ ├── 16 │ │ ├── add.png │ │ ├── back.png │ │ ├── delete.png │ │ ├── edit.png │ │ ├── move_bottom.png │ │ ├── move_down.png │ │ ├── move_top.png │ │ ├── move_up.png │ │ ├── search.png │ │ └── view.png │ └── 64 │ │ ├── categories.png │ │ ├── database.png │ │ ├── groups.png │ │ ├── statuses.png │ │ └── users.png │ └── profiler.png ├── license.txt └── manual ├── css └── userguide.css ├── images ├── arrow.gif ├── dmz.png ├── dmzlogo.png ├── donate_button.gif ├── download.png ├── example.png ├── favicon.png ├── feed.png ├── nav_bg_darker.jpg ├── nav_separator_darker.jpg ├── nav_toggle_darker.jpg ├── nestedsets.gif ├── notice_icon.jpg └── searchlogo.png ├── index.html ├── js ├── menu.js ├── mootools.js └── rot13.js ├── pages ├── _template.html ├── accessingrelations.html ├── advancedrelations.html ├── advancedusage.html ├── changelog.html ├── changelog │ ├── 1.2.html │ ├── 1.3.html │ ├── 1.4.html │ └── 1.5.html ├── clear.html ├── clonecopy.html ├── config.html ├── controllers.html ├── count.html ├── credits.html ├── database.html ├── delete.html ├── deleteall.html ├── deletingrelations.html ├── download.html ├── examples.html ├── examples │ ├── htmlform.html │ └── login.html ├── exists.html ├── extensions.html ├── extensions │ ├── array.html │ ├── csv.html │ ├── htmlform.html │ ├── json.html │ ├── nestedsets.html │ ├── rowindex.html │ ├── simplecache.html │ └── translate.html ├── extlist.html ├── extwrite.html ├── functions.html ├── get.html ├── getadvanced.html ├── getalt.html ├── getby.html ├── getrules.html ├── gettingstarted.html ├── glossary.html ├── installation.html ├── joinfields.html ├── license.html ├── localize.html ├── manual.html ├── models.html ├── prefix.html ├── prodcache.html ├── refreshall.html ├── relationtypes.html ├── requirements.html ├── reservednames.html ├── roadmap.html ├── save.html ├── savingrelations.html ├── settingrelations.html ├── subqueries.html ├── timestamp.html ├── toc.html ├── transactions.html ├── troubleshooting.html ├── update.html ├── upgrade.html ├── utility.html ├── validate.html └── validation.html ├── robots.txt ├── rss.xml └── sitemap.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Eclipse project files 2 | .buildpath 3 | .project 4 | .settings/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | datamapper 2 | ========== 3 | 4 | CodeIgniter Datamapper 5 | DataMapper is an Object Relational Mapper written in PHP for CodeIgniter. It is designed to map your Database tables into easy to work with objects, fully aware of the relationships between each other. 6 | 7 | General Features 8 | 9 | Everything is an object! 10 | Easy to setup, easy to use. 11 | Custom Validation on object properties. 12 | Lazy Loading (related objects are only loaded upon access). 13 | Relations and their integrity are automatically managed for you. 14 | One to One, One to Many, and Many to Many relations fully supported. 15 | Select data in the style of Active Record (with or without Method Chaining). 16 | -------------------------------------------------------------------------------- /application/config/datamapper.php: -------------------------------------------------------------------------------- 1 | '; 12 | $config['error_suffix'] = '

'; 13 | $config['created_field'] = 'created'; 14 | $config['updated_field'] = 'updated'; 15 | $config['local_time'] = FALSE; 16 | $config['unix_timestamp'] = FALSE; 17 | $config['timestamp_format'] = 'Y-m-d H:i:s'; 18 | $config['lang_file_format'] = 'model_${model}'; 19 | $config['field_label_lang_format'] = '${model}_${field}'; 20 | $config['auto_transaction'] = FALSE; 21 | $config['auto_populate_has_many'] = FALSE; 22 | $config['auto_populate_has_one'] = FALSE; 23 | $config['all_array_uses_ids'] = FALSE; 24 | // set to FALSE to use the same DB instance across the board (breaks subqueries) 25 | // Set to any acceptable parameters to $CI->database() to override the default. 26 | $config['db_params'] = ''; 27 | // Uncomment to enable the production cache 28 | // $config['production_cache'] = 'datamapper/cache'; 29 | $config['extensions_path'] = 'datamapper'; 30 | $config['extensions'] = array(); 31 | $config['cascade_delete'] = TRUE; 32 | 33 | /* End of file datamapper.php */ 34 | /* Location: ./application/config/datamapper.php */ 35 | -------------------------------------------------------------------------------- /application/datamapper/csv.php: -------------------------------------------------------------------------------- 1 | fields; 40 | } 41 | 42 | $success = TRUE; 43 | 44 | // determine if we need to open the file or not. 45 | if(is_string($filename)) 46 | { 47 | // open the file, if possible. 48 | $fp = fopen($filename, 'w'); 49 | if($fp === FALSE) 50 | { 51 | log_message('error', 'CSV Extension: Unable to open file ' . $filename); 52 | return FALSE; 53 | } 54 | } 55 | else 56 | { 57 | // assume file pointer. 58 | $fp = $filename; 59 | } 60 | 61 | if($include_header) 62 | { 63 | // Print out header line 64 | $success = fputcsv($fp, $fields); 65 | } 66 | 67 | if($success) 68 | { 69 | foreach($object as $o) 70 | { 71 | // convert each object into an array 72 | $result = array(); 73 | foreach($fields as $f) 74 | { 75 | $result[] = $o->{$f}; 76 | } 77 | // output CSV-formatted line 78 | $success = fputcsv($fp, $result); 79 | if(!$success) 80 | { 81 | // stop on first failure. 82 | break; 83 | } 84 | } 85 | } 86 | 87 | if(is_string($filename)) 88 | { 89 | fclose($fp); 90 | } 91 | 92 | return $success; 93 | } 94 | 95 | /** 96 | * Import objects from a CSV file. 97 | * 98 | * Completely empty rows are automatically skipped, as are rows that 99 | * start with a # sign (assumed to be comments). 100 | * 101 | * @param DataMapper $object The type of DataMapper Object to import 102 | * @param mixed $filename Name of CSV file, or a file pointer. 103 | * @param array $fields If empty, the database fields are used. Otherwise used to limit what fields are saved. 104 | * @param boolean $header_row If true, the first line is assumed to be a header row. Defaults to true. 105 | * @param mixed $callback A callback method for each row. Can return FALSE on failure to save, or 'stop' to stop the import. 106 | * @return array Array of imported objects, or FALSE if unable to import. 107 | */ 108 | function csv_import($object, $filename, $fields = '', $header_row = TRUE, $callback = NULL) 109 | { 110 | $class = get_class($object); 111 | 112 | if(empty($fields)) 113 | { 114 | $fields = $object->fields; 115 | } 116 | 117 | // determine if we need to open the file or not. 118 | if(is_string($filename)) 119 | { 120 | // open the file, if possible. 121 | $fp = fopen($filename, 'r'); 122 | if($fp === FALSE) 123 | { 124 | log_message('error', 'CSV Extension: Unable to open file ' . $filename); 125 | return FALSE; 126 | } 127 | } 128 | else 129 | { 130 | // assume file pointer. 131 | $fp = $filename; 132 | } 133 | 134 | if(empty($callback)) 135 | { 136 | $result = array(); 137 | } 138 | else 139 | { 140 | $result = 0; 141 | } 142 | $columns = NULL; 143 | 144 | while(($data = fgetcsv($fp)) !== FALSE) 145 | { 146 | // get column names 147 | if(is_null($columns)) 148 | { 149 | if($header_row) 150 | { 151 | // store header row for column names 152 | $columns = $data; 153 | // only include columns in $fields 154 | foreach($columns as $index => $name) 155 | { 156 | if( ! in_array($name, $fields)) 157 | { 158 | // mark column as false to skip 159 | $columns[$index] = FALSE; 160 | } 161 | } 162 | continue; 163 | } 164 | else 165 | { 166 | $columns = $fields; 167 | } 168 | } 169 | 170 | // skip on comments and empty rows 171 | if(empty($data) || $data[0][0] == '#' || implode('', $data) == '') 172 | { 173 | continue; 174 | } 175 | 176 | // create the object to save 177 | $o = new $class(); 178 | foreach($columns as $index => $key) 179 | { 180 | if(count($data) <= $index) 181 | { 182 | // more header columns than data columns 183 | break; 184 | } 185 | 186 | // skip columns that were determined to not be needed above. 187 | if($key === FALSE) 188 | { 189 | continue; 190 | } 191 | 192 | // finally, it's OK to save the data column. 193 | $o->{$key} = $data[$index]; 194 | } 195 | 196 | if( empty($callback)) 197 | { 198 | $result[] = $o; 199 | } 200 | else 201 | { 202 | $test = call_user_func($callback, $o); 203 | if($test === 'stop') 204 | { 205 | break; 206 | } 207 | if($test !== FALSE) 208 | { 209 | $result++; 210 | } 211 | } 212 | } 213 | 214 | if(is_string($filename)) 215 | { 216 | fclose($fp); 217 | } 218 | 219 | return $result; 220 | } 221 | 222 | } 223 | 224 | /* End of file csv.php */ 225 | /* Location: ./application/datamapper/csv.php */ 226 | -------------------------------------------------------------------------------- /application/datamapper/simplecache.php: -------------------------------------------------------------------------------- 1 | _should_delete_cache) ) 35 | { 36 | $object->db->cache_delete(); 37 | $object->_should_delete_cache = FALSE; 38 | } 39 | 40 | $object->db->cache_on(); 41 | // get the arguments, but pop the object. 42 | $args = func_get_args(); 43 | array_shift($args); 44 | call_user_func_array(array($object, 'get'), $args); 45 | $object->db->cache_off(); 46 | return $object; 47 | } 48 | 49 | /** 50 | * Clears the cached query the next time get_cached is called. 51 | * 52 | * @param DataMapper $object The DataMapper Object. 53 | * @return DataMapper The DataMapper $object for chaining. 54 | */ 55 | function clear_cache($object) 56 | { 57 | $args = func_get_args(); 58 | array_shift($args); 59 | if( ! empty($args)) { 60 | call_user_func_array(array($object->db, 'cache_delete'), $args); 61 | } else { 62 | $object->_should_delete_cache = TRUE; 63 | } 64 | return $object; 65 | } 66 | 67 | } 68 | 69 | /* End of file simplecache.php */ 70 | /* Location: ./application/datamapper/simplecache.php */ 71 | -------------------------------------------------------------------------------- /application/datamapper/translate.php: -------------------------------------------------------------------------------- 1 | fields; 40 | } 41 | 42 | // loop through the fields 43 | foreach($fields as $f) 44 | { 45 | // first, deal with the loaded fields 46 | if ( isset($object->{$f}) ) 47 | { 48 | $line = lang($object->{$f}); 49 | if ( $line ) 50 | { 51 | $object->{$f}; 52 | } 53 | } 54 | 55 | // then, loop through the all array 56 | foreach($object->all as $key => $all_object) 57 | { 58 | if ( isset($all_object->{$f}) ) 59 | { 60 | $line = lang($all_object->{$f}); 61 | if ( $line ) 62 | { 63 | $object->all[$key]->{$f} = $line; 64 | } 65 | } 66 | } 67 | } 68 | 69 | // return the Datamapper object 70 | return $object; 71 | } 72 | 73 | } 74 | 75 | /* End of file translate.php */ 76 | /* Location: ./application/datamapper/translate.php */ 77 | -------------------------------------------------------------------------------- /application/helpers/inflector_helper.php: -------------------------------------------------------------------------------- 1 | 4 OR in_array($end3, array('ses', 'hes', 'oes'))) 64 | { 65 | $str = substr($str, 0, -2); 66 | } 67 | elseif (in_array($end2, array('da', 'ia', 'la'))) 68 | { 69 | $str = substr($str, 0, -1).'um'; 70 | } 71 | elseif (in_array($end2, array('bi', 'ei', 'gi', 'li', 'mi', 'pi'))) 72 | { 73 | $str = substr($str, 0, -1).'us'; 74 | } 75 | else 76 | { 77 | if ($end1 == 's' && $end2 != 'us' && $end2 != 'ss') 78 | { 79 | $str = substr($str, 0, -1); 80 | } 81 | } 82 | 83 | return $str; 84 | } 85 | } 86 | 87 | // -------------------------------------------------------------------- 88 | 89 | /** 90 | * Plural 91 | * 92 | * Takes a singular word and makes it plural (improved by stensi) 93 | * 94 | * @access public 95 | * @param string 96 | * @param bool 97 | * @return str 98 | */ 99 | if ( ! function_exists('plural')) 100 | { 101 | function plural($str, $force = FALSE) 102 | { 103 | $str = strtolower(trim($str)); 104 | $end3 = substr($str, -3); 105 | $end2 = substr($str, -2); 106 | $end1 = substr($str, -1); 107 | 108 | if ($end3 == 'eau') 109 | { 110 | $str .= 'x'; 111 | } 112 | elseif ($end3 == 'man') 113 | { 114 | $str = substr($str, 0, -2).'en'; 115 | } 116 | elseif (in_array($end3, array('dum', 'ium', 'lum'))) 117 | { 118 | $str = substr($str, 0, -2).'a'; 119 | } 120 | elseif (strlen($str) > 4 && in_array($end3, array('bus', 'eus', 'gus', 'lus', 'mus', 'pus'))) 121 | { 122 | $str = substr($str, 0, -2).'i'; 123 | } 124 | elseif ($end3 == 'ife') 125 | { 126 | $str = substr($str, 0, -2).'ves'; 127 | } 128 | elseif ($end1 == 'f') 129 | { 130 | $str = substr($str, 0, -1).'ves'; 131 | } 132 | elseif ($end1 == 'y') 133 | { 134 | if(preg_match('#[aeiou]y#i', $end2)) 135 | { 136 | // ays, oys, etc. 137 | $str = $str . 's'; 138 | } 139 | else 140 | { 141 | $str = substr($str, 0, -1).'ies'; 142 | } 143 | } 144 | elseif ($end1 == 'o') 145 | { 146 | if(preg_match('#[aeiou]o#i', $end2)) 147 | { 148 | // oos, etc. 149 | $str = $str . 's'; 150 | } 151 | else 152 | { 153 | $str .= 'es'; 154 | } 155 | } 156 | elseif ($end1 == 'x' || in_array($end2, array('ss', 'ch', 'sh')) ) 157 | { 158 | $str .= 'es'; 159 | } 160 | elseif ($end1 == 's') 161 | { 162 | if ($force == TRUE) 163 | { 164 | $str .= 'es'; 165 | } 166 | } 167 | else 168 | { 169 | $str .= 's'; 170 | } 171 | 172 | return $str; 173 | } 174 | } 175 | 176 | // -------------------------------------------------------------------- 177 | 178 | /** 179 | * Camelize 180 | * 181 | * Takes multiple words separated by spaces or underscores and camelizes them 182 | * 183 | * @access public 184 | * @param string 185 | * @return str 186 | */ 187 | if ( ! function_exists('camelize')) 188 | { 189 | function camelize($str) 190 | { 191 | $str = 'x'.strtolower(trim($str)); 192 | $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); 193 | return substr(str_replace(' ', '', $str), 1); 194 | } 195 | } 196 | 197 | // -------------------------------------------------------------------- 198 | 199 | /** 200 | * Underscore 201 | * 202 | * Takes multiple words separated by spaces and underscores them 203 | * 204 | * @access public 205 | * @param string 206 | * @return str 207 | */ 208 | if ( ! function_exists('underscore')) 209 | { 210 | function underscore($str) 211 | { 212 | return preg_replace('/[\s]+/', '_', strtolower(trim($str))); 213 | } 214 | } 215 | 216 | // -------------------------------------------------------------------- 217 | 218 | /** 219 | * Humanize 220 | * 221 | * Takes multiple words separated by underscores and changes them to spaces 222 | * 223 | * @access public 224 | * @param string 225 | * @return str 226 | */ 227 | if ( ! function_exists('humanize')) 228 | { 229 | function humanize($str) 230 | { 231 | return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str)))); 232 | } 233 | } 234 | 235 | /* End of file inflector_helper.php */ 236 | /* Location: ./application/helpers/inflector_helper.php */ -------------------------------------------------------------------------------- /application/language/ca/datamapper_lang.php: -------------------------------------------------------------------------------- 1 | array( 51 | * 'class' => 'user', 52 | * 'other_field' => 'created_template' 53 | * ) 54 | * ); 55 | * 56 | * Don't forget to add 'created_template' to User, with class set to 57 | * 'template', and the other_field set to 'creator'! 58 | * 59 | */ 60 | 61 | // -------------------------------------------------------------------- 62 | // Validation 63 | // Add validation requirements, such as 'required', for your fields. 64 | // -------------------------------------------------------------------- 65 | 66 | var $validation = array( 67 | 'example' => array( 68 | // example is required, and cannot be more than 120 characters long. 69 | 'rules' => array('required', 'max_length' => 120), 70 | 'label' => 'Example' 71 | ) 72 | ); 73 | 74 | // -------------------------------------------------------------------- 75 | // Default Ordering 76 | // Uncomment this to always sort by 'name', then by 77 | // id descending (unless overridden) 78 | // -------------------------------------------------------------------- 79 | 80 | // var $default_order_by = array('name', 'id' => 'desc'); 81 | 82 | // -------------------------------------------------------------------- 83 | 84 | /** 85 | * Constructor: calls parent constructor 86 | */ 87 | function __construct($id = NULL) 88 | { 89 | parent::__construct($id); 90 | } 91 | 92 | // -------------------------------------------------------------------- 93 | // Post Model Initialisation 94 | // Add your own custom initialisation code to the Model 95 | // The parameter indicates if the current config was loaded from cache or not 96 | // -------------------------------------------------------------------- 97 | function post_model_init($from_cache = FALSE) 98 | { 99 | } 100 | 101 | // -------------------------------------------------------------------- 102 | // Custom Methods 103 | // Add your own custom methods here to enhance the model. 104 | // -------------------------------------------------------------------- 105 | 106 | /* Example Custom Method 107 | function get_open_templates() 108 | { 109 | return $this->where('status <>', 'closed')->get(); 110 | } 111 | */ 112 | 113 | // -------------------------------------------------------------------- 114 | // Custom Validation Rules 115 | // Add custom validation rules for this model here. 116 | // -------------------------------------------------------------------- 117 | 118 | /* Example Rule 119 | function _convert_written_numbers($field, $parameter) 120 | { 121 | $nums = array('one' => 1, 'two' => 2, 'three' => 3); 122 | if(in_array($this->{$field}, $nums)) 123 | { 124 | $this->{$field} = $nums[$this->{$field}]; 125 | } 126 | } 127 | */ 128 | } 129 | 130 | /* End of file template.php */ 131 | /* Location: ./application/models/template.php */ 132 | -------------------------------------------------------------------------------- /application/third_party/datamapper/bootstrap.php: -------------------------------------------------------------------------------- 1 | {\$function}(...\$args); 29 | } 30 | 31 | // public interface to internal driver properties 32 | public function dm_get(\$var) 33 | { 34 | return isset(\$this->{\$var}) ? \$this->{\$var} : NULL; 35 | } 36 | 37 | public function dm_set(\$var, \$value) 38 | { 39 | \$this->{\$var} = \$value; 40 | } 41 | 42 | public function dm_set_append(\$var, \$value) 43 | { 44 | \$this->{\$var}[] = \$value; 45 | } 46 | } 47 | CODE; 48 | 49 | // dynamically add our class extension 50 | eval($dmclass); 51 | unset($dmclass); 52 | } 53 | 54 | /* End of file DB_driver.php */ 55 | /* Location: ./application/third_party/datamapper/system/DB_driver.php */ 56 | -------------------------------------------------------------------------------- /application/third_party/datamapper/system/Lang.php: -------------------------------------------------------------------------------- 1 | language[\$line])) ? FALSE : \$this->language[\$line]; 32 | } 33 | } 34 | CODE; 35 | 36 | // dynamically add our class extension 37 | eval($dmclass); 38 | unset($dmclass); 39 | 40 | // and update the name of the class to instantiate 41 | $name = 'DM_Lang'; 42 | 43 | /* End of file Lang.php */ 44 | /* Location: ./application/third_party/datamapper/system/Lang.php */ 45 | -------------------------------------------------------------------------------- /application/third_party/datamapper/system/Loader.php: -------------------------------------------------------------------------------- 1 | db) AND is_object(\$CI->db)) 36 | { 37 | return FALSE; 38 | } 39 | 40 | require_once(DATAMAPPERPATH.'third_party/datamapper/system/DB.php'); 41 | 42 | if (\$return === TRUE) 43 | { 44 | return DB(\$params, \$active_record); 45 | } 46 | 47 | // Initialize the db variable. Needed to prevent 48 | // reference errors with some configurations 49 | \$CI->db = ''; 50 | 51 | // Load the DB class 52 | \$CI->db =& DB(\$params, \$active_record); 53 | } 54 | } 55 | CODE; 56 | 57 | // dynamically add our class extension 58 | eval($dmclass); 59 | unset($dmclass); 60 | 61 | // and update the name of the class to instantiate 62 | $name = 'DM_Loader'; 63 | 64 | /* End of file Loader.php */ 65 | /* Location: ./application/third_party/datamapper/system/Loader.php */ 66 | -------------------------------------------------------------------------------- /application/views/dmz_htmlform/form.php: -------------------------------------------------------------------------------- 1 | 18 | error->all)): ?> 19 |
20 |

There was an error saving the form.

21 | 25 |
26 | 27 | 28 |
29 | 30 | 31 | 32 | 38 | 39 |
40 |
41 | -------------------------------------------------------------------------------- /application/views/dmz_htmlform/row.php: -------------------------------------------------------------------------------- 1 | 54 | > 55 | >: 56 | 57 | 58 | 61 | 62 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /application/views/dmz_htmlform/section.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /examples/application/config/autoload.php: -------------------------------------------------------------------------------- 1 | '; 12 | $config['error_suffix'] = ''; 13 | $config['created_field'] = 'created'; 14 | $config['updated_field'] = 'updated'; 15 | $config['local_time'] = FALSE; 16 | $config['unix_timestamp'] = FALSE; 17 | $config['timestamp_format'] = 'Y-m-d H:i:s'; 18 | $config['lang_file_format'] = 'model_${model}'; 19 | $config['field_label_lang_format'] = '${model}_${field}'; 20 | $config['auto_transaction'] = FALSE; 21 | $config['auto_populate_has_many'] = FALSE; 22 | $config['auto_populate_has_one'] = TRUE; 23 | $config['all_array_uses_ids'] = FALSE; 24 | // set to FALSE to use the same DB instance across the board (breaks subqueries) 25 | // Set to any acceptable parameters to $CI->database() to override the default. 26 | $config['db_params'] = ''; 27 | // Uncomment to enable the production cache 28 | // $config['production_cache'] = 'datamapper/cache'; 29 | $config['extensions_path'] = 'datamapper'; 30 | $config['extensions'] = array('array'); 31 | 32 | /* End of file datamapper.php */ 33 | /* Location: ./application/config/datamapper.php */ 34 | -------------------------------------------------------------------------------- /examples/application/controllers/admin.php: -------------------------------------------------------------------------------- 1 | load->library('login_manager', array('autologin' => FALSE)); 9 | } 10 | 11 | function index() 12 | { 13 | $this->login_manager->check_login(1); 14 | $this->load->view('template_header', array('title' => 'Admin Console', 'section' => 'admin')); 15 | $this->load->view('admin/index'); 16 | $this->load->view('template_footer'); 17 | } 18 | 19 | function reset_warning() 20 | { 21 | if( ! $this->session->userdata('first_time') && 22 | $this->db->table_exists('users') && $this->login_manager->get_user() !== FALSE) 23 | { 24 | show_error('The database is already configured'); 25 | } 26 | $this->load->view('template_header', array('title' => 'First Time Setup', 'section' => 'admin', 'hide_nav' => TRUE)); 27 | $this->load->view('admin/reset', array('first_time' => TRUE)); 28 | $this->load->view('template_footer'); 29 | } 30 | 31 | /** 32 | * Resets the entire Database 33 | */ 34 | function reset() 35 | { 36 | $this->load->dbforge(); 37 | try { 38 | // force disabling of g-zip so output can be streamed 39 | apache_setenv('no-gzip', '1'); 40 | } catch(Exception $e) { /* ignore */ } 41 | 42 | $success = TRUE; 43 | 44 | $first_time = $this->session->userdata('first_time') || 45 | ( ! $this->db->table_exists('users') && $this->login_manager->get_user() === FALSE); 46 | 47 | if( ! $first_time) 48 | { 49 | $this->login_manager->check_login(1); 50 | } 51 | 52 | $this->session->set_userdata('first_time', TRUE); 53 | 54 | echo $this->load->view('template_header', array('title' => 'Resetting Database', 'section' => 'admin', 'hide_nav' => $first_time), TRUE); 55 | ?>
_message('Creating the Squash database at ' . $this->db->database . '
', ''); 57 | $success = $success && $this->_drop_tables(); 58 | echo("

"); 59 | $success = $success && $this->_create_tables(); 60 | echo("

"); 61 | $success = $success && $this->_init_data(); 62 | 63 | ?>

Continue

An error occurred. Please reset the database and try again.load->view('template_footer'); 71 | } 72 | 73 | function _drop_tables() { 74 | $list = file(APPPATH . 'sql/tabledroplist.txt'); 75 | foreach($list as $table) { 76 | $table = trim($table); 77 | if(empty($table) || $table[0] == '#') { 78 | continue; 79 | } 80 | if($this->db->table_exists($table)) { 81 | $this->_message("Dropping table $table..."); 82 | if($this->dbforge->drop_table($table)) { 83 | echo("done."); 84 | } else { 85 | echo("ERROR."); 86 | return FALSE; 87 | } 88 | } 89 | } 90 | return TRUE; 91 | } 92 | 93 | function _create_tables() { 94 | $this->load->helper('file'); 95 | $path = APPPATH . 'sql/' . $this->db->dbdriver; 96 | if( ! file_exists($path)) { 97 | show_error("ERROR: Unable to automatically create tables for " . $this->db->dbdriver . ' databases.'); 98 | } 99 | $tables = get_filenames($path); 100 | foreach($tables as $table) { 101 | $n = str_ireplace('.sql', '', $table); 102 | $this->_message("Creating table $n..."); 103 | $sql = file_get_contents($path . '/' . $table); 104 | if($this->db->query($sql)) { 105 | echo("done."); 106 | } else { 107 | echo("ERROR."); 108 | return FALSE; 109 | } 110 | } 111 | return TRUE; 112 | } 113 | 114 | function _init_data() { 115 | $this->load->helper('file'); 116 | $success = TRUE; 117 | $path = APPPATH . 'sql/data'; 118 | $files = get_filenames($path); 119 | foreach($files as $file) { 120 | if( ! strpos($file, '.csv')) 121 | { 122 | continue; 123 | } 124 | $class = str_ireplace('.csv', '', $file); 125 | $this->_message("Importing data for $class "); 126 | $object = new $class(); 127 | $object->load_extension('csv'); 128 | $num = $object->csv_import($path . '/' . $file, '', TRUE, array($this, '_save_object')); 129 | $n = ($num == 1) ? $class : plural($class); 130 | echo(" $num $n were imported."); 131 | } 132 | 133 | return $success; 134 | } 135 | 136 | function _save_object($obj) { 137 | if(!$obj->save()) 138 | { 139 | $this->_message('Errors: ', ''); 140 | return FALSE; 141 | } 142 | $this->_message('.', ''); 143 | return TRUE; 144 | } 145 | 146 | function _message($msg, $lb = '
') { 147 | echo($lb . $msg); 148 | ob_flush(); 149 | flush(); 150 | } 151 | 152 | /** 153 | * Allows the creation of an Administrator 154 | * 155 | */ 156 | function init($save = FALSE) { 157 | $first_time = $this->session->userdata('first_time'); 158 | if( ! $first_time) { 159 | show_error('This page can only be accessed the first time.'); 160 | } 161 | $user = new User(); 162 | 163 | if($save) 164 | { 165 | $user->trans_start(); 166 | $user->from_array($_POST, array('name', 'email', 'username', 'password', 'confirm_password')); 167 | $group = new Group(); 168 | $group->get_by_id(1); 169 | if($user->save($group)) { 170 | $user->password = $this->input->post('password'); 171 | if(!$this->login_manager->process_login($user)) { 172 | show_error('Errors:
' . var_export($user->error, TRUE) . '
'); 173 | } 174 | $this->session->unset_userdata('first_time'); 175 | $user->trans_complete(); 176 | redirect('welcome'); 177 | } 178 | } 179 | 180 | $user->load_extension('htmlform'); 181 | 182 | // ID is not included because it is not necessary 183 | $form_fields = array( 184 | 'Contact Information' => 'section', 185 | 'name' => array( 186 | 'label' => 'Your Name' 187 | ), 188 | 'email', 189 | 'Login Information' => 'section', 190 | 'username', 191 | 'password', 192 | 'confirm_password' 193 | ); 194 | 195 | $this->load->view('template_header', array('title' => 'Set Up Your Account', 'section' => 'admin')); 196 | $this->load->view('admin/init', array('user' => $user, 'form_fields' => $form_fields)); 197 | $this->load->view('template_footer'); 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /examples/application/controllers/login.php: -------------------------------------------------------------------------------- 1 | load->library('login_manager', array('autologin' => FALSE)); 9 | } 10 | 11 | function index() 12 | { 13 | $user = $this->login_manager->get_user(); 14 | if($user !== FALSE) 15 | { 16 | // already logged in, redirect to welcome page 17 | redirect('welcome'); 18 | } 19 | // Create a user to store the login validation 20 | $user = new User(); 21 | if($this->input->post('username') !== FALSE) 22 | { 23 | // A login was attempted, load the user data 24 | $user->from_array($_POST, array('username', 'password')); 25 | // get the result of the login request 26 | $login_redirect = $this->login_manager->process_login($user); 27 | if($login_redirect) 28 | { 29 | if($login_redirect === TRUE) 30 | { 31 | // if the result was simply TRUE, redirect to the welcome page. 32 | redirect('welcome'); 33 | } 34 | else 35 | { 36 | // otherwise, redirect to the stored page that was last accessed. 37 | redirect($login_redirect); 38 | } 39 | } 40 | } 41 | 42 | $user->load_extension('htmlform'); 43 | 44 | $this->output->enable_profiler(TRUE); 45 | $this->load->view('template_header', array('title' => 'Login', 'hide_nav' => TRUE)); 46 | $this->load->view('login', array('user' => $user)); 47 | $this->load->view('template_footer'); 48 | } 49 | } 50 | 51 | /* End of file login.php */ 52 | /* Location: ./system/application/controllers/login.php */ -------------------------------------------------------------------------------- /examples/application/controllers/logout.php: -------------------------------------------------------------------------------- 1 | load->library('login_manager', array('autologin' => FALSE)); 9 | } 10 | 11 | function index() 12 | { 13 | $this->login_manager->logout(); 14 | redirect('login'); 15 | } 16 | } 17 | 18 | /* End of file login.php */ 19 | /* Location: ./system/application/controllers/login.php */ -------------------------------------------------------------------------------- /examples/application/controllers/users.php: -------------------------------------------------------------------------------- 1 | load->library('login_manager', array('required_group' => 1)); 10 | } 11 | 12 | function index() 13 | { 14 | $users = new User(); 15 | $users->include_related('group', 'name'); 16 | $bug = $users->bug; 17 | $bug 18 | ->select_func('COUNT', '*', 'count') 19 | ->where_related_status('closed', FALSE) 20 | ->where_related('user', 'id', '${parent}.id'); 21 | $users->select_subquery($bug, 'bug_count'); 22 | $users->get_iterated(); 23 | 24 | $this->output->enable_profiler(TRUE); 25 | $this->load->view('template_header', array('title' => 'Users', 'section' => 'admin')); 26 | $this->load->view('users/index', array('users' => $users)); 27 | $this->load->view('template_footer'); 28 | 29 | } 30 | 31 | function add($save = FALSE) 32 | { 33 | $this->edit($save); 34 | } 35 | 36 | function edit($id = -1) 37 | { 38 | $this->output->enable_profiler(TRUE); 39 | 40 | // Create User Object 41 | $user = new User(); 42 | 43 | if($id == 'save') 44 | { 45 | // Try to save the user 46 | $id = $this->input->post('id'); 47 | $this->_get_user($user, $id); 48 | 49 | $user->trans_start(); 50 | 51 | // Only add the passwords in if they aren't empty 52 | // New users start with blank passwords, so they will get an error automatically. 53 | if( ! empty($_POST['password'])) 54 | { 55 | $user->from_array($_POST, array('password', 'confirm_password')); 56 | } 57 | 58 | // Load and save the reset of the data at once 59 | // The passwords saved above are already stored. 60 | $success = $user->from_array($_POST, array( 61 | 'name', 62 | 'email', 63 | 'username', 64 | 'group' 65 | ), TRUE); // TRUE means save immediately 66 | 67 | // redirect on save 68 | if($success) 69 | { 70 | $user->trans_complete(); 71 | if($id < 1) 72 | { 73 | $this->session->set_flashdata('message', 'The user ' . $user->name . ' was successfully created.'); 74 | } 75 | else 76 | { 77 | $this->session->set_flashdata('message', 'The user ' . $user->name . ' was successfully updated.'); 78 | } 79 | redirect('users'); 80 | } 81 | } 82 | else 83 | { 84 | // load an existing user 85 | $this->_get_user($user, $id); 86 | } 87 | 88 | // Load the HTML Form extension 89 | $user->load_extension('htmlform'); 90 | 91 | // These are the fields to edit. 92 | $form_fields = array( 93 | 'id', 94 | 'Contact Information' => 'section', 95 | 'name', 96 | 'email', 97 | 'Login Information' => 'section', 98 | 'username', 99 | 'password', 100 | 'confirm_password', 101 | 'Access Restrictions' => 'section', 102 | 'group' 103 | ); 104 | 105 | // Set up page text 106 | if($id > 0) 107 | { 108 | $title = 'Edit User'; 109 | $url = 'users/edit/save'; 110 | } 111 | else 112 | { 113 | $title = 'Add User'; 114 | $url = 'users/add/save'; 115 | } 116 | 117 | $this->load->view('template_header', array('title' => $title, 'section' => 'admin')); 118 | $this->load->view('users/edit', array('user' => $user, 'form_fields' => $form_fields, 'url' => $url)); 119 | $this->load->view('template_footer'); 120 | } 121 | 122 | function _get_user($user, $id) 123 | { 124 | if( ! empty($id)) 125 | { 126 | $user->get_by_id($id); 127 | if( ! $user->exists()) 128 | { 129 | show_error('Invalid User ID'); 130 | } 131 | } 132 | } 133 | 134 | function delete($id = 0) 135 | { 136 | $user = new User(); 137 | $user->get_by_id($id); 138 | if( ! $user->exists()) 139 | { 140 | show_error('Invalid User Id'); 141 | } 142 | if($this->input->post('deleteok') !== FALSE) 143 | { 144 | // Delete the user 145 | $name = $user->name; 146 | $user->delete(); 147 | $this->session->set_flashdata('message', 'The user ' . $name . ' was successfully deleted.'); 148 | redirect('users'); 149 | } 150 | else if($this->input->post('cancel') !== FALSE) 151 | { 152 | redirect('users'); 153 | } 154 | 155 | $this->load->view('template_header', array('title' => 'Delete User', 'section' => 'admin')); 156 | $this->load->view('users/delete', array('user' => $user)); 157 | $this->load->view('template_footer'); 158 | } 159 | } 160 | 161 | /* End of file users.php */ 162 | /* Location: ./system/application/controllers/users.php */ -------------------------------------------------------------------------------- /examples/application/controllers/welcome.php: -------------------------------------------------------------------------------- 1 | load->library('login_manager'); 9 | } 10 | 11 | function index() 12 | { 13 | $user = $this->login_manager->get_user(); 14 | // get open bugs, order with most recently updated at the top 15 | $bugs = $user->bugs; 16 | $bugs->where_related_status('closed', FALSE); 17 | $bugs->include_related('status', 'name', TRUE, TRUE); 18 | $bugs = $bugs->order_by('updated', 'DESC')->order_by_related_status('sortorder')->limit(25)->get_iterated(); 19 | 20 | $this->output->enable_profiler(TRUE); 21 | $this->load->view('template_header', array('title' => 'Welcome', 'section' => 'welcome')); 22 | $this->load->view('welcome/index', array('bugs' => $bugs)); 23 | $this->load->view('template_footer'); 24 | } 25 | } 26 | 27 | /* End of file welcome.php */ 28 | /* Location: ./system/application/controllers/welcome.php */ -------------------------------------------------------------------------------- /examples/application/helpers/utilities_helper.php: -------------------------------------------------------------------------------- 1 | "; 11 | } 12 | } -------------------------------------------------------------------------------- /examples/application/language/english/model_bug_lang.php: -------------------------------------------------------------------------------- 1 | CI =& get_instance(); 14 | $this->session =& $this->CI->session; 15 | 16 | if( ! isset($params['autologin']) || $params['autologin'] !== FALSE) 17 | { 18 | $required_group = -1; 19 | if(isset($params['required_group'])) 20 | { 21 | $required_group = $params['required_group']; 22 | } 23 | $this->check_login($required_group); 24 | } 25 | } 26 | 27 | function check_login($required_group = -1) 28 | { 29 | // Special auto-setup routine 30 | if( ! $this->CI->db->table_exists('users')) 31 | { 32 | redirect('admin/reset_warning'); 33 | } 34 | else 35 | { 36 | // see if there are any users in the system 37 | $u = new User(); 38 | if($u->count() == 0) 39 | { 40 | redirect('admin/init'); 41 | } 42 | } 43 | // if not logged in, automatically redirect 44 | $u = $this->get_user(); 45 | if($u === FALSE) 46 | { 47 | $this->session->set_userdata('login_redirect', uri_string()); 48 | redirect('login'); 49 | } 50 | if($required_group > 0) 51 | { 52 | if($u->group->id > $required_group) 53 | { 54 | show_error('You do not have access to this section.'); 55 | } 56 | } 57 | } 58 | 59 | /** 60 | * process_login 61 | * Validates that a username and password are correct. 62 | * 63 | * @param object $user The user containing the login information. 64 | * @return FALSE if invalid, TRUE or a redirect string if valid. 65 | */ 66 | function process_login($user) 67 | { 68 | // attempt the login 69 | $success = $user->login(); 70 | if($success) 71 | { 72 | // store the userid if the login was successful 73 | $this->session->set_userdata('logged_in_id', $user->id); 74 | // store the user for this request 75 | $this->logged_in_user = $user; 76 | // if a redirect is necessary, return it. 77 | $redirect = $this->session->userdata('login_redirect'); 78 | if( ! empty($redirect)) 79 | { 80 | $success = $redirect; 81 | } 82 | } 83 | return $success; 84 | } 85 | 86 | function logout() 87 | { 88 | $this->session->sess_destroy(); 89 | $this->logged_in_user = NULL; 90 | } 91 | 92 | function get_user() 93 | { 94 | if(is_null($this->logged_in_user)) 95 | { 96 | if( ! $this->CI->db->table_exists('users')) 97 | { 98 | return FALSE; 99 | } 100 | $id = $this->session->userdata('logged_in_id'); 101 | if(is_numeric($id)) 102 | { 103 | $u = new User(); 104 | $u->get_by_id($id); 105 | if($u->exists()) { 106 | $u->group->get(); 107 | $this->logged_in_user = $u; 108 | return $this->logged_in_user; 109 | } 110 | } 111 | return FALSE; 112 | } 113 | else 114 | { 115 | return $this->logged_in_user; 116 | } 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /examples/application/models/bug.php: -------------------------------------------------------------------------------- 1 | array( 23 | 'class' => 'user', 24 | 'other_field' => 'created_bug' 25 | ), 26 | // The editor of this bug 27 | 'editor' => array( 28 | 'class' => 'user', 29 | 'other_field' => 'edited_bug' 30 | ), 31 | // Keep track of this bug's status 32 | 'status' 33 | ); 34 | 35 | // Insert related models that Bug can have more than one of. 36 | public $has_many = array( 37 | // users assigned to this bug 38 | 'user', 39 | // Other Bugs that depend on this Bug 40 | 'dependent' => array( 41 | 'class' => 'bug', 42 | 'other_field' => 'dependency' 43 | ), 44 | // Other Bugs that this Bug depends on 45 | 'dependency' => array( 46 | 'class' => 'bug', 47 | 'other_field' => 'dependent' 48 | ), 49 | // categories for this Bug 50 | 'category' 51 | ); 52 | 53 | // -------------------------------------------------------------------- 54 | // Validation 55 | // -------------------------------------------------------------------- 56 | 57 | public $validation = array( 58 | 'title' => array( 59 | 'rules' => array('required', 'trim', 'max_length' => 100) 60 | ), 61 | 'description' => array( 62 | 'rules' => array('required', 'xss_clean'), 63 | 'type' => 'textarea' 64 | ), 65 | 'priority' => array( 66 | 'rules' => array('required', 'integer', 'min_size' => 0, 'max_size' => 3), 67 | 'get_rules' => array('intval'), 68 | 'type' => 'dropdown', 69 | 'values' => array( 70 | '0' => 'None', 71 | '1' => 'Low', 72 | '2' => 'Medium', 73 | '3' => 'High' 74 | ) 75 | ), 76 | 'creator' => array( 77 | 'rules' => array('required') 78 | ), 79 | 'editor' => array( 80 | 'rules' => array('required') 81 | ), 82 | 'status' => array( 83 | 'rules' => array('required') 84 | ) 85 | ); 86 | 87 | // -------------------------------------------------------------------- 88 | 89 | public function get_priority() 90 | { 91 | $p = $this->priority; 92 | if( ! is_numeric($p)) 93 | { 94 | $p = 0; 95 | } 96 | return $this->validation['priority']['values'][$p]; 97 | } 98 | } 99 | 100 | /* End of file bug.php */ 101 | /* Location: ./application/models/bug.php */ 102 | -------------------------------------------------------------------------------- /examples/application/models/category.php: -------------------------------------------------------------------------------- 1 | array( 26 | 'rules' => array('required', 'trim', 'unique', 'max_length' => 40) 27 | ) 28 | ); 29 | 30 | // Default to ordering by name 31 | public $default_order_by = array('name'); 32 | 33 | // -------------------------------------------------------------------- 34 | 35 | /** 36 | * Returns the name of this status. 37 | * @return $this->name 38 | */ 39 | function __toString() 40 | { 41 | return empty($this->name) ? $this->localize_label('unset') : $this->name; 42 | } 43 | } 44 | 45 | /* End of file category.php */ 46 | /* Location: ./application/models/category.php */ -------------------------------------------------------------------------------- /examples/application/models/comment.php: -------------------------------------------------------------------------------- 1 | array( 31 | 'rules' => array('required') 32 | ), 33 | // Bug is required 34 | 'bug' => array( 35 | 'rules' => array('required') 36 | ), 37 | // User is required 38 | 'user' => array( 39 | 'rules' => array('required') 40 | ) 41 | ); 42 | 43 | // Default to ordering by updated 44 | public $default_order_by = array('updated'); 45 | 46 | } 47 | 48 | /* End of file comment.php */ 49 | /* Location: ./application/models/comment.php */ -------------------------------------------------------------------------------- /examples/application/models/group.php: -------------------------------------------------------------------------------- 1 | array( 26 | 'rules' => array('required', 'trim', 'unique', 'min_length' => 3, 'max_length' => 20) 27 | ) 28 | ); 29 | 30 | // Default to ordering by name 31 | public $default_order_by = array('id' => 'desc'); 32 | 33 | /** 34 | * Returns the name of this status. 35 | * @return $this->name 36 | */ 37 | function __toString() 38 | { 39 | return empty($this->name) ? $this->localize_label('unset') : $this->name; 40 | } 41 | 42 | // -------------------------------------------------------------------- 43 | 44 | /** 45 | * This method is provided for the htmlform extension. 46 | * It is used to prevent logged-in users from being able to accidentally 47 | * convert themselves away from being an admin. 48 | * 49 | * @param object $object 50 | * @param object $field 51 | * @return 52 | */ 53 | function get_htmlform_list($object, $field) 54 | { 55 | if($object->model == 'user') 56 | { 57 | // limit the items if the user is the logged-in user 58 | $CI =& get_instance(); 59 | if($CI->login_manager->get_user()->id == $object->id) 60 | { 61 | $this->get_by_id(1); 62 | return; 63 | } 64 | } 65 | $this->get_iterated(); 66 | } 67 | } 68 | 69 | /* End of file group.php */ 70 | /* Location: ./application/models/group.php */ -------------------------------------------------------------------------------- /examples/application/models/status.php: -------------------------------------------------------------------------------- 1 | statuses 15 | public $model = 'status'; 16 | public $table = 'statuses'; 17 | 18 | // -------------------------------------------------------------------- 19 | // Relationships 20 | // -------------------------------------------------------------------- 21 | 22 | public $has_many = array('bug'); 23 | 24 | // -------------------------------------------------------------------- 25 | // Validation 26 | // -------------------------------------------------------------------- 27 | 28 | public $validation = array( 29 | 'name' => array( 30 | 'rules' => array('required', 'trim', 'unique', 'max_length' => 40) 31 | ), 32 | 'closed' => array( 33 | 'rules' => array('boolean'), 34 | 'type' => 'checkbox' 35 | ) 36 | ); 37 | 38 | // Default to ordering by sortorder 39 | public $default_order_by = array('sortorder'); 40 | 41 | // -------------------------------------------------------------------- 42 | 43 | /** 44 | * Returns the name of this status. 45 | * @return $this->name 46 | */ 47 | function __toString() 48 | { 49 | return empty($this->name) ? $this->localize_label('unset') : $this->name; 50 | } 51 | } 52 | 53 | /* End of file status.php */ 54 | /* Location: ./application/models/status.php */ -------------------------------------------------------------------------------- /examples/application/models/user.php: -------------------------------------------------------------------------------- 1 | array( 25 | 'class' => 'bug', 26 | 'other_field' => 'creator' 27 | ), 28 | // bugs edited by this user 29 | 'edited_bug' => array( 30 | 'class' => 'bug', 31 | 'other_field' => 'editor' 32 | ), 33 | // bugs assigned to this user 34 | 'bug' 35 | ); 36 | 37 | // -------------------------------------------------------------------- 38 | // Validation 39 | // -------------------------------------------------------------------- 40 | 41 | public $validation = array( 42 | 'name' => array( 43 | 'rules' => array('required', 'trim', 'unique', 'max_length' => 100) 44 | ), 45 | 'email' => array( 46 | 'rules' => array('required', 'trim', 'unique', 'valid_email') 47 | ), 48 | 'username' => array( 49 | 'rules' => array('required', 'trim', 'unique', 'alpha_dash', 'min_length' => 3, 'max_length' => 20) 50 | ), 51 | 'password' => array( 52 | 'rules' => array('required', 'trim', 'min_length' => 3, 'max_length' => 40, 'encrypt'), 53 | 'type' => 'password' 54 | ), 55 | 'confirm_password' => array( 56 | 'rules' => array('required', 'encrypt', 'matches' => 'password', 'min_length' => 3, 'max_length' => 40), 57 | 'type' => 'password' 58 | ), 59 | 'group' => array( 60 | 'rules' => array('required') 61 | ) 62 | ); 63 | 64 | // Default to ordering by name 65 | public $default_order_by = array('name'); 66 | 67 | // -------------------------------------------------------------------- 68 | 69 | function __toString() 70 | { 71 | return empty($this->name) ? $this->localize_label('newuser') : $this->name; 72 | } 73 | 74 | // -------------------------------------------------------------------- 75 | 76 | /** 77 | * Returns an array list of all users that can have bugs assigned 78 | * to them. 79 | * 80 | * @return $this for chaining 81 | */ 82 | function get_assignable() 83 | { 84 | return $this->where_in_related_group('id', array(1, 2))->get(); 85 | } 86 | 87 | // -------------------------------------------------------------------- 88 | 89 | /** 90 | * Login 91 | * 92 | * Authenticates a user for logging in. 93 | * 94 | * @access public 95 | * @return bool 96 | */ 97 | function login() 98 | { 99 | // backup username for invalid logins 100 | $uname = $this->username; 101 | 102 | // Create a temporary user object 103 | $u = new User(); 104 | 105 | // Get this users stored record via their username 106 | $u->where('username', $uname)->get(); 107 | 108 | // Give this user their stored salt 109 | $this->salt = $u->salt; 110 | 111 | // Validate and get this user by their property values, 112 | // this will see the 'encrypt' validation run, encrypting the password with the salt 113 | $this->validate()->get(); 114 | 115 | // If the username and encrypted password matched a record in the database, 116 | // this user object would be fully populated, complete with their ID. 117 | 118 | // If there was no matching record, this user would be completely cleared so their id would be empty. 119 | if ($this->exists()) 120 | { 121 | // Login succeeded 122 | return TRUE; 123 | } 124 | else 125 | { 126 | // Login failed, so set a custom error message 127 | $this->error_message('login', $this->localize_label('error_login')); 128 | 129 | // restore username for login field 130 | $this->username = $uname; 131 | 132 | return FALSE; 133 | } 134 | } 135 | 136 | // -------------------------------------------------------------------- 137 | 138 | /** 139 | * Encrypt (prep) 140 | * 141 | * Encrypts this objects password with a random salt. 142 | * 143 | * @access private 144 | * @param string 145 | * @return void 146 | */ 147 | function _encrypt($field) 148 | { 149 | if (!empty($this->{$field})) 150 | { 151 | if (empty($this->salt)) 152 | { 153 | $this->salt = md5(uniqid(rand(), true)); 154 | } 155 | 156 | $this->{$field} = sha1($this->salt . $this->{$field}); 157 | } 158 | } 159 | } 160 | 161 | /* End of file user.php */ 162 | /* Location: ./application/models/user.php */ -------------------------------------------------------------------------------- /examples/application/sql/data/category.csv: -------------------------------------------------------------------------------- 1 | "name" 2 | "Website" 3 | "Application" -------------------------------------------------------------------------------- /examples/application/sql/data/group.csv: -------------------------------------------------------------------------------- 1 | name 2 | Administrators 3 | Users 4 | Reporters -------------------------------------------------------------------------------- /examples/application/sql/data/status.csv: -------------------------------------------------------------------------------- 1 | "name","closed","sortorder" 2 | New,0,1 3 | Unconfirmed,0,2 4 | Confirmed,0,3 5 | In Progress,0,4 6 | Fixed,1,5 7 | "Won't Fix",1,6 8 | Works For Me,1,7 -------------------------------------------------------------------------------- /examples/application/sql/mysql/bugs.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `bugs` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `title` character varying(100) NOT NULL, 4 | `description` text, 5 | `priority` smallint DEFAULT 0 NOT NULL, 6 | `created` DATETIME NULL, 7 | `updated` DATETIME NULL, 8 | `status_id` BIGINT UNSIGNED, 9 | `creator_id` BIGINT UNSIGNED, 10 | `editor_id` BIGINT UNSIGNED, 11 | PRIMARY KEY (`id`) 12 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysql/bugs_categories.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `bugs_categories` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `bug_id` BIGINT UNSIGNED NOT NULL, 4 | `category_id` BIGINT UNSIGNED NOT NULL, 5 | PRIMARY KEY (`id`) 6 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysql/bugs_users.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `bugs_users` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `user_id` BIGINT UNSIGNED, 4 | `bug_id` BIGINT UNSIGNED, 5 | `iscompleted` smallint DEFAULT 0 NOT NULL, 6 | `isowner` smallint DEFAULT 0 NOT NULL, 7 | PRIMARY KEY (`id`) 8 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysql/categories.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `categories` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `name` character varying(40) NOT NULL, 4 | PRIMARY KEY (`id`), 5 | UNIQUE INDEX name (`name` ASC) 6 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysql/comments.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `comments` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `comment` text, 4 | `created` DATETIME NULL, 5 | `updated` DATETIME NULL, 6 | `user_id` BIGINT UNSIGNED, 7 | `bug_id` BIGINT UNSIGNED, 8 | PRIMARY KEY (`id`) 9 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysql/dependencies_dependents.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `dependencies_dependents` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `dependency_id` BIGINT UNSIGNED NOT NULL, 4 | `dependent_id` BIGINT UNSIGNED NOT NULL, 5 | PRIMARY KEY (`id`) 6 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysql/groups.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `groups` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `name` character varying(20) NOT NULL, 4 | PRIMARY KEY (`id`), 5 | UNIQUE INDEX name (`name` ASC) 6 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysql/statuses.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `statuses` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `name` character varying(40) NOT NULL, 4 | `closed` smallint DEFAULT 0 NOT NULL, 5 | `sortorder` BIGINT UNSIGNED DEFAULT 0 NOT NULL, 6 | PRIMARY KEY (`id`), 7 | UNIQUE INDEX name (`name` ASC) 8 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysql/users.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `users` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `name` character varying(100) NOT NULL, 4 | `username` character varying(20) NOT NULL, 5 | `email` character varying(120) NOT NULL, 6 | `password` character(40) NOT NULL, 7 | `salt` character varying(32), 8 | `group_id` BIGINT UNSIGNED, 9 | PRIMARY KEY (`id`), 10 | UNIQUE INDEX username (`username` ASC), 11 | UNIQUE INDEX email (`email` ASC) 12 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysqli/bugs.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `bugs` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `title` character varying(100) NOT NULL, 4 | `description` text, 5 | `priority` smallint DEFAULT 0 NOT NULL, 6 | `created` DATETIME NULL, 7 | `updated` DATETIME NULL, 8 | `status_id` BIGINT UNSIGNED, 9 | `creator_id` BIGINT UNSIGNED, 10 | `editor_id` BIGINT UNSIGNED, 11 | PRIMARY KEY (`id`) 12 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysqli/bugs_categories.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `bugs_categories` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `bug_id` BIGINT UNSIGNED NOT NULL, 4 | `category_id` BIGINT UNSIGNED NOT NULL, 5 | PRIMARY KEY (`id`) 6 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysqli/bugs_users.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `bugs_users` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `user_id` BIGINT UNSIGNED, 4 | `bug_id` BIGINT UNSIGNED, 5 | `iscompleted` smallint DEFAULT 0 NOT NULL, 6 | `isowner` smallint DEFAULT 0 NOT NULL, 7 | PRIMARY KEY (`id`) 8 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysqli/categories.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `categories` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `name` character varying(40) NOT NULL, 4 | PRIMARY KEY (`id`), 5 | UNIQUE INDEX name (`name` ASC) 6 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysqli/comments.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `comments` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `comment` text, 4 | `created` DATETIME NULL, 5 | `updated` DATETIME NULL, 6 | `user_id` BIGINT UNSIGNED, 7 | `bug_id` BIGINT UNSIGNED, 8 | PRIMARY KEY (`id`) 9 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysqli/dependencies_dependents.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `dependencies_dependents` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `dependency_id` BIGINT UNSIGNED NOT NULL, 4 | `dependent_id` BIGINT UNSIGNED NOT NULL, 5 | PRIMARY KEY (`id`) 6 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysqli/groups.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `groups` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `name` character varying(20) NOT NULL, 4 | PRIMARY KEY (`id`), 5 | UNIQUE INDEX name (`name` ASC) 6 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysqli/statuses.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `statuses` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `name` character varying(40) NOT NULL, 4 | `closed` smallint DEFAULT 0 NOT NULL, 5 | `sortorder` BIGINT UNSIGNED DEFAULT 0 NOT NULL, 6 | PRIMARY KEY (`id`), 7 | UNIQUE INDEX name (`name` ASC) 8 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/mysqli/users.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `users` ( 2 | `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, 3 | `name` character varying(100) NOT NULL, 4 | `username` character varying(20) NOT NULL, 5 | `email` character varying(120) NOT NULL, 6 | `password` character(40) NOT NULL, 7 | `salt` character varying(32), 8 | `group_id` BIGINT UNSIGNED, 9 | PRIMARY KEY (`id`), 10 | UNIQUE INDEX username (`username` ASC), 11 | UNIQUE INDEX email (`email` ASC) 12 | ) ENGINE = InnoDB; -------------------------------------------------------------------------------- /examples/application/sql/postgre/bugs.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE "bugs" ( 2 | "id" serial NOT NULL PRIMARY KEY, 3 | "title" character varying(100) NOT NULL, 4 | "description" text, 5 | "priority" smallint DEFAULT 0 NOT NULL, 6 | "created" timestamp with time zone DEFAULT now() NOT NULL, 7 | "updated" timestamp with time zone DEFAULT now() NOT NULL, 8 | "status_id" integer, 9 | "creator_id" integer, 10 | "editor_id" integer 11 | ); -------------------------------------------------------------------------------- /examples/application/sql/postgre/bugs_categories.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE "bugs_categories" ( 2 | "id" serial NOT NULL PRIMARY KEY, 3 | "bug_id" integer NOT NULL, 4 | "category_id" integer NOT NULL 5 | ); -------------------------------------------------------------------------------- /examples/application/sql/postgre/bugs_users.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE "bugs_users" ( 2 | "id" serial NOT NULL PRIMARY KEY, 3 | "user_id" integer, 4 | "bug_id" integer, 5 | "iscompleted" smallint DEFAULT 0 NOT NULL, 6 | "isowner" smallint DEFAULT 0 NOT NULL 7 | ); -------------------------------------------------------------------------------- /examples/application/sql/postgre/categories.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE "categories" ( 2 | "id" serial NOT NULL PRIMARY KEY, 3 | "name" character varying(40) NOT NULL UNIQUE 4 | ); -------------------------------------------------------------------------------- /examples/application/sql/postgre/comments.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE "comments" ( 2 | "id" serial NOT NULL PRIMARY KEY, 3 | "comment" text, 4 | "created" timestamp with time zone DEFAULT now() NOT NULL, 5 | "updated" timestamp with time zone DEFAULT now() NOT NULL, 6 | "user_id" integer, 7 | "bug_id" integer 8 | ); -------------------------------------------------------------------------------- /examples/application/sql/postgre/dependencies_dependents.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE "dependencies_dependents" ( 2 | "id" serial NOT NULL PRIMARY KEY, 3 | "dependency_id" integer NOT NULL, 4 | "dependent_id" integer NOT NULL 5 | ); -------------------------------------------------------------------------------- /examples/application/sql/postgre/groups.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE "groups" ( 2 | "id" serial NOT NULL PRIMARY KEY, 3 | "name" character varying(20) NOT NULL UNIQUE 4 | ); -------------------------------------------------------------------------------- /examples/application/sql/postgre/statuses.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE "statuses" ( 2 | "id" serial NOT NULL PRIMARY KEY, 3 | "name" character varying(40) NOT NULL, 4 | "closed" smallint DEFAULT 0 NOT NULL, 5 | "sortorder" integer DEFAULT 0 NOT NULL 6 | ); -------------------------------------------------------------------------------- /examples/application/sql/postgre/users.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE "users" ( 2 | "id" serial NOT NULL PRIMARY KEY, 3 | "name" character varying(100) NOT NULL, 4 | "username" character varying(20) NOT NULL UNIQUE, 5 | "email" character varying(120) NOT NULL UNIQUE, 6 | "password" character(40) NOT NULL, 7 | "salt" character varying(32), 8 | "group_id" integer 9 | ); -------------------------------------------------------------------------------- /examples/application/sql/tabledroplist.txt: -------------------------------------------------------------------------------- 1 | # Join Tables 2 | bugs_categories 3 | bugs_users 4 | dependencies_dependents 5 | 6 | # Model Tables 7 | bugs 8 | categories 9 | comments 10 | groups 11 | statuses 12 | users -------------------------------------------------------------------------------- /examples/application/views/admin/index.php: -------------------------------------------------------------------------------- 1 |

Manage User Accounts
2 | Add, edit, and delete users from this section.

3 | 4 | load->view('admin/reset'); 7 | 8 | ?> 9 | -------------------------------------------------------------------------------- /examples/application/views/admin/init.php: -------------------------------------------------------------------------------- 1 |

Create an administrative account for yourself.

2 | render_form( 5 | $form_fields, 6 | 'admin/init/save'); 7 | 8 | ?> 9 | -------------------------------------------------------------------------------- /examples/application/views/admin/reset.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

The database has not yet been created. Please click on the link below if you want to have the database automatically created.

4 | 5 | 6 |

7 | Click here to automatically the database. 8 |
9 | This will be created on the db->dbdriver; ?> database db->database; ?>”. 10 |
11 | Procede with caution: Any existing Squash Bug Tracker tables in this database will be erased! 12 |

13 | -------------------------------------------------------------------------------- /examples/application/views/bugs/edit.php: -------------------------------------------------------------------------------- 1 | render_form($form_fields, $url); 4 | 5 | ?> -------------------------------------------------------------------------------- /examples/application/views/bugs/list.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | result_count() < 1): ?> 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 26 | 27 | 28 | 29 |
IDTitleStatusOptions
No Bugs Found.
id; ?>title); ?>status->name); ?> 22 | 23 |   24 | 25 |
30 | -------------------------------------------------------------------------------- /examples/application/views/bugs/paging.php: -------------------------------------------------------------------------------- 1 | paged; 8 | 9 | ?>
10 | has_previous): 11 | ?><< First  << First  < Previous  ·  Found total_rows; ?> Total Bugtotal_rows != 1 ? 's' : ''; ?>  ·  has_next): 20 | ?>  Last >>Next >  Last >> 26 |
27 | -------------------------------------------------------------------------------- /examples/application/views/bugs/search.php: -------------------------------------------------------------------------------- 1 |
2 |

Search

3 | render_form($form_fields, $url, array('save_button' => 'Search', 'reset_button' => TRUE)); 6 | 7 | ?> 8 |
9 | 10 |
11 | load->view('bugs/paging', array('bugs' => $bugs), TRUE); 17 | 18 | echo($paging); 19 | 20 | $this->load->view('bugs/list', array('bugs' => $bugs)); 21 | 22 | echo($paging); 23 | } 24 | ?> 25 | 26 |
27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/application/views/bugs/view.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
Status: status->name); ?> Edit this Bug Edit this Bug
4 |
description); ?>
5 |
6 | 7 |
8 |

Assigned Users

9 |
    10 | users->result_count() == 0): ?> 11 |
  • No users assigned to this bug.
  • 12 | 13 | users as $user): ?> 14 |
  • name; ?>
  • 15 | 16 | 17 |
18 | categories->result_count() > 0): ?> 19 |

Categories:

20 |
    21 | categories as $cat): ?> 22 |
  • name; ?>
  • 23 | 24 |
25 | 26 |

Other

27 |
    28 |
  • Priority: get_priority(); ?>
  • 29 |
  • Reported By: creator->name); ?>
  • 30 |
  • Date Created: created)); ?>
  • 31 |
  • Last Edited By: editor->name); ?>
  • 32 |
  • Last Updated: updated)); ?>
  • 33 |
34 |
35 |
36 | 37 | -------------------------------------------------------------------------------- /examples/application/views/login.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Welcome to the Squash Bug Tracker. Please log in.

4 | render_form(array( 7 | 'username', 8 | 'password' 9 | ), 10 | 'login', 11 | array( 12 | 'save_button' => 'Log In', 13 | 'reset_button' => 'Clear' 14 | ) 15 | ); 16 | 17 | ?> 18 |
19 |
-------------------------------------------------------------------------------- /examples/application/views/template_footer.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /examples/application/views/template_header.php: -------------------------------------------------------------------------------- 1 | array( 20 | 'name' => 'Welcome', 21 | 'url' => 'welcome' 22 | ), 23 | 'search' => array( 24 | 'name' => 'Find Bugs', 25 | 'url' => 'bugs/search' 26 | ), 27 | 'report' => array( 28 | 'name' => 'Report a Bug', 29 | 'url' => 'bugs/report' 30 | ), 31 | 'admin' => array( 32 | 'name' => 'Admin', 33 | 'url' => 'admin', 34 | 'restrict' => 1 35 | ), 36 | 'logout' => array( 37 | 'name' => 'Log Out', 38 | 'url' => 'logout' 39 | ) 40 | ); 41 | 42 | $user = isset($this->login_manager) ? $this->login_manager->get_user() : FALSE; 43 | 44 | if( ! isset($message)) 45 | { 46 | $message = $this->session->flashdata('message'); 47 | } 48 | 49 | ?> 50 | 51 | 52 | 53 | <?php echo $page_title; ?>Squash Bug Tracker 54 | 55 | 56 | 57 | 61 | 62 |
63 |

Squash Bug Tracker

64 | 65 | 84 | 85 |
Welcome, name); ?>
86 | 87 | 88 |
89 | 90 | 91 | 92 | 93 |

94 | 95 | 96 | 97 |
98 | 99 | 100 | 101 |
102 | 103 | -------------------------------------------------------------------------------- /examples/application/views/users/delete.php: -------------------------------------------------------------------------------- 1 |

Are you sure you want to delete the user name); ?>?

2 |
3 |

4 | 5 | 6 |

7 |
8 | -------------------------------------------------------------------------------- /examples/application/views/users/edit.php: -------------------------------------------------------------------------------- 1 | render_form($form_fields, $url); 4 | 5 | ?> -------------------------------------------------------------------------------- /examples/application/views/users/index.php: -------------------------------------------------------------------------------- 1 |

2 | Add a New User Add a New User 3 |

4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 22 | 23 | 24 | 25 | 29 | 30 | 31 |
NameOpen BugsGroupOptions
name); ?>id == $this->login_manager->get_user()->id) { 19 | echo(' *'); 20 | } 21 | ?>bug_count; ?>group_name); ?>id != $this->login_manager->get_user()->id) { 27 | ?>  
32 |

* My Account

33 | 34 |

Back to Admin Console

35 | -------------------------------------------------------------------------------- /examples/application/views/welcome/index.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 |

Welcome to the Squash Bug Tracker.

5 |
6 | 7 |
8 |

My Open Bugs (Most Recently Updated First)

9 |
10 | load->view('bugs/list', array('bugs' => $bugs)); 12 | ?> 13 |
14 |
15 | 16 |
17 | 18 | -------------------------------------------------------------------------------- /examples/css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: 16px; 3 | font-family: "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", sans-serif; 4 | padding: 0; 5 | margin: 0; 6 | background: #F2F2F2 url(../img/bg.png) repeat-x left top; 7 | } 8 | 9 | a:link, 10 | a:visited { 11 | color: #004C2C; 12 | text-decoration: none; 13 | } 14 | a:active, 15 | a:hover { 16 | color: #00905A; 17 | } 18 | 19 | a img { 20 | border: none; 21 | vertical-align: middle; 22 | } 23 | a:link img, a:visited img { 24 | opacity: .8; 25 | } 26 | a:hover img, a:active img { 27 | opacity: 1; 28 | } 29 | 30 | .header { 31 | height: 80px; 32 | } 33 | 34 | h1 { 35 | position: absolute; 36 | z-index: -500; 37 | background: transparent url(../img/header-logo.jpg) no-repeat left top; 38 | top: 0; 39 | left: 0; 40 | width: 240px; 41 | height: 94px; 42 | margin: 0; 43 | padding: 0; 44 | font-size: 1px; 45 | text-indent: -9999px; 46 | } 47 | 48 | .nav ul { 49 | margin: 0; 50 | padding: 56px 0 0 0; 51 | text-align: center; 52 | height: 24px; 53 | } 54 | .nav li { 55 | display: inline-block; 56 | list-style: none; 57 | margin: 0 .25em; 58 | height: 24px; 59 | } 60 | .nav li a { 61 | display: inline-block; 62 | padding: 3px 6px 1px; 63 | height: 18px; 64 | border: 1px solid #C9D0C6; 65 | border-bottom-color: #C8D1C6; 66 | background-color: #E7E9E5; 67 | font-size: 14px; 68 | color: #757F76; 69 | text-decoration: none; 70 | } 71 | .nav li a:hover { 72 | color: #333; 73 | border-color: #C8D1C6; 74 | background-color: #ECEEEB; 75 | } 76 | .nav li.selected a { 77 | background: White; 78 | border-color: #C8D1C6; 79 | border-bottom-color: White; 80 | color: #333; 81 | } 82 | .nav li.selected a:hover { 83 | color: #757F76; 84 | } 85 | 86 | .header .username { 87 | float: right; 88 | font-size: .75em; 89 | padding: .85em 1.5em 0 0; 90 | color: #666; 91 | } 92 | 93 | h2 { 94 | font-size: 1em; 95 | font-weight: bold; 96 | margin: 0; 97 | padding: .5em 1em .5em 4em; 98 | color: #333; 99 | border-bottom: 1px solid #F8F8F8; 100 | } 101 | 102 | #page_message { 103 | margin: .5em; 104 | padding: .5em; 105 | background: #FFF9D1; 106 | border: 1px solid #D8A969; 107 | color: #333; 108 | } 109 | 110 | .content { 111 | padding: .5em 1.5em 1em; 112 | background-color: White; 113 | font-size: .85em; 114 | } 115 | 116 | .content .box { 117 | background-color: #E7E9E5; 118 | border: 1px outset #C8D1C6; 119 | } 120 | .content .box h3 { 121 | margin: 0; 122 | padding: 4px; 123 | font-size: .75em; 124 | color: #333; 125 | background-color: #C8D1C6; 126 | border-top: 1px solid #E7E9E5; 127 | } 128 | .content .box .boxContent { 129 | padding: .5em 1em; 130 | } 131 | 132 | .error { 133 | font-weight: bold; 134 | color: Maroon; 135 | } 136 | 137 | table.form .section th { 138 | text-align: left; 139 | padding-top: 1em; 140 | font-weight: bold; 141 | font-size: 1.1em; 142 | padding-bototm: .1em; 143 | margin-bottom: .1em; 144 | border-bottom: 1px solid #F2F2F2; 145 | } 146 | table.form td { 147 | padding-top: .5em; 148 | } 149 | table.form td.label { 150 | font-weight: normal; 151 | text-align: right; 152 | padding-right: .5em; 153 | vertical-align: top; 154 | } 155 | table.form tr.buttons td { 156 | text-align: center; 157 | } 158 | table.form tr.buttons td input { 159 | min-width: 8em; 160 | } 161 | table.form tr.required td.label { 162 | font-weight: bold; 163 | } 164 | 165 | .clear { 166 | display: block; 167 | clear: both; 168 | color: White; 169 | text-indent: -9999px; 170 | } 171 | 172 | 173 | .login { 174 | width: 30em; 175 | margin: 0 auto; 176 | } 177 | 178 | 179 | table.bugs, 180 | table.users { 181 | width: 100%; 182 | border-collapse: collapse; 183 | table-layout: fixed; 184 | } 185 | table.bugs th, 186 | table.users th { 187 | text-align: left; 188 | border-bottom: 1px solid #C8D1C6; 189 | padding: .25em; 190 | } 191 | table.bugs td, 192 | table.users td { 193 | padding: .25em .5em;; 194 | white-space: nowrap; 195 | } 196 | table.bugs .id { 197 | text-align: right; 198 | width: 1.5em; 199 | } 200 | table.bugs .title, 201 | table.users .name, 202 | table.users .email { 203 | width: auto; 204 | white-space: nowrap; 205 | overflow: hidden; 206 | text-overflow: ellipsis; 207 | } 208 | table.bugs .status, 209 | table.users .group { 210 | width: 8em; 211 | white-space: nowrap; 212 | overflow: hidden; 213 | text-overflow: ellipsis; 214 | } 215 | table.bugs .buttons, 216 | table.users .buttons { 217 | width: 5.5em; 218 | text-align: center; 219 | } 220 | table.bugs .even, 221 | table.users .even { 222 | background-color: #F2F2F2; 223 | } 224 | 225 | .paging { 226 | text-align: center; 227 | } 228 | .paging .disabled { 229 | color: #999; 230 | } 231 | 232 | /** 233 | * Columns 234 | */ 235 | .columns { 236 | position: relative; 237 | overflow: hidden; 238 | } 239 | .smallRight .colset { 240 | position: relative; 241 | float: left; 242 | right: 35%; 243 | width: 100%; 244 | } 245 | .smallRight .leftcol { 246 | position: relative; 247 | float: left; 248 | width: 63%; 249 | left: 36%; 250 | overflow: hidden; 251 | } 252 | .smallRight .rightcol { 253 | float: left; 254 | position: relative; 255 | width: 34%; 256 | left: 36%; 257 | font-size: .75em; 258 | overflow: hidden; 259 | } 260 | 261 | .searchSection { 262 | width: 28em; 263 | float: left; 264 | margin-right: 1em; 265 | } 266 | 267 | .searchResults { 268 | padding-left: 29.5em; 269 | } 270 | 271 | 272 | .database_setup { 273 | padding-left: 76px; 274 | min-height: 64px; 275 | background: transparent url(../img/icon/64/database.png) no-repeat left top; 276 | } 277 | 278 | .users_setup { 279 | padding-left: 76px; 280 | min-height: 64px; 281 | background: transparent url(../img/icon/64/users.png) no-repeat left top; 282 | } 283 | 284 | 285 | 286 | .legal { 287 | margin: 0 0 1em; 288 | padding: 0; 289 | font-size: .75em; 290 | color: #CCC; 291 | text-align: center; 292 | border-top: 1px solid #C8D1C6; 293 | } 294 | .legal .copyright { 295 | padding-top: 1em; 296 | } 297 | .legal a:link, .legal a:visited { 298 | color: #CCC; 299 | } 300 | .legal .licenseInfo, 301 | .legal .resources { 302 | margin-top: .5em; 303 | } 304 | 305 | #codeigniter_profiler { 306 | background: url(../img/profiler.png) no-repeat left top; 307 | height: 10px; 308 | overflow: hidden; 309 | font-size: .75em; 310 | } 311 | #codeigniter_profiler:hover { 312 | height: auto; 313 | overflow: visible; 314 | } 315 | -------------------------------------------------------------------------------- /examples/img/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/bg.png -------------------------------------------------------------------------------- /examples/img/cc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/cc.png -------------------------------------------------------------------------------- /examples/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/favicon.png -------------------------------------------------------------------------------- /examples/img/header-logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/header-logo.jpg -------------------------------------------------------------------------------- /examples/img/icon/16/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/16/add.png -------------------------------------------------------------------------------- /examples/img/icon/16/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/16/back.png -------------------------------------------------------------------------------- /examples/img/icon/16/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/16/delete.png -------------------------------------------------------------------------------- /examples/img/icon/16/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/16/edit.png -------------------------------------------------------------------------------- /examples/img/icon/16/move_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/16/move_bottom.png -------------------------------------------------------------------------------- /examples/img/icon/16/move_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/16/move_down.png -------------------------------------------------------------------------------- /examples/img/icon/16/move_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/16/move_top.png -------------------------------------------------------------------------------- /examples/img/icon/16/move_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/16/move_up.png -------------------------------------------------------------------------------- /examples/img/icon/16/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/16/search.png -------------------------------------------------------------------------------- /examples/img/icon/16/view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/16/view.png -------------------------------------------------------------------------------- /examples/img/icon/64/categories.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/64/categories.png -------------------------------------------------------------------------------- /examples/img/icon/64/database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/64/database.png -------------------------------------------------------------------------------- /examples/img/icon/64/groups.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/64/groups.png -------------------------------------------------------------------------------- /examples/img/icon/64/statuses.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/64/statuses.png -------------------------------------------------------------------------------- /examples/img/icon/64/users.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/icon/64/users.png -------------------------------------------------------------------------------- /examples/img/profiler.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/examples/img/profiler.png -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010 Harro "WanWizard" Verton 4 | 5 | Continuation of Datamapper DMZ, Copyright (c) 2008-2010 Phil DeJarnett 6 | In turn based heavily on the original DataMapper, Copyright © 2008 Simon Stenhouse 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /manual/images/arrow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/arrow.gif -------------------------------------------------------------------------------- /manual/images/dmz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/dmz.png -------------------------------------------------------------------------------- /manual/images/dmzlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/dmzlogo.png -------------------------------------------------------------------------------- /manual/images/donate_button.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/donate_button.gif -------------------------------------------------------------------------------- /manual/images/download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/download.png -------------------------------------------------------------------------------- /manual/images/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/example.png -------------------------------------------------------------------------------- /manual/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/favicon.png -------------------------------------------------------------------------------- /manual/images/feed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/feed.png -------------------------------------------------------------------------------- /manual/images/nav_bg_darker.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/nav_bg_darker.jpg -------------------------------------------------------------------------------- /manual/images/nav_separator_darker.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/nav_separator_darker.jpg -------------------------------------------------------------------------------- /manual/images/nav_toggle_darker.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/nav_toggle_darker.jpg -------------------------------------------------------------------------------- /manual/images/nestedsets.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/nestedsets.gif -------------------------------------------------------------------------------- /manual/images/notice_icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/notice_icon.jpg -------------------------------------------------------------------------------- /manual/images/searchlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P2GR/datamapper/0fcdb1f9c2fe251439660ba87651056cd46835a4/manual/images/searchlogo.png -------------------------------------------------------------------------------- /manual/js/rot13.js: -------------------------------------------------------------------------------- 1 | /** 2 | * ROT13 3 | * 4 | * ROT13 encryption. 5 | * 6 | * @licence MIT License 7 | * @author stensi 8 | * @link http://stensi.com 9 | */ 10 | var ROT13 = new Class({ 11 | 12 | // implements 13 | Implements: [Options], 14 | 15 | // options 16 | options: { 17 | map: null 18 | }, 19 | 20 | /** 21 | * Constructur - Class.initialize 22 | * 23 | * @param object 24 | * @return void 25 | */ 26 | initialize: function(options) { 27 | 28 | this.setOptions(options); 29 | 30 | if (this.options.map != null) 31 | { 32 | return; 33 | } 34 | 35 | var map = new Array(); 36 | var s = "abcdefghijklmnopqrstuvwxyz"; 37 | 38 | for (i = 0; i < s.length; i++) 39 | { 40 | map[s.charAt(i)] = s.charAt((i + 13) % 26); 41 | } 42 | 43 | for (i = 0; i < s.length; i++) 44 | { 45 | map[s.charAt(i).toUpperCase()] = s.charAt((i + 13) % 26).toUpperCase(); 46 | } 47 | 48 | this.options.map = map; 49 | }, 50 | 51 | convert: function(a) { 52 | var s = ""; 53 | 54 | for (i = 0; i < a.length; i++) 55 | { 56 | var b = a.charAt(i); 57 | s += ((b>='A' && b<='Z') || (b>='a' && b<='z') ? this.options.map[b] : b); 58 | } 59 | 60 | return s; 61 | } 62 | }); 63 | -------------------------------------------------------------------------------- /manual/pages/_template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PAGE_TITLE : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

PAGE_TITLE

54 | 55 |

Brief description of PAGE_TITLE.

56 | 57 |

Important:  This is an important note with EMPHASIS.

58 | 59 | 60 |

Features:

61 | 62 |
    63 |
  • Foo
  • 64 |
  • Bar
  • 65 |
66 | 67 |

Usage Heading

68 | 69 |

Description of using Foo. Highlight variables and filenames in regular text with the <var> tag, and code using the <dfn> tag.

70 | 71 |
 72 | 	$this->load->library('foo');
 73 | 
 74 | 	$this->foo->bar('bat');
 75 | 
76 | 77 | 78 |

Table Preferences

79 | 80 |

Use tables where appropriate for long lists of preferences.

81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 |
PreferenceDefault ValueOptionsDescription
fooFooNoneDescription of foo.
barBarbat, bag, or bakDescription of bar.
105 | 106 |

Foo Function Reference

107 |
108 |

Example Application

109 |

An example can be found in:

110 |

examples/models/status.php

111 |
112 |

$this->foo->bar()

113 | 114 |

Description

115 |
$this->foo->bar('baz')
116 | 117 | 118 | 119 |
120 | 121 | 122 | 123 | 137 | 138 | 139 | 140 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /manual/pages/advancedusage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Get By : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Add Model Path

54 | 55 |

Add Model Path is a static dynamic method that allows you to define alternative file locations for the model autoloader. 56 | When a model is requested the autoloader checks all defined paths for the existence of a models folder. If that exists, it will check if the request model file exists, and if so, it will be loaded.

57 |

Datamapper searches the following locations: 58 |

    59 |
  • The application model directory
  • 60 |
  • The module directories of loaded modules (HMVC & Modular CI)
  • 61 |
  • All defined CodeIgniter packages (CI 2.0+, added with $this->load->add_package_path)
  • 62 |
  • All manually added paths
  • 63 |
64 |

65 |

You can add model search paths to Datamapper manually using the Add Model Path static method:

66 |
 67 | // add the users, groups and admin modules to the model autoloader search path
 68 | Datamapper::add_model_path( array( APPPATH.'modules/users', APPPATH.'modules/groups', APPPATH.'modules/admin' ) );
 69 | 
70 |

Note that this is a global operation, you will have to do this only once per page request, for example in the controlller constructor.

71 | 72 |

 

73 | 74 |
75 | 76 |
77 | 78 | 79 | 80 | 94 | 95 | 96 | 97 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /manual/pages/changelog/1.2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 1.2.x Change Log : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 |

DataMapper ORM

31 |
32 | 33 | 34 | 35 | 36 | 37 | 43 | 44 | 45 |
46 | 47 | 48 |
49 | 50 | 51 | 52 |
53 | 54 | 55 |

1.2.x Change Log

56 | 57 |

For more information on upgrading to the latest release, please see Upgrade Instructions

58 | 59 |

Version 1.2.5

60 |

Release Date: June 15, 2009

61 | 70 | 71 |

Version 1.2.4

72 |

Release Date: June 3, 2009

73 | 81 | 82 | 83 |
84 | 85 | 86 | 87 | 101 | 102 | 103 | 104 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /manual/pages/changelog/1.3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 1.3.x Change Log : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 |

DataMapper ORM

31 |
32 | 33 | 34 | 35 | 36 | 37 | 43 | 44 | 45 |
46 | 47 | 48 |
49 | 50 | 51 | 52 |
53 | 54 | 55 |

1.3.x Change Log

56 | 57 |

For more information on upgrading to the latest release, please see Upgrade Instructions

58 | 59 |

Version 1.3.2

60 |

Release Date: June 29, 2009

61 | 76 | 77 |

Version 1.3.1

78 |

Release Date: June 17, 2009

79 | 101 | 102 |

Version 1.3.0

103 |

Release Date: June 16, 2009

104 | 123 | 124 | 125 |
126 | 127 | 128 | 129 | 143 | 144 | 145 | 146 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /manual/pages/clear.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Clear : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Clear

54 | 55 |

Clear documentation has been moved to the utility methods page.

56 | 57 | 58 |
59 | 60 | 61 | 62 | 76 | 77 | 78 | 79 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /manual/pages/controllers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | DataMapper in Controllers : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

DataMapper in Controllers

54 | 55 |

Here we can finally get to the good stuff! By now you've got your DataMapper models all setup so we can begin using our tables as objects.

56 | 57 |

I wont go into too much detail here as the Functions section of the Table of Contents contains detailed usage instructions on the Get, Save, and Delete functions, as well as others. The Relationships section also has detailed usage instructions for accessing and modifying your relationships between objects.

58 | 59 |

Before you do look at those, you might want to read through the next few sections.

60 | 61 | 62 |
63 | 64 | 65 | 66 | 80 | 81 | 82 | 83 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /manual/pages/deleteall.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Delete All : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Delete All

54 | 55 |

Delete All is used to delete all objects in an objects all list. It is basically quicker than looping through the all list yourself to delete each one. For example:

56 | 57 |
 58 | // Get a number of books from the year 2000
 59 | $b = new Book();
 60 | $b->where('year', 2000)->get();
 61 | 
 62 | // Loop through the all list and delete them one by one
 63 | foreach ($b->all as $book)
 64 | {
 65 |     $book->delete();
 66 | }
 67 | 
68 | 69 |

Instead just do this:

70 |
 71 | $b = new Book();
 72 | $b->where('year', 2000)->get();
 73 | $b->delete_all();
 74 | 
75 | 76 |

This is especially useful for deleting related items.

77 | 78 |

 

79 | 80 |

Truncate

81 | 82 |

Since Delete All will iterate over all objects in an objects all list, it will run a delete query for every record found. While this is very useful if you want to 83 | delete a subset of records in the table, it is very ineffecient when you simply want to delete all records.

84 | 85 |

If that is the goal, just use:

86 |
 87 | $b = new Book();
 88 | $b->truncate();
 89 | 
90 | 91 |

This will delete all records in the books table, reset all in-table-foreign-keys in related tables linking to the books table, and delete all records in relationship tables referenced by the Book model.

92 | 93 |

Note that if your relationship tables are used in multiple many-to-many relations, you should not use this method, as it will also delete all relationships between the other models using the same relationship table!

94 | 95 |
96 | 97 | 98 | 99 | 113 | 114 | 115 | 116 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /manual/pages/deletingrelations.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Deleting Relationships : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Deleting Relationships

54 | 55 |

Read Delete to see how to delete relationships.

56 | 57 | 58 | 59 |
60 | 61 | 62 | 63 | 77 | 78 | 79 | 80 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /manual/pages/examples.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Example Application : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Example Application

54 | 55 |

Included with the download of Datamapper ORM is a simple bug-tracking application. It is not complete (nor is it intended to be), but it has examples of a lot of Datamapper ORM functionality.

56 | 57 |

Setting up the Example Application

58 | 59 |

Follow these instructions to get the examples running on your server:

60 | 61 | 67 | 68 |

Example Highlights

69 | 70 |
71 |

Example Application

72 |

Look for these boxes throughout the documentation for working examples in the example application.

73 |
74 |

These are some highlights from the examples.

75 | 83 | 84 |
85 | 86 | 87 | 88 | 102 | 103 | 104 | 105 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /manual/pages/exists.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Exists : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Exists

54 | 55 |

Exists documentation has been moved to the utility methods page.

56 | 57 | 58 |
59 | 60 | 61 | 62 | 76 | 77 | 78 | 79 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /manual/pages/extensions/simplecache.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Query Caching Methods : Included Extensions : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 |

DataMapper ORM

31 |
32 | 33 | 34 | 35 | 36 | 37 | 43 | 44 | 45 |
46 | 47 | 48 |
49 | 50 | 51 | 52 |
53 | 54 | 55 |

Query Caching Methods (simplecache)

56 |

To enable these methods, add 'simplecache' to DataMapper's config, under 'extensions'.

57 |

Enables the usage of CodeIgniter's simple query caching for large result sets.

58 |

Note that this is different than the start_cache and stop_cache methods, which are only used to cache ActiveRecord queries, and it is also different than the Production Cache, which is used to cache initialization information for models.

59 | 60 |

get_cached(...)

61 | 64 |

Gets the results of the current query. If a cached version is available, it uses that one, otherwise it runs the query and saves it for later. You can pass in any arguments that you would pass in to DataMapper's get method.

65 |

Like CodeIgniter's caching, this method requires that the query always be on the exact same URL, and have the exact same structure. It may or may not improve performance. Please read the CodeIgniter Documentation for more information.

66 | 67 |

General Usage

68 |
 69 | $post = new Post();
 70 | // There are a lot of posts, so cache if possible.
 71 | $post->get_cached();
 72 | 
73 | 74 |

clear_cache(...)

75 | 78 |

On the next call to get_cached, the cache will be cleared. You can also forcibly clear the cache for a specific URI by passing in the URI segments.

79 | 80 |

General Usage:

81 |
 82 | $should_clear_cache = ? // Look up whether or not this cache needs to be cleared
 83 | if($should_clear_cache)
 84 | {
 85 |     $post->clear_cache();
 86 | }
 87 | $post->get_cached();
 88 | 
89 | 90 |

Clearing the Cache on Save

91 |
 92 | $post->save();
 93 | 
 94 | // Need to clear the caches for large post queries
 95 | $post->clear_cache('welcome');      // index.php/welcome
 96 | $post->clear_cache('posts', 'all'); // index.php/posts/all
 97 | 
98 | 99 | 100 |
101 | 102 | 103 | 104 | 118 | 119 | 120 | 121 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /manual/pages/extensions/translate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Translation Methods : Included Extensions : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 |

DataMapper ORM

31 |
32 | 33 | 34 | 35 | 36 | 37 | 43 | 44 | 45 |
46 | 47 | 48 |
49 | 50 | 51 | 52 |
53 | 54 | 55 |

Translation Methods (translate)

56 |

To enable these methods, add 'translate' to DataMapper's config, under 'extensions'.

57 |

Runs (a selected list of) object properties through CodeIgniters language method so you can store language keys in the database.

58 | 59 |

translate($fields)

60 | 64 | 65 |

Usage

66 |
 67 | $u = new User();
 68 | $u->get_by_id($user_id);
 69 | $u->translate();
 70 | 
71 | 72 |
73 | 74 | 75 | 76 | 90 | 91 | 92 | 93 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /manual/pages/extlist.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Included Extensions : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Included Extensions

54 | 55 |

Datamapper ORM includes the following extensions. To use the features of an extension, simply add the name in the (parentheses) to your extensions list.

56 | 57 |
58 |

Third-Party Extensions

59 |

You may be able to find third-party extensions to Datamapper ORM via this CodeIgniter Wiki Category.

60 |

You can also use share your extensions with others.

61 |
62 | 63 |

Data Conversion Extensions

64 | 76 | 77 |

HTML Generation Extensions

78 | 82 | 83 |

DataBase Utility Extensions

84 | 90 | 91 |
92 | 93 | 94 | 95 | 109 | 110 | 111 | 112 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /manual/pages/license.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | License Agreement : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

License Agreement

54 | 55 |

Copyright © 2010-2011 Harro "WanWizard" Verton

56 |

Copyright © 2009-2010 Phil DeJarnett

57 |

Based on the original DataMapper, Copyright © 2008 Simon Stenhouse

58 |

CodeIgniter is Copyright © 2008-2011 Ellislab, Inc.

59 | 60 |

Permission is hereby granted, free of charge, to any person obtaining a copy 61 | of this software and associated documentation files (the "Software"), to deal 62 | in the Software without restriction, including without limitation the rights 63 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 64 | copies of the Software, and to permit persons to whom the Software is 65 | furnished to do so, subject to the following conditions:

66 | 67 |

The above copyright notice and this permission notice shall be included in 68 | all copies or substantial portions of the Software.

69 | 70 |

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 71 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 72 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 73 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 74 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 75 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 76 | THE SOFTWARE.

77 | 78 | 79 |
80 | 81 | 82 | 83 | 97 | 98 | 99 | 100 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /manual/pages/refreshall.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Refresh All : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Refresh All

54 | 55 |

Refresh All is really only used in one scenario. For example, if you get a number of object, loop through its all list, and delete one or more records, but not all of them. Refresh All will do just that, refresh the all list so the deleted items are removed. We're not able to dynamically remove them from the all list while you're looping through it as that would cause issues with the loop itself. Here's an example of when you'd use refresh_all():

56 | 57 |
 58 | // Get a number of books from the year 2000
 59 | $b = new Book();
 60 | $b->where('year', 2000)->get();
 61 | 
 62 | // Loop through the all list and delete those that are fiction
 63 | foreach ($b as $book)
 64 | {
 65 |     if ($book->fiction)
 66 |     {
 67 |         $book->delete();
 68 |     }
 69 | }
 70 | 
 71 | // Refresh the book objects all list to remove the deleted entries (which are simply empty entries in the all list now)
 72 | $b->refresh_all();
 73 | 
 74 | // Now we can loop through the all list again looking at only existing objects
 75 | foreach ($b as $book)
 76 | {
 77 |     echo $book->name ."<br />";
 78 | }
 79 | 
80 | 81 |

Alternatively, you could instead run your get query again but that will execute a database call whereas Refresh All just removes empty records from the objects all list.

82 | 83 |
84 | 85 | 86 | 87 | 101 | 102 | 103 | 104 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /manual/pages/requirements.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Server Requirements : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Server Requirements

54 | 55 | 65 | 66 |

 

67 | 68 |
69 |

Using PHP older than 5.1.2

70 |

71 | It is possible, by manually modifying the DataMapper library, to get Datamapper ORM to work on PHP older than 5.1.2. 72 | PHP 5.0.0 or newer is still required, and it is not officially supported. 73 |

74 |

Please see this forum post for instructions.

75 |
76 | 77 |
78 |

CodeIgniter 2.0

79 |

Datamapper is tested with the latest CodeIgniter 2.0 (which has not yet been released at this time) from the Bitbucket repository and is proven to work.

80 |

However, until it is released, we can not guarantee it will work with any particular development version.

81 |
82 | 83 |
84 |

Expression Engine

85 |

Please note: Expression Engine is not officially supported.

86 |

Patches and suggestions are welcome, however.

87 |
88 | 89 |
90 |

Using Oracle

91 |

Oracle probably will not work 100% out-of-the-box.

92 |

However, Frank Liu has done some research on how to get Oracle working.

93 |
94 | 95 |
96 | 97 | 98 | 99 | 113 | 114 | 115 | 116 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /manual/pages/roadmap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Road Map: DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Road Map

54 | 55 |

Datamapper ORM is fully functional as is. Certain new features are in the queue to help make Datamapper ORM easier to use, as well as adding more extensions.

56 | 57 | 64 | 65 |

If you have any suggestions or ideas on what you'd like to see in Datamapper ORM, feel free to add a feature request to the BitBucket tracker!

66 | 67 | 68 |
69 | 70 | 71 | 72 | 86 | 87 | 88 | 89 | 90 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /manual/pages/savingrelations.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Saving Relationships : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Saving Relationships

54 | 55 |

Read Save to see how to save relationships.

56 | 57 | 58 | 59 |
60 | 61 | 62 | 63 | 77 | 78 | 79 | 80 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /manual/pages/timestamp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Automated Timestamps : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Automated Timestamps

54 | 55 |

DataMapper has the ability to automattically manage your Created and Updated timestamps, if your tables have the Created and Updated fields. By default, DataMapper looks for fields names created and updated. If they exist, it looks after the values for these fields without you ever needing to set them.

56 | 57 |

Note: By default, the Created and Updated fields are of the DateTime type, and GMT/UTC time is used.

58 | 59 |

If you would like to change the name of the Created and Updated fields, you can do so by setting the $created_field and $updated_field class variables in your DataMapper model. For example, we'll set them in our User model:

60 | 61 |
1 62 | 2 63 | 3 64 | 4 65 | 5 66 | 6 67 | 7 68 | 8 69 | 9 70 | 10 71 | 11 72 | 12 73 | 13 74 | 14 75 | 15
<?php 76 | 77 | class User extends DataMapper { 78 | 79 | var $created_field = 'created_on'; 80 | var $updated_field = 'updated_on'; 81 | 82 | function __construct($id = NULL) 83 | { 84 | parent::__construct($id); 85 | } 86 | } 87 | 88 | /* End of file user.php */ 89 | /* Location: ./application/models/user.php */ 90 |
91 | 92 |

If you'd prefer to use Unix Timestamps or if you'd like to use Local Time instead of GMT/UTC, you can do so by setting the $unix_timestamp and $local_time class variables respectively. For example:

93 | 94 |
1 95 | 2 96 | 3 97 | 4 98 | 5 99 | 6 100 | 7 101 | 8 102 | 9 103 | 10 104 | 11 105 | 12 106 | 13 107 | 14 108 | 15 109 | 16 110 | 17
<?php 111 | 112 | class User extends DataMapper { 113 | 114 | var $created_field = 'created_on'; 115 | var $updated_field = 'updated_on'; 116 | var $local_time = TRUE; 117 | var $unix_timestamp = TRUE; 118 | 119 | function __construct($id = NULL) 120 | { 121 | parent::__construct($id); 122 | } 123 | } 124 | 125 | /* End of file user.php */ 126 | /* Location: ./application/models/user.php */ 127 |
128 | 129 |

Alternatively, you can set this up globally for all your DataMapper models by setting them in the Configuration.

130 | 131 |

Timestamp Format

132 |

New to Datamapper ORM 1.7.0, you can now specify the timestamp format.

133 | 134 |
135 | 136 | 137 | 138 | 152 | 153 | 154 | 155 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /manual/pages/toc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Table of Contents : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Table of Contents

54 | 55 |
56 | 57 |
58 | 59 | 60 | 61 | 68 | 69 | 70 | 71 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /manual/pages/validate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Validate : DataMapper ORM - User Guide 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 |

DataMapper ORM

30 |
31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 | 49 | 50 |
51 | 52 | 53 |

Validate

54 | 55 |

Validate is automatically run on every save() call, so long as you don't provide any parameters (such as saving a relationship). This allows your data to automatically have your predefined pre-processing and prepping validation rules applied. Read the Get and Save topics for more information.

56 |

You can also force DataMapper to skip validation on a save by calling skip_validation just before calling save.

57 | 58 | 59 |
60 | 61 | 62 | 63 | 77 | 78 | 79 | 80 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /manual/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Allow: / 3 | --------------------------------------------------------------------------------