diff --git a/ci-model.sublime-project b/ci-model.sublime-project new file mode 100644 index 0000000..e71b2d5 --- /dev/null +++ b/ci-model.sublime-project @@ -0,0 +1,8 @@ +{ + "folders": + [ + { + "path": "/Users/carlos/Sites/codeigniter-base-model" + } + ] +} diff --git a/ci-model.sublime-workspace b/ci-model.sublime-workspace new file mode 100644 index 0000000..892231d --- /dev/null +++ b/ci-model.sublime-workspace @@ -0,0 +1,339 @@ +{ + "auto_complete": + { + "selected_items": + [ + [ + "te", + "text-align" + ], + [ + "esc", + "escalera" + ], + [ + "B", + "Bancaria" + ], + [ + "he", + "helper" + ], + [ + "reco", + "record" + ], + [ + "po", + "post" + ], + [ + "pa", + "pasivos" + ], + [ + "su", + "sucur" + ], + [ + "pas", + "pasivo" + ], + [ + "strp", + "strpos" + ], + [ + "email", + "exif_thumbnail" + ], + [ + "pre", + "prevision" + ], + [ + "fun", + "function" + ], + [ + "sub", + "substr_count" + ], + [ + "s", + "style" + ], + [ + "f", + "file" + ], + [ + "var", + "var_dump" + ], + [ + "ex", + "exit" + ], + [ + "a", + "array $… = array (…)" + ], + [ + "g", + "group" + ], + [ + "for", + "foreach foreach …" + ], + [ + "va", + "var_dump" + ], + [ + "do", + "documentos" + ], + [ + "th", + "this" + ], + [ + "is", + "is_array" + ], + [ + "border-s", + "border-style" + ], + [ + "ba", + "base64_encode" + ], + [ + "base", + "base64_decode" + ] + ] + }, + "buffers": + [ + ], + "build_system": "", + "command_palette": + { + "height": 311.0, + "selected_items": + [ + [ + "Package Control: ", + "Package Control: Discover Packages" + ] + ], + "width": 400.0 + }, + "console": + { + "height": 0.0 + }, + "distraction_free": + { + "menu_visible": true, + "show_minimap": false, + "show_open_files": false, + "show_tabs": false, + "side_bar_visible": false, + "status_bar_visible": false + }, + "file_history": + [ + "/Users/carlos/Sites/helpdesk/helpdesk.sublime-project", + "/C/wamp/www/helpdesk/application/models/Tecnicos_emp_Model.php", + "/C/wamp/www/helpdesk/application/core/MY_Model.php", + "/C/wamp/www/helpdesk/application/libraries/User_Controller.php", + "/C/wamp/www/helpdesk/application/models/Empresas_model.php", + "/C/wamp/www/helpdesk/application/models/Users_Model.php", + "/C/wamp/www/helpdesk/application/controllers/admin/empresas.php", + "/C/wamp/www/helpdesk/application/views/admin/empresas/index.php", + "/C/wamp/www/www.tuxteam.com.ar/www/css/base-admin.css", + "/C/wamp/www/www.tuxteam.com.ar/www/css/main.css", + "/C/wamp/www/www.tuxteam.com.ar/application/views/layout/navigation.php", + "/C/Users/Carlos.GRUPOATISA/Documents/personal/pruebas.ep", + "/C/wamp/www/www.tuxteam.com.ar/application/config/config.php", + "/C/wamp/www/www.tuxteam.com.ar/application/config/database.php", + "/C/wamp/www/www.tuxteam.com.ar/application/config/autoload.php", + "/C/Users/Carlos.GRUPOATISA/AppData/Roaming/Sublime Text 2/Packages/User/Preferences.sublime-settings", + "/C/Users/Carlos.GRUPOATISA/AppData/Roaming/Sublime Text 2/Packages/User/PHP.sublime-settings", + "/C/wamp/www/endesa/application/core/MY_Model.php", + "/C/wamp/www/endesa/application/views/solicitudes/bancos_ok.php", + "/C/wamp/www/endesa/application/models/pasivos_model.php", + "/C/wamp/www/endesa/application/views/solicitudes/domicilio.php", + "/C/wamp/www/endesa/application/views/container/menu.php", + "/C/wamp/www/endesa/application/controllers/solicitudes.php", + "/C/wamp/www/endesa/application/models/prevision_model.php", + "/C/wamp/www/endesa/application/models/documentos_model.php", + "/C/wamp/www/endesa/application/views/solicitudes/bancos.php", + "/C/wamp/www/endesa/application/config/config.php", + "/C/wamp/www/endesa/application/views/solicitudes/pendientes.php", + "/C/wamp/www/endesa/application/controllers/auth.php", + "/C/wamp/www/endesa/application/views/auth/login.php", + "/C/Users/Carlos/AppData/Roaming/Sublime Text 2/Packages/User/phpcs.sublime-settings", + "/C/wamp/www/endesa/application/views/solicitudes/domicilio_ok.php", + "//webserver2/www/prejubiladosypasivosendesa.es/www/.htaccess", + "/C/wamp/www/endesa/application/controllers/documentos.php", + "/C/wamp/www/endesa/application/controllers/pasivos.php", + "/C/wamp/www/endesa/application/views/pasivos/prevision.php", + "/C/wamp/www/endesa/application/views/pasivos/fluido.php", + "/C/wamp/www/endesa/application/views/documentos/documentos.php", + "/C/wamp/www/endesa/www/css/endesa/bootstrap/less/bootstrap.less", + "/C/wamp/www/endesa/application/views/pasivos/view.php", + "/C/wamp/www/endesa/application/views/pasivos/beneficios.php", + "/C/wamp/www/endesa/application/views/pasivos/sevillana.php", + "/C/wamp/www/endesa/application/models/beneficios_model.php", + "/C/wamp/www/endesa/application/models/personas_model.php", + "/C/wamp/www/endesa/www/css/endesa/bootstrap/less/font-awesome.less", + "/C/wamp/www/endesa/application/views/personas/view.php", + "/C/wamp/www/endesa/application/views/pasivos/password.php", + "/C/wamp/www/endesa/application/views/documentos/fichero.php", + "/C/wamp/www/endesa/application/models/rf_calculos_traba_model.php", + "/C/wamp/www/endesa/application/models/ion_auth_model.php", + "/C/wamp/www/endesa/www/css/endesa/bootstrap/less/variables.less", + "/C/wamp/www/endesa/application/models/auth_model.php", + "/C/wamp/www/endesa/application/views/container.php", + "/C/wamp/www/endesa/application/controllers/personas.php", + "/C/wamp/www/endesa/application/views/auth/alta.php", + "/C/wamp/www/endesa/application/views/container/footer.php", + "/C/wamp/www/endesa/application/models/captcha_model.php", + "/C/wamp/www/endesa/application/views/documentos/download.php", + "/C/wamp/www/endesa/application/views/documentos/mod145blanco.php", + "/C/wamp/www/endesa/application/views/auth/testigo.php", + "/C/wamp/www/endesa/application/views/documentos/list.php", + "/C/wamp/www/endesa/application/views/welcome/view.php", + "/C/temp/tt/entropillc-bootstrap-verticaltabs-b08174f/index.html", + "/C/wamp/www/endesa/application/views/container/meta.php", + "/C/wamp/www/endesa/application/controllers/welcome.php", + "/C/wamp/www/endesa/www/css/dev204/footer.less", + "/C/wamp/www/endesa/www/css/endesa/bootstrap/less/bootstrap0.less", + "/C/wamp/www/endesa/www/css/endesa/base.less", + "/C/wamp/www/endesa/application/abstracts/AB_Base_Controller.php", + "/C/wamp/www/endesa/application/models/menu_model.php", + "/C/wamp/www/endesa/application/models/usuarios_model.php", + "/C/wamp/www/endesa/application/controllers/cambiar_clave.php", + "/C/wamp/www/endesa/application/config/database.php", + "/C/wamp/www/endesa/application/controllers/styles.php", + "/C/Users/Carlos/Desktop/5452_000001155424_25092012.n43" + ], + "find": + { + "height": 34.0 + }, + "find_in_files": + { + "height": 0.0, + "where_history": + [ + ] + }, + "find_state": + { + "case_sensitive": false, + "find_history": + [ + "_with", + "with", + "]?>", + "]?>\"/>", + " uneditable-input\"", + "$record[", + "/bootstrap220/", + "@import \"", + "/bootstrap/" + ], + "highlight": true, + "in_selection": false, + "preserve_case": false, + "regex": false, + "replace_history": + [ + ", $actual[])?>\"/>", + "\" value=\"", + "set_value(", + "$actual[", + "/bootstrap220/less/", + "@import \"../../../comun/bootstrap220/", + "/bootstrap220/" + ], + "reverse": false, + "show_context": true, + "use_buffer2": true, + "whole_word": false, + "wrap": true + }, + "groups": + [ + { + "sheets": + [ + ] + } + ], + "incremental_find": + { + "height": 0.0 + }, + "input": + { + "height": 31.0 + }, + "layout": + { + "cells": + [ + [ + 0, + 0, + 1, + 1 + ] + ], + "cols": + [ + 0.0, + 1.0 + ], + "rows": + [ + 0.0, + 1.0 + ] + }, + "menu_visible": true, + "replace": + { + "height": 62.0 + }, + "save_all_on_build": true, + "select_file": + { + "height": 0.0, + "selected_items": + [ + ], + "width": 0.0 + }, + "select_project": + { + "height": 0.0, + "selected_items": + [ + ], + "width": 0.0 + }, + "show_minimap": true, + "show_open_files": true, + "show_tabs": true, + "side_bar_visible": true, + "side_bar_width": 235.0, + "status_bar_visible": true +} diff --git a/core/MY_Model.php b/core/MY_Model.php index fcf1aa1..a395b42 100644 --- a/core/MY_Model.php +++ b/core/MY_Model.php @@ -523,6 +523,50 @@ public function relate($row) return $row; } + public function with_count($relationship) + { + $this->_with_count[] = $relationship; + + if (!in_array('relate_count', $this->after_get)) + { + $this->after_get[] = 'relate_count'; + } + + return $this; + } + + public function relate_count($row) + { + foreach ($this->has_many as $key => $value) + { + if (is_string($value)) + { + $relationship = $value; + $options = array( 'primary_key' => singular($this->_table) . '_id', 'model' => singular($value) . '_model' ); + } + else + { + $relationship = $key; + $options = $value; + } + + if (in_array($relationship, $this->_with_count)) + { + $this->load->model($options['model']); + if (is_object($row)) + { + $row->{$relationship} = $this->{$options['model']}->count_by($options['primary_key'], $row->{$this->primary_key}); + } + else + { + $row[$relationship] = $this->{$options['model']}->count_by($options['primary_key'], $row[$this->primary_key]); + } + } + } + + return $row; + } + /* -------------------------------------------------------------- * UTILITY METHODS * ------------------------------------------------------------ */ @@ -575,6 +619,11 @@ public function count_by() $where = func_get_args(); $this->_set_where($where); + if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) + { + $this->_database->where($this->soft_delete_key, FALSE); + } + return $this->_database->count_all_results($this->_table); } @@ -583,10 +632,18 @@ public function count_by() */ public function count_all() { - return $this->_database->count_all($this->_table); + if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) + { + $this->_database->where($this->soft_delete_key, FALSE); + return $this->_database->count_all_results($this->_table); + } + else + { + return $this->_database->count_all($this->_table); + } } - - /** + + /** * Tell the class to skip the insert validation */ public function skip_validation() @@ -902,4 +959,4 @@ protected function _return_type($multi = FALSE) $method = ($multi) ? 'result' : 'row'; return $this->_temporary_return_type == 'array' ? $method . '_array' : $method; } -} \ No newline at end of file +}