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 : ' . $provider_id);
22: }
23: return $this->db->get_where('ea_users', array('id' => $provider_id))->row_array();
24: }
25:
26: 27: 28: 29: 30: 31: 32: 33:
34: public function get_value($field_name, $provider_id) {
35: if (!is_numeric($provider_id)) {
36: throw new InvalidArgumentException('Invalid argument provided as $customer_id : '
37: . $provider_id);
38: }
39:
40: if (!is_string($field_name)) {
41: throw new InvalidArgumentException('$field_name argument is not a string : '
42: . $field_name);
43: }
44:
45: if ($this->db->get_where('ea_users', array('id' => $provider_id))->num_rows() == 0) {
46: throw new InvalidArgumentException('The record with the $provider_id argument'
47: . 'does not exist in the database : ' . $provider_id);
48: }
49:
50: $row_data = $this->db->get_where('ea_users', array('id' => $provider_id))->row_array();
51: if (!isset($row_data[$field_name])) {
52: throw new InvalidArgumentException('The given $field_name argument does not'
53: . 'exist in the database : ' . $field_name);
54: }
55:
56: return $this->db->get_where('ea_users', array('id' => $provider_id))
57: ->row_array()[$field_name];
58: }
59:
60: 61: 62: 63: 64: 65: 66: 67: 68:
69: public function get_batch($where_clause = '') {
70: $providers_role_id = $this->get_providers_role_id();
71:
72: if ($where_clause != '') {
73: $this->db->where($where_clause);
74: }
75:
76: $this->db->where('id_roles', $providers_role_id);
77:
78: return $this->db->get('ea_users')->result_array();
79: }
80:
81: 82: 83: 84: 85: 86: 87:
88: public function get_available_providers() {
89: $this->db
90: ->select('ea_users.*')
91: ->from('ea_users')
92: ->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner')
93: ->where('ea_roles.slug', 'provider');
94:
95: $providers = $this->db->get()->result_array();
96:
97: foreach($providers as &$provider) {
98: $this->db
99: ->select('id_services')
100: ->from('ea_services_providers')
101: ->where('id_users', $provider['id']);
102:
103: $provider_services = $this->db->get()->result_array();
104:
105: if (!isset($provider['services'])) {
106: $provider['services'] = array();
107: }
108:
109: foreach($provider_services as $providerService) {
110: $provider['services'][] = $providerService['id_services'];
111: }
112: }
113:
114: return $providers;
115: }
116:
117: 118: 119: 120: 121:
122: public function get_providers_role_id() {
123: return $this->db->get_where('ea_roles', array('slug' => DB_SLUG_PROVIDER))->row()->id;
124: }
125:
126: 127: 128: 129: 130: 131: 132: 133:
134: public function get_setting($setting_name, $provider_id) {
135: return $this->db->get_where('ea_user_settings', array('id_users' => $provider_id))
136: ->row_array()[$setting_name];
137: }
138: }
139:
140:
141: