3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
33 class CRM_SMS_BAO_Provider
extends CRM_SMS_DAO_Provider
{
38 * @return \CRM_SMS_DAO_Provider
40 public function __construct() {
41 parent
::__construct();
47 public static function activeProviderCount() {
48 $activeProviders = CRM_Core_DAO
::singleValueQuery('SELECT MAX(id) FROM civicrm_sms_provider WHERE is_active = 1');
49 return $activeProviders;
53 * Retrieves the list of providers from the database.
55 * $selectArr array of coloumns to fetch
56 * $getActive boolean to get active providers
58 * @param null $selectArr
60 * @param bool $getActive
61 * @param string $orderBy
65 public static function getProviders($selectArr = NULL, $filter = NULL, $getActive = TRUE, $orderBy = 'id') {
69 $dao = new CRM_SMS_DAO_Provider();
70 if ($filter && !array_key_exists('is_active', $filter) && $getActive) {
73 if ($filter && is_array($filter)) {
74 foreach ($filter as $key => $value) {
78 if ($selectArr && is_array($selectArr)) {
79 $select = implode(',', $selectArr);
80 $dao->selectAdd($select);
82 $dao->orderBy($orderBy);
84 while ($dao->fetch()) {
85 CRM_Core_DAO
::storeValues($dao, $temp);
94 public static function saveRecord($values) {
95 $dao = new CRM_SMS_DAO_Provider();
96 $dao->copyValues($values);
102 * @param int $providerId
104 public static function updateRecord($values, $providerId) {
105 $dao = new CRM_SMS_DAO_Provider();
106 $dao->id
= $providerId;
107 if ($dao->find(TRUE)) {
108 $dao->copyValues($values);
119 public static function setIsActive($id, $is_active) {
120 return CRM_Core_DAO
::setFieldValue('CRM_SMS_DAO_Provider', $id, 'is_active', $is_active);
124 * @param int $providerID
129 public static function del($providerID) {
131 CRM_Core_Error
::fatal(ts('Invalid value passed to delete function.'));
134 $dao = new CRM_SMS_DAO_Provider();
135 $dao->id
= $providerID;
136 if (!$dao->find(TRUE)) {
143 * @param int $providerID
144 * @param null $returnParam
145 * @param null $returnDefaultString
149 public static function getProviderInfo($providerID, $returnParam = NULL, $returnDefaultString = NULL) {
150 static $providerInfo = array();
152 if (!array_key_exists($providerID, $providerInfo)) {
153 $providerInfo[$providerID] = array();
155 $dao = new CRM_SMS_DAO_Provider();
156 $dao->id
= $providerID;
157 if ($dao->find(TRUE)) {
158 CRM_Core_DAO
::storeValues($dao, $providerInfo[$providerID]);
159 $inputLines = explode("\n", $providerInfo[$providerID]['api_params']);
160 $inputVals = array();
161 foreach ($inputLines as $value) {
163 list($key, $val) = explode("=", $value);
164 $inputVals[trim($key)] = trim($val);
167 $providerInfo[$providerID]['api_params'] = $inputVals;
169 // Replace the api_type ID with the string value
170 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type');
171 $apiTypeId = $providerInfo[$providerID]['api_type'];
172 $providerInfo[$providerID]['api_type'] = CRM_Utils_Array
::value($apiTypeId, $apiTypes, $apiTypeId);
177 return CRM_Utils_Array
::value($returnParam, $providerInfo[$providerID], $returnDefaultString);
179 return $providerInfo[$providerID];