1: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2:
3: class Providers_Model extends CI_Model {
4: 5: 6:
7: public function __construct() {
8: parent::__construct();
9: }
10:
11: 12: 13: 14: 15: 16: 17: 18:
19: public function get_row($provider_id) {
20: if (!is_numeric($provider_id)) {
21: throw new InvalidArgumentException('$provider_id argument is not an integer : '
22: . $provider_id);
23: }
24: return $this->db->get_where('ea_users', array('id' => $provider_id))->row_array();
25: }
26:
27: 28: 29: 30: 31: 32: 33: 34:
35: public function get_value($field_name, $provider_id) {
36: if (!is_numeric($provider_id)) {
37: throw new InvalidArgumentException('Invalid argument provided as $customer_id : '
38: . $provider_id);
39: }
40:
41: if (!is_string($field_name)) {
42: throw new InvalidArgumentException('$field_name argument is not a string : '
43: . $field_name);
44: }
45:
46: if ($this->db->get_where('ea_users', array('id' => $provider_id))->num_rows() == 0) {
47: throw new InvalidArgumentException('The record with the $provider_id argument'
48: . 'does not exist in the database : ' . $provider_id);
49: }
50:
51: $row_data = $this->db->get_where('ea_users', array('id' => $provider_id))->row_array();
52: if (!isset($row_data[$field_name])) {
53: throw new InvalidArgumentException('The given $field_name argument does not'
54: . 'exist in the database : ' . $field_name);
55: }
56:
57: return $this->db->get_where('ea_users', array('id' => $provider_id))
58: ->row_array()[$field_name];
59: }
60:
61: 62: 63: 64: 65: 66: 67: 68: 69:
70: public function get_batch($where_clause = '') {
71: $providers_role_id = $this->get_providers_role_id();
72:
73: if ($where_clause != '') {
74: $this->db->where($where_clause);
75: }
76:
77: $this->db->where('id_roles', $providers_role_id);
78:
79: return $this->db->get('ea_users')->result_array();
80: }
81:
82: 83: 84: 85: 86: 87: 88: 89:
90: public function get_available_providers() {
91: $this->db
92: ->select('ea_users.*')
93: ->from('ea_users')
94: ->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
95: ->where('ea_roles.slug', 'provider');
96:
97: $providers = $this->db->get()->result_array();
98:
99:
100:
101: foreach($providers as &$provider) {
102: $this->db
103: ->select('id_services')
104: ->from('ea_services_providers')
105: ->where('id_users', $provider['id']);
106:
107: $provider_services = $this->db->get()->result_array();
108:
109: if (!isset($provider['services'])) {
110: $provider['services'] = array();
111: }
112:
113: foreach($provider_services as $service) {
114: $provider['services'][] = $service['id_services'];
115: }
116: }
117:
118: return $providers;
119: }
120:
121: 122: 123: 124: 125:
126: public function get_providers_role_id() {
127: return $this->db->get_where('ea_roles', array('slug' => DB_SLUG_PROVIDER))->row()->id;
128: }
129:
130: 131: 132: 133: 134: 135: 136: 137:
138: public function get_setting($setting_name, $provider_id) {
139: return $this->db->get_where('ea_user_settings', array('id_users' => $provider_id))
140: ->row_array()[$setting_name];
141: }
142:
143: 144: 145: 146: 147: 148: 149:
150: public function set_setting($setting_name, $value, $provider_id) {
151: $this->db->where(array('id_users' => $provider_id));
152: return $this->db->update('ea_user_settings', array($setting_name => $value));
153: }
154: }
155:
156:
157: