3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 class CRM_SMS_BAO_Provider
extends CRM_SMS_DAO_Provider
{
40 * @return \CRM_SMS_DAO_Provider
44 public function __construct() {
45 parent
::__construct();
51 public static function activeProviderCount() {
52 $activeProviders = CRM_Core_DAO
::singleValueQuery('SELECT MAX(id) FROM civicrm_sms_provider WHERE is_active = 1');
53 return $activeProviders;
57 * Retrieves the list of providers from the database.
59 * $selectArr array of coloumns to fetch
60 * $getActive boolean to get active providers
62 * @param null $selectArr
64 * @param bool $getActive
65 * @param string $orderBy
69 public static function getProviders($selectArr = NULL, $filter = NULL, $getActive = TRUE, $orderBy = 'id') {
73 $dao = new CRM_SMS_DAO_Provider();
74 if ($filter && !array_key_exists('is_active', $filter) && $getActive) {
77 if ($filter && is_array($filter)) {
78 foreach ($filter as $key => $value) {
82 if ($selectArr && is_array($selectArr)) {
83 $select = implode(',', $selectArr);
84 $dao->selectAdd($select);
86 $dao->orderBy($orderBy);
88 while ($dao->fetch()) {
89 CRM_Core_DAO
::storeValues($dao, $temp);
98 public static function saveRecord($values) {
99 $dao = new CRM_SMS_DAO_Provider();
100 $dao->copyValues($values);
106 * @param int $providerId
108 public static function updateRecord($values, $providerId) {
109 $dao = new CRM_SMS_DAO_Provider();
110 $dao->id
= $providerId;
111 if ($dao->find(TRUE)) {
112 $dao->copyValues($values);
123 public static function setIsActive($id, $is_active) {
124 return CRM_Core_DAO
::setFieldValue('CRM_SMS_DAO_Provider', $id, 'is_active', $is_active);
128 * @param int $providerID
133 public static function del($providerID) {
135 CRM_Core_Error
::fatal(ts('Invalid value passed to delete function.'));
138 $dao = new CRM_SMS_DAO_Provider();
139 $dao->id
= $providerID;
140 if (!$dao->find(TRUE)) {
147 * @param int $providerID
148 * @param null $returnParam
149 * @param null $returnDefaultString
153 public static function getProviderInfo($providerID, $returnParam = NULL, $returnDefaultString = NULL) {
154 static $providerInfo = array();
156 if (!array_key_exists($providerID, $providerInfo)) {
157 $providerInfo[$providerID] = array();
159 $dao = new CRM_SMS_DAO_Provider();
160 $dao->id
= $providerID;
161 if ($dao->find(TRUE)) {
162 CRM_Core_DAO
::storeValues($dao, $providerInfo[$providerID]);
163 $inputLines = explode("\n", $providerInfo[$providerID]['api_params']);
164 $inputVals = array();
165 foreach ($inputLines as $value) {
167 list($key, $val) = explode("=", $value);
168 $inputVals[trim($key)] = trim($val);
171 $providerInfo[$providerID]['api_params'] = $inputVals;
173 // Replace the api_type ID with the string value
174 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type');
175 $apiTypeId = $providerInfo[$providerID]['api_type'];
176 $providerInfo[$providerID]['api_type'] = CRM_Utils_Array
::value($apiTypeId, $apiTypes, $apiTypeId);
181 return CRM_Utils_Array
::value($returnParam, $providerInfo[$providerID], $returnDefaultString);
183 return $providerInfo[$providerID];