copyright and version fixes
[civicrm-core.git] / CRM / SMS / BAO / Provider.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id: $
33 *
34 */
35class CRM_SMS_BAO_Provider extends CRM_SMS_DAO_Provider {
36
37 function __construct() {
38 parent::__construct();
39 }
40
41 static function activeProviderCount() {
42 $activeProviders = CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_sms_provider WHERE is_active = 1');
43 return $activeProviders;
44 }
45
46 /*
47 * Retrieves the list of providers from the database
f813f78e 48 *
6a488035
TO
49 * @access public
50 * $selectArr array of coloumns to fetch
51 * $getActive boolean to get active providers
52 */
53 static function getProviders($selectArr = NULL, $filter = NULL, $getActive = TRUE, $orderBy = 'id') {
54
55 $providers = array();
56 $temp = array();
57 $dao = new CRM_SMS_DAO_Provider();
58 if ($filter && !array_key_exists('is_active', $filter) && $getActive) {
59 $dao->is_active = 1;
60 }
61 if ($filter && is_array($filter)) {
62 foreach ($filter as $key => $value) {
63 $dao->$key = $value;
64 }
65 }
66 if ($selectArr && is_array($selectArr)) {
67 $select = implode(',', $selectArr);
68 $dao->selectAdd($select);
69 }
70 $dao->orderBy($orderBy);
71 $dao->find();
72 while ($dao->fetch()) {
73 CRM_Core_DAO::storeValues($dao, $temp);
74 $providers[] = $temp;
75 }
76 return $providers;
77 }
78
79 static function saveRecord($values) {
80 $dao = new CRM_SMS_DAO_Provider();
81 $dao->copyValues($values);
82 $dao->save();
83 }
84
85 static function updateRecord($values, $providerId) {
86 $dao = new CRM_SMS_DAO_Provider();
87 $dao->id = $providerId;
88 if ($dao->find(TRUE)) {
89 $dao->copyValues($values);
90 $dao->save();
91 }
92 }
93
94 static function setIsActive($id, $is_active) {
95 return CRM_Core_DAO::setFieldValue('CRM_SMS_DAO_Provider', $id, 'is_active', $is_active);
96 }
97
98 static function del($providerID) {
99 if (!$providerID) {
100 CRM_Core_Error::fatal(ts('Invalid value passed to delete function'));
101 }
102
103 $dao = new CRM_SMS_DAO_Provider();
104 $dao->id = $providerID;
105 if (!$dao->find(TRUE)) {
106 return NULL;
107 }
108 $dao->delete();
109 }
110
111 public static function getProviderInfo($providerID, $returnParam = NULL, $returnDefaultString = NULL) {
112 static $providerInfo = array();
113
114 if (!array_key_exists($providerID, $providerInfo)) {
115 $providerInfo[$providerID] = array();
116
117 $dao = new CRM_SMS_DAO_Provider();
118 $dao->id = $providerID;
119 if ($dao->find(TRUE)) {
120 CRM_Core_DAO::storeValues($dao, $providerInfo[$providerID]);
121 $inputLines = explode("\n", $providerInfo[$providerID]['api_params']);
122 $inputVals = array();
123 foreach ($inputLines as $value) {
124 if ($value) {
125 list($key, $val) = explode("=", $value);
126 $inputVals[trim($key)] = trim($val);
127 }
128 }
129 $providerInfo[$providerID]['api_params'] = $inputVals;
503fc58c 130
131 // Replace the api_type ID with the string value
132 $apiTypes = CRM_Core_OptionGroup::values('sms_api_type');
133 $apiTypeId = $providerInfo[$providerID]['api_type'];
134 $providerInfo[$providerID]['api_type'] = CRM_Utils_Array::value($apiTypeId, $apiTypes, $apiTypeId);
6a488035
TO
135 }
136 }
137
138 if ($returnParam) {
139 return CRM_Utils_Array::value($returnParam, $providerInfo[$providerID], $returnDefaultString);
140 }
141 return $providerInfo[$providerID];
142 }
143}
144
145