-
Notifications
You must be signed in to change notification settings - Fork 0
Measure
Measure model.
Measure model is responsible for all measure related transactions. Also, measure model extends ObservableModel in order to send information about transactions to attached observers.
- Class name: Measure
- Namespace:
- Parent class: ObservableModel
private mixed $_observers = array()
- Visibility: private
public string $error = ''
Stores custom errors that can be used in UI error reporting.
- Visibility: public
public string $table_name = ''
The name of the db table this model primarily uses.
- Visibility: public
protected string $key = 'id'
The primary key of the table. Used as the 'id' throughout.
- Visibility: protected
protected string $created_field = 'created_on'
Field name to use for the created time column in the DB table if $set_created is enabled
- Visibility: protected
protected string $modified_field = 'modified_on'
Field name to use for the modified time column in the DB table if $set_modified is enabled
- Visibility: protected
protected string $deleted_field = 'deleted'
Field name to use for the deleted column in the DB table if $soft_deletes is enabled
- Visibility: protected
protected boolean $set_created = false
Whether or not to auto-fill the $created_field on inserts.
- Visibility: protected
protected boolean $set_modified = false
Whether or not to auto-fill the $modified_field on updates.
- Visibility: protected
protected string $date_format = 'datetime'
The type of date/time field used for $created_field and $modified_field
Valid values are 'int', 'datetime', 'date'
- Visibility: protected
protected boolean $soft_deletes = false
If false, the delete() method will perform a delete of that row.
If true, the value in $deleted_field will be set to 1.
- Visibility: protected
protected string $selects = ''
Stores any selects here for use by the find* functions.
- Visibility: protected
protected boolean $escape = true
If false, the select() method will not try to protect your field or table names with backticks.
This is useful if you need a compound select statement.
- Visibility: protected
protected mixed $db_con = ''
DB Connection details (string or array)
- Visibility: protected
protected array $before_insert = array()
Observer Arrays
Each array can contain the names of callback functions within the extending model which will be called during each event.
$before_insert = array('set_created', 'validate_fields');
$before_insert contains the names of callback functions within the extending model which will be called before the insert method.
- Visibility: protected
protected array $after_insert = array()
Contains the names ozf callback functions within the extending model which will be called after the insert method
- Visibility: protected
protected array $before_update = array()
Contains the names of callback functions within the extending model which will be called before the update method
- Visibility: protected
protected array $after_update = array()
Contains the names of callback functions within the extending model which will be called after the update method
- Visibility: protected
protected array $before_find = array()
Contains the names of callback functions within the extending model which will be called before the find method
- Visibility: protected
protected array $after_find = array()
Contains the names of callback functions within the extending model which will be called after the find method
- Visibility: protected
protected array $before_union_all = array()
Contains the names of callback functions within the extending model which will be called before the union_all method
- Visibility: protected
protected array $after_union_all = array()
Contains the names of callback functions within the extending model which will be called after the union_all method
- Visibility: protected
protected array $before_delete = array()
Contains the names of callback functions within the extending model which will be called before the delete method
- Visibility: protected
protected array $after_delete = array()
Contains the names of callback functions within the extending model which will be called after the delete method
- Visibility: protected
protected array $empty_validation_rules = array()
Contains the names of callback functions within the extending model which will be called if $validation_rules is empty (or not an array) when requested via the get_validation_rules() method.
Note: These methods should not add $insert_validation_rules, as they are added to the $validation_rules after these functions return.
- Visibility: protected
protected array $protected_attributes = array()
Protected, non-modifiable attributes
- Visibility: protected
protected string $return_type = 'object'
By default, we return items as objects. You can change this for the entire class by setting this value to 'array' instead of 'object'.
Alternatively, you can do it on a per-instance basis using the 'as_array()' and 'as_object()' methods.
- Visibility: protected
protected string $temp_return_type = null
Holds the return type temporarily when using the as_array() and as_object() methods
- Visibility: protected
protected Array $validation_rules = array()
- Visibility: protected
protected Array $insert_validation_rules = array()
- Visibility: protected
protected boolean $skip_validation = false
- Visibility: protected
protected boolean $return_insert_id = true
- Visibility: protected
protected Array $field_info = array()
- Visibility: protected
protected array $pending_selects = array()
This array will be populated with selects and mainly use for union based query.
- Visibility: protected
void CI_Model::__construct()
Class constructor
- Visibility: public
- This method is defined by CI_Model
array Measure::getMeasuresByUser(integer $userId)
Get the last measure of each $userWatches
- Visibility: public
- $userId integer - <p>id of the user</p>
mixed Measure::computeAccuracy(\Measure $watchMeasure)
Compute the accuracy of a watch given the raw data of the database
- Visibility: public
- $watchMeasure Measure - <p>A watchMeasure object containing row data about the timing of measure</p>
integer Measure::computePercentileAccuracy(float $accuracy)
Computes the percentile for an accuracy, i.e, the percentage of watches that are less accurate than $accuracy.
The percentile excludes bugged measure (+/- 300 spd)
- Visibility: public
- $accuracy float - <p>A complete measure with computed</p>
mixed Measure::addBaseMesure(integer $watchId, \Long $referenceTime, \Long $userTime)
Add a base measure (1/2) to $watchId given $referenceTime and $userTime
All previous measures, completed or not, will be archived (status = 3) at the creation of a new measure.
- Visibility: public
- $watchId integer - <p>The watch being mesured</p>
- $referenceTime Long - <p>the reference time in ms</p>
- $userTime Long - <p>the user time in ms</p>
mixed|boolean Measure::addAccuracyMesure(\[type] $measureId, \[type] $referenceTime, \[type] $userTime)
Add an accuracy measure (2/2) for $measureId given $referenceTime and $userTime
- Visibility: public
- $measureId [type] - <p>[description]</p>
- $referenceTime [type] - <p>[description]</p>
- $userTime [type] - <p>[description]</p>
boolean Measure::deleteMesure(integer $measureId)
(Soft) Delete the $measureId measure.
- Visibility: public
- $measureId integer - <p>MeasureId of the measure to be deleted</p>
integer Measure::getMeasuresCountByWatchBrand(String $watchBrand)
Count the amount of watch of $watchBrand
- Visibility: public
- $watchBrand String - <p>The watchBrand of interest</p>
mixed ObservableModel::notify(String $event, Array $data)
Notify method. Notifies the registered observers
- Visibility: public
- This method is defined by ObservableModel
- $event String - <p>Description of the event</p>
- $data Array - <p>Data related to the event</p>
mixed MY_Model::find(string $id)
Search for a single row in the database.
- Visibility: public
- This method is defined by MY_Model
- $id string - <p>The primary key of the record to search for.</p>
mixed MY_Model::find_all()
Returns all records in the table.
By default, there is no 'where' clause, but the where clause can be set by using either CodeIgniter's Active Record functions before calling this function, or through method chaining with the model's where() method.
- Visibility: public
- This method is defined by MY_Model
mixed MY_Model::find_union_all()
Returns all of unions, the $pending_selects value has to be populated trhought the union conveniant method
- Visibility: public
- This method is defined by MY_Model
boolean|mixed MY_Model::find_all_by(mixed $field, mixed $value, string $type)
A convenience method that combines a where() and find_all() call into a single call.
- Visibility: public
- This method is defined by MY_Model
- $field mixed - <p>The table field to search in.</p>
- $value mixed - <p>The value that field should be.</p>
- $type string - <p>The type of where clause to create: 'and' or 'or'.</p>
boolean|mixed MY_Model::find_by(string $field, string $value, string $type)
Returns the first result that matches the field/values passed.
- Visibility: public
- This method is defined by MY_Model
- $field string - <p>Either a string or an array of fields to match against. If an array is passed it, the $value parameter is ignored since the array is expected to have key/value pairs in it.</p>
- $value string - <p>The value to match on the $field. Only used when $field is a string.</p>
- $type string - <p>The type of where clause to create: 'and' or 'or'.</p>
boolean|mixed MY_Model::insert(array $data)
Insert a row of data into the database.
- Visibility: public
- This method is defined by MY_Model
- $data array - <p>an array of key/value pairs to insert.</p>
boolean MY_Model::insert_batch(array $data)
Perform a batch insert of data into the database.
- Visibility: public
- This method is defined by MY_Model
- $data array - <p>an array of key/value pairs to insert.</p>
boolean MY_Model::update_table(mixed $where, array $data, $table)
Update an existing row in the database.
- Visibility: public
- This method is defined by MY_Model
- $where mixed - <p>The primary_key value of the row to update, or an array to use for the where clause.</p>
- $data array - <p>An array of key/value pairs to update.</p>
- $table mixed
boolean MY_Model::update(mixed $where, array $data)
Update an existing row in the database.
- Visibility: public
- This method is defined by MY_Model
- $where mixed - <p>The primary_key value of the row to update, or an array to use for the where clause.</p>
- $data array - <p>An array of key/value pairs to update.</p>
boolean MY_Model::increment(mixed $where, $field)
Increment a field. Mostly use for views, likes and so on.
- Visibility: public
- This method is defined by MY_Model
- $where mixed - <p>The primary_key value of the row to update, or an array to use for the where clause.</p>
- $field mixed
boolean MY_Model::decrement(mixed $where, $field)
Decrement a field. Mostly use for views, likes and so on.
- Visibility: public
- This method is defined by MY_Model
- $where mixed - <p>The primary_key value of the row to update, or an array to use for the where clause.</p>
- $field mixed
boolean MY_Model::update_where(string $field, string $value, array $data)
A convenience method that allows use of any field/value pair as the 'where' portion of an update.
- Visibility: public
- This method is defined by MY_Model
- $field string - <p>The field to match on.</p>
- $value string - <p>The value to search the $field for.</p>
- $data array - <p>An array of key/value pairs to update.</p>
boolean MY_Model::update_batch(array $data, string $index)
Updates a batch of existing rows in the database.
- Visibility: public
- This method is defined by MY_Model
- $data array - <p>An array of key/value pairs to update.</p>
- $index string - <p>The name of the db column to use as the where key</p>
boolean MY_Model::delete(mixed $id)
Delete the record with the specified primary key value.
If $this->soft_deletes is true, it will attempt to set $this->deleted_field on the specified record to '1', to allow the data to remain in the database.
- Visibility: public
- This method is defined by MY_Model
- $id mixed - <p>The primary_key value to match against.</p>
boolean MY_Model::delete_where($where)
Delete the record(s) specified by the given field/value pair(s).
Performs a delete using the field/value pair(s) as the 'where' portion of the delete statement.
If $this->soft_deletes is true, it will attempt to set $this->deleted_field on the specified record(s) to '1', to allow the data to remain in the database.
- Visibility: public
- This method is defined by MY_Model
- $where mixed
boolean MY_Model::is_unique(string $field, string $value)
Check whether a field/value pair exists within the table.
- Visibility: public
- This method is defined by MY_Model
- $field string - <p>The name of the field to search</p>
- $value string - <p>The value to match $field against.</p>
boolean|integer MY_Model::count_by(string $field, string $value)
Return the number of elements that match the field/value pair.
- Visibility: public
- This method is defined by MY_Model
- $field string - <p>The field to search for.</p>
- $value string - <p>The value to match $field against.</p>
boolean|mixed MY_Model::get_field(mixed $id, string $field)
A convenience method to return only a single field of the specified row.
- Visibility: public
- This method is defined by MY_Model
- $id mixed - <p>The primary_key value to match against.</p>
- $field string - <p>The field to search for.</p>
array MY_Model::format_dropdown()
A convenience method to return options for form dropdown menus.
Can pass either Key ID and Label Table names or Just Label Table name.
- Visibility: public
- This method is defined by MY_Model
\FF_Model MY_Model::where(mixed $field, string $value, $escape)
Sets the where portion of the query in a chainable format.
- Visibility: public
- This method is defined by MY_Model
- $field mixed - <p>The field to search the db on. Can be either a string with the field name to search, or an associative array of key/value pairs.</p>
- $value string - <p>The value to match the field against. If $field is an array, this value is ignored.</p>
- $escape mixed
\FF_Model MY_Model::order_by(mixed $field, string $order)
Inserts a chainable order_by method from either a string or an array of field/order combinations.
If the $field value is an array, it should look like:
array( 'field1' => 'asc', 'field2' => 'desc' );
- Visibility: public
- This method is defined by MY_Model
- $field mixed - <p>The field to order the results by, or an array of field/order pairs.</p>
- $order string - <p>The direction to order the results ('asc' or 'desc')</p>
\FF_Model MY_Model::soft_delete(boolean $val)
Set the value of the soft deletes flag.
$this->my_model->soft_delete(true)->delete($id);
- Visibility: public
- This method is defined by MY_Model
- $val boolean - <p>If true, will temporarily use soft_deletes.</p>
\FF_Model MY_Model::as_array()
Temporarily set the return type to an array.
- Visibility: public
- This method is defined by MY_Model
\FF_Model MY_Model::as_object()
Temporarily sets the return type to an object.
- Visibility: public
- This method is defined by MY_Model
\FF_Model MY_Model::as_json()
Temporarily sets the object return to a json object.
- Visibility: public
- This method is defined by MY_Model
\FF_Model MY_Model::return_insert_id(Bool $return)
Sets the value of the return_insert_id flag
- Visibility: public
- This method is defined by MY_Model
- $return Bool - <p>(optional) whether insert will return the ID</p>
\FF_Model MY_Model::skip_validation(Bool $skip)
Sets the value of the skip_validation flag
- Visibility: public
- This method is defined by MY_Model
- $skip Bool - <p>(optional) whether to skip validation in the model</p>
array MY_Model::created_on(array $row)
Sets the created date for the row
Uses the current date/time, the model's date_format, and places the value in the model's created_field. Will not overwrite existing.
- Visibility: public
- This method is defined by MY_Model
- $row array - <p>The array of data to be inserted</p>
array MY_Model::modified_on(array $row)
Sets the modified date for the row
Uses the current date/time, the model's date_format, and places the value in the model's modified_field. Will not overwrite existing.
- Visibility: public
- This method is defined by MY_Model
- $row array - <p>The array of data to be inserted</p>
mixed MY_Model::trigger(string $event, mixed $data)
Triggers a model-specific event and calls each of its observers.
- Visibility: public
- This method is defined by MY_Model
- $event string - <p>The name of the event to trigger</p>
- $data mixed - <p>The data to be passed to the callback functions.</p>
array MY_Model::get_validation_rules(String $type)
Get the validation rules for the model
- Visibility: public
- This method is defined by MY_Model
- $type String - <p>The type of validation rules to retrieve: 'update' or 'insert'. If 'insert', appends rules set in $insert_validation_rules.</p>
\array/bool MY_Model::validate(array $data, string $type)
Validate the $data passed into it
Uses the form_validation rules setup in $this->validation_rules.
If $type == 'insert', any additional rules in $insert_validation_rules for that field will be added to the rules.
- Visibility: public
- This method is defined by MY_Model
- $data array - <p>An array of data to validate</p>
- $type string - <p>Either 'update' or 'insert'.</p>
mixed MY_Model::protect_attributes(\object/array $row)
Protect attributes by removing them from $row array.
Useful for removing the primary key, or submit button names if $_POST is thrown at the model.
- Visibility: public
- This method is defined by MY_Model
- $row object/array - <p>The value pair item to remove.</p>
integer|null|string MY_Model::set_date(mixed $user_date)
A utility function to allow child models to use the type of date/time format that they prefer. This is primarily used for setting created_on and modified_on values, but can be used for other fields as well.
The available time formats are:
-
'int' - Stores the date as an integer timestamp.
-
'datetime' - Stores the date and time in the SQL datetime format.
-
'date' - Stores teh date (only) in the SQL date format.
-
Visibility: protected
-
This method is defined by MY_Model
- $user_date mixed - <p>An optional PHP timestamp to be converted.</p>
string MY_Model::_return_type($multi)
Return the method name for the current return type
- Visibility: protected
- This method is defined by MY_Model
- $multi mixed
string MY_Model::get_db_error_message()
Retrieve error messages from the database
- Visibility: protected
- This method is defined by MY_Model
void MY_Model::set_table(string $table)
Allows setting the table to use for all methods during runtime.
- Visibility: public
- This method is defined by MY_Model
- $table string - <p>The table name to use (do not include the prefix!)</p>
string MY_Model::get_table()
Get the table name
- Visibility: public
- This method is defined by MY_Model
string MY_Model::get_key()
Get the table's primary key
- Visibility: public
- This method is defined by MY_Model
String MY_Model::get_created_by_field()
Get the name of the created by field
- Visibility: public
- This method is defined by MY_Model
String MY_Model::get_created_field()
Get the name of the created field
- Visibility: public
- This method is defined by MY_Model
String MY_Model::get_deleted_field()
Get the name of the deleted field
- Visibility: public
- This method is defined by MY_Model
String MY_Model::get_deleted_by_field()
Get the name of the deleted by field
- Visibility: public
- This method is defined by MY_Model
array MY_Model::get_field_info()
Get the metadata for the model's database fields
Returns the model's database field metadata stored in $this->field_info if set, else it tries to retrieve the metadata from $this->db->field_data($this->table_name);
- Visibility: public
- This method is defined by MY_Model
String MY_Model::get_modified_by_field()
Get the name of the modified by field
- Visibility: public
- This method is defined by MY_Model
String MY_Model::get_modified_field()
Get the name of the modified field
- Visibility: public
- This method is defined by MY_Model
boolean MY_Model::set_date_format(string $format)
Sets the date_format to use for setting created_on and modified_on values.
- Visibility: public
- This method is defined by MY_Model
- $format string - <p>String describing format. Valid values are: 'int', 'datetime', 'date'</p>
boolean MY_Model::set_modified(boolean $modified)
Sets whether to auto-create modified_on dates in the update method.
- Visibility: public
- This method is defined by MY_Model
- $modified boolean
boolean MY_Model::set_soft_deletes(boolean $soft)
Sets whether soft deletes are used by the delete method.
- Visibility: public
- This method is defined by MY_Model
- $soft boolean
mixed MY_Model::logit(string $message, string $level)
Logs an error to the Console (if loaded) and to the log files.
- Visibility: protected
- This method is defined by MY_Model
- $message string - <p>The string to write to the logs.</p>
- $level string - <p>The log level, as per CI log_message method.</p>
Array MY_Model::prep_data(Array $post_data)
Extracts the model's fields (except the key and those handled by Observers) from the $post_data and returns an array of name => value pairs
- Visibility: public
- This method is defined by MY_Model
- $post_data Array - <p>The post data, usually $this->input->post() when called from the controller</p>
mixed MY_Model::raw_sql($sql)
- Visibility: public
- This method is defined by MY_Model
- $sql mixed
mixed MY_Model::select($select, $escape)
- Visibility: public
- This method is defined by MY_Model
- $select mixed
- $escape mixed
mixed MY_Model::select_max($select, $alias)
- Visibility: public
- This method is defined by MY_Model
- $select mixed
- $alias mixed
mixed MY_Model::select_min($select, $alias)
- Visibility: public
- This method is defined by MY_Model
- $select mixed
- $alias mixed
mixed MY_Model::select_avg($select, $alias)
- Visibility: public
- This method is defined by MY_Model
- $select mixed
- $alias mixed
mixed MY_Model::select_sum($select, $alias)
- Visibility: public
- This method is defined by MY_Model
- $select mixed
- $alias mixed
mixed MY_Model::distinct($val)
- Visibility: public
- This method is defined by MY_Model
- $val mixed
mixed MY_Model::from($from)
- Visibility: public
- This method is defined by MY_Model
- $from mixed
mixed MY_Model::join($table, $cond, $type)
- Visibility: public
- This method is defined by MY_Model
- $table mixed
- $cond mixed
- $type mixed
mixed MY_Model::union($select)
- Visibility: public
- This method is defined by MY_Model
- $select mixed
mixed MY_Model::or_where($key, $value, $escape)
- Visibility: public
- This method is defined by MY_Model
- $key mixed
- $value mixed
- $escape mixed
mixed MY_Model::where_in($key, $values)
- Visibility: public
- This method is defined by MY_Model
- $key mixed
- $values mixed
mixed MY_Model::or_where_in($key, $values)
- Visibility: public
- This method is defined by MY_Model
- $key mixed
- $values mixed
mixed MY_Model::where_not_in($key, $values)
- Visibility: public
- This method is defined by MY_Model
- $key mixed
- $values mixed
mixed MY_Model::or_where_not_in($key, $values)
- Visibility: public
- This method is defined by MY_Model
- $key mixed
- $values mixed
mixed MY_Model::like($field, $match, $side)
- Visibility: public
- This method is defined by MY_Model
- $field mixed
- $match mixed
- $side mixed
mixed MY_Model::nto_like($field, $match, $side)
- Visibility: public
- This method is defined by MY_Model
- $field mixed
- $match mixed
- $side mixed
mixed MY_Model::or_like($field, $match, $side)
- Visibility: public
- This method is defined by MY_Model
- $field mixed
- $match mixed
- $side mixed
mixed MY_Model::or_not_like($field, $match, $side)
- Visibility: public
- This method is defined by MY_Model
- $field mixed
- $match mixed
- $side mixed
mixed MY_Model::group_by($by)
- Visibility: public
- This method is defined by MY_Model
- $by mixed
mixed MY_Model::having($key, $value, $escape)
- Visibility: public
- This method is defined by MY_Model
- $key mixed
- $value mixed
- $escape mixed
mixed MY_Model::or_having($key, $value, $escape)
- Visibility: public
- This method is defined by MY_Model
- $key mixed
- $value mixed
- $escape mixed
mixed MY_Model::limit($value, $offset)
- Visibility: public
- This method is defined by MY_Model
- $value mixed
- $offset mixed
mixed MY_Model::offset($offset)
- Visibility: public
- This method is defined by MY_Model
- $offset mixed
mixed MY_Model::set($key, $value, $escape)
- Visibility: public
- This method is defined by MY_Model
- $key mixed
- $value mixed
- $escape mixed
mixed MY_Model::affected_rows()
- Visibility: public
- This method is defined by MY_Model
mixed MY_Model::last_query()
- Visibility: public
- This method is defined by MY_Model
mixed MY_Model::truncate()
- Visibility: public
- This method is defined by MY_Model
mixed MY_Model::inserted_id()
- Visibility: public
- This method is defined by MY_Model
mixed CI_Model::__get(string $key)
__get magic
Allows models to access CI's loaded classes using the same syntax as controllers.
- Visibility: public
- This method is defined by CI_Model
- $key string