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 public function __construct() {
39 parent
::__construct();
45 public static function activeProviderCount() {
46 $activeProviders = CRM_Core_DAO
::singleValueQuery('SELECT MAX(id) FROM civicrm_sms_provider WHERE is_active = 1');
47 return $activeProviders;
51 * Retrieves the list of providers from the database.
53 * $selectArr array of coloumns to fetch
54 * $getActive boolean to get active providers
56 * @param null $selectArr
58 * @param bool $getActive
59 * @param string $orderBy
63 public static function getProviders($selectArr = NULL, $filter = NULL, $getActive = TRUE, $orderBy = 'id') {
67 $dao = new CRM_SMS_DAO_Provider();
68 if ($filter && !array_key_exists('is_active', $filter) && $getActive) {
71 if ($filter && is_array($filter)) {
72 foreach ($filter as $key => $value) {
76 if ($selectArr && is_array($selectArr)) {
77 $select = implode(',', $selectArr);
78 $dao->selectAdd($select);
80 $dao->whereAdd("(domain_id = " . CRM_Core_Config
::domainID() . " OR domain_id IS NULL)");
81 $dao->orderBy($orderBy);
83 while ($dao->fetch()) {
84 CRM_Core_DAO
::storeValues($dao, $temp);
91 * Create or Update an SMS provider
92 * @param array $params
93 * @return array saved values
95 public static function create(&$params) {
96 $id = CRM_Utils_Array
::value('id', $params);
99 CRM_Utils_Hook
::pre('edit', 'SmsProvider', $id, $params);
102 CRM_Utils_Hook
::pre('create', 'SmsProvider', NULL, $params);
105 $provider = new CRM_SMS_DAO_Provider();
108 $provider->find(TRUE);
111 $provider->domain_id
= CRM_Utils_Array
::value('domain_id', $params, $provider->domain_id
);
114 $provider->domain_id
= CRM_Utils_Array
::value('domain_id', $params, CRM_Core_Config
::domainID());
116 $provider->copyValues($params);
117 $result = $provider->save();
119 CRM_Utils_Hook
::post('edit', 'SmsProvider', $provider->id
, $provider);
122 CRM_Utils_Hook
::post('create', 'SmsProvider', NULL, $provider);
133 public static function setIsActive($id, $is_active) {
134 return CRM_Core_DAO
::setFieldValue('CRM_SMS_DAO_Provider', $id, 'is_active', $is_active);
138 * @param int $providerID
143 public static function del($providerID) {
145 CRM_Core_Error
::fatal(ts('Invalid value passed to delete function.'));
148 $dao = new CRM_SMS_DAO_Provider();
149 $dao->id
= $providerID;
150 $dao->whereAdd
= "(domain_id = " . CRM_Core_Config
::domainID() . "OR domain_id IS NULL)";
151 if (!$dao->find(TRUE)) {
158 * @param int $providerID
159 * @param null $returnParam
160 * @param null $returnDefaultString
164 public static function getProviderInfo($providerID, $returnParam = NULL, $returnDefaultString = NULL) {
165 static $providerInfo = array();
167 if (!array_key_exists($providerID, $providerInfo)) {
168 $providerInfo[$providerID] = array();
170 $dao = new CRM_SMS_DAO_Provider();
171 $dao->id
= $providerID;
172 if ($dao->find(TRUE)) {
173 CRM_Core_DAO
::storeValues($dao, $providerInfo[$providerID]);
174 $inputLines = explode("\n", $providerInfo[$providerID]['api_params']);
175 $inputVals = array();
176 foreach ($inputLines as $value) {
178 list($key, $val) = explode("=", $value);
179 $inputVals[trim($key)] = trim($val);
182 $providerInfo[$providerID]['api_params'] = $inputVals;
184 // Replace the api_type ID with the string value
185 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type');
186 $apiTypeId = $providerInfo[$providerID]['api_type'];
187 $providerInfo[$providerID]['api_type'] = CRM_Utils_Array
::value($apiTypeId, $apiTypes, $apiTypeId);
192 return CRM_Utils_Array
::value($returnParam, $providerInfo[$providerID], $returnDefaultString);
194 return $providerInfo[$providerID];