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