-
Notifications
You must be signed in to change notification settings - Fork 194
Model Users To Marks
Jeff Johns edited this page Feb 6, 2014
·
3 revisions
Model | Extends | Table | Path |
---|---|---|---|
Users_To_Marks_Model | Plain_Model | users_to_marks | /application/models/users_to_marks_model.php |
$this->load->model('users_to_marks_model', 'user_marks');
Property | Visibility | Default Value | Description |
---|---|---|---|
$sort | Public | created_on DESC | The default sort direction for reads. |
Called automatically which in turn calls the parent constructor and sets the model $data_types
properties.
Used to create new records in the users_to_marks
table.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$options | array | array() | Yes | An associative array that contains the column names and the values for the record to be created. Array keys are the column names for each value. |
$options['mark_id'] | integer | N/A/td> | Yes | The mark id. |
$options['user_id'] | integer | N/A/td> | Yes | The user id. |
$options['label_id'] | integer | N/A/td> | No | The label id to apply. |
$options['notes'] | string | N/A/td> | No | Any notes to save. |
$this->load->model('users_to_marks_model', 'user_marks');
$mark = $this->user_marks->create(array('mark_id' => 7, 'user_id' => $this->user_id));
// If tag was created
if (isset($mark->mark_id)) {
// Good to go
}
// Some sort of validation error
elseif (isset($mark['errors']) {
// Validation errors were found
}
// Some sort of database write error, check logs
else {
// will return false
}
Formats results from complex queries before it returns them.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$marks | array | N/A | Yes | The complete array of objects returned from the query. |
return self::format($marks);
Returns totals for different mark states. (IE: archived, saved or marks)
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$type | string | N/A | Yes | One of the following: archived, saved or marks. Archived returns the total archived marks, saved is total marks overall and marks it total active marks for the time period specified. |
$user_id | integer | N/A | Yes | The user id to get the stats for. |
$start | string | null | No | The start date range for finding totals for. |
$finish | string | null | No | The finish date range for finding totals for. |
$this->load->model('users_to_marks_model', 'user_marks');
$total_saved = $this->user_marks->getTotal('saved', $this->user_id, 'yesterday', 'today');
// will return total saved marks overall for yesterday
Used to get the correct total count of marks for search queries.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$page | integer | 1 | No | The current page of records to return. Used as an offset in the LIMIT statement. |
$limit | integer | 1 | No | The max records to return. |
$data | array | array() | No | The current $data array to add onto and return. |
$keyword | string | N/A | Yes | The keyword used for searching. |
$user_id | integer | N/A | Yes | An user id to use in the search. |
// Searching
$this->load->model('users_to_marks_model', 'user_marks');
$marks = $this->user_marks->readComplete($where, $this->limit, $page, array('search' => 'google', 'user_id' => $this->user_id));
$marks = $this->user_marks->getTotalsSearch($page, $this->limit, $marks, 'google', $this->uesr_id);
Used to read all label data and return it in a nicely formatted structure. You can always use $this->labels->read
to get the raw data from the table anytime you wish.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$where | mixed | N/A | Yes | If numeric the where clause will be filled in with the id submitted and the correct column, otherwise it will just use the where clause you submitted. |
$limit | integer | 1 | No | The max records to return. |
$page | integer | 1 | No | The current page of records to return. Used as an offset in the LIMIT statement. |
$start | integer | null | No | The start position to return records from. |
$options | array | array() | No | An array of special options which if sent change the resulting query. |
$options['tag_id'] | integer | N/A | No | If specified it will add an INNER JOIN for the specific tag id. Used for lookups by tag. |
$options['search'] | string | N/A | No | The word or phrase to use for search. If not empty, you must also send the $options['user_id'] |
$options['user_id'] | integer | N/A | If $options['search'] = true, Yes; else No. | The user id to use for search. |
$options['url_key'] | string | N/A | No | If specified it will add an INNER JOIN for the specific url_ey. Used for lookups by url_key. |
// Normal full query for first 30 marks
$this->load->model('users_to_marks_model', 'user_marks');
$marks = $this->user_marks->readComplete($where, $this->limit, $page);
if ($marks == false) {
$this->data['errors'] = formatErrors(2);
$this->data['total'] = 0;
}
else {
$this->data['marks'] = $marks;
$this->data = $this->user_marks->getTotals($where, $page, $this->limit, $this->data);
}
// Tag lookup
$this->load->model('users_to_marks_model', 'user_marks');
$marks = $this->user_marks->readComplete($where, $this->limit, $page, array('tag_id' => 7));
// Searching
$this->load->model('users_to_marks_model', 'user_marks');
$marks = $this->user_marks->readComplete($where, $this->limit, $page, array('search' => 'google', 'user_id' => $this->user_id));