3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
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 count(id) FROM civicrm_sms_provider WHERE is_active = 1 AND (domain_id = %1 OR domain_id IS NULL)',
47 array(1 => array(CRM_Core_Config
::domainID(), 'Positive')));
48 return $activeProviders;
52 * Retrieves the list of providers from the database.
54 * $selectArr array of coloumns to fetch
55 * $getActive boolean to get active providers
57 * @param null $selectArr
59 * @param bool $getActive
60 * @param string $orderBy
64 public static function getProviders($selectArr = NULL, $filter = NULL, $getActive = TRUE, $orderBy = 'id') {
68 $dao = new CRM_SMS_DAO_Provider();
69 if ($filter && !array_key_exists('is_active', $filter) && $getActive) {
72 if ($filter && is_array($filter)) {
73 foreach ($filter as $key => $value) {
77 if ($selectArr && is_array($selectArr)) {
78 $select = implode(',', $selectArr);
79 $dao->selectAdd($select);
81 $dao->whereAdd("(domain_id = " . CRM_Core_Config
::domainID() . " OR domain_id IS NULL)");
82 $dao->orderBy($orderBy);
84 while ($dao->fetch()) {
85 CRM_Core_DAO
::storeValues($dao, $temp);
86 $providers[$dao->id
] = $temp;
92 * Create or Update an SMS provider
93 * @param array $params
94 * @return array saved values
96 public static function create(&$params) {
97 $id = CRM_Utils_Array
::value('id', $params);
100 CRM_Utils_Hook
::pre('edit', 'SmsProvider', $id, $params);
103 CRM_Utils_Hook
::pre('create', 'SmsProvider', NULL, $params);
106 $provider = new CRM_SMS_DAO_Provider();
109 $provider->find(TRUE);
112 $provider->domain_id
= CRM_Utils_Array
::value('domain_id', $params, $provider->domain_id
);
115 $provider->domain_id
= CRM_Utils_Array
::value('domain_id', $params, CRM_Core_Config
::domainID());
117 $provider->copyValues($params);
118 $result = $provider->save();
120 CRM_Utils_Hook
::post('edit', 'SmsProvider', $provider->id
, $provider);
123 CRM_Utils_Hook
::post('create', 'SmsProvider', NULL, $provider);
134 public static function setIsActive($id, $is_active) {
135 return CRM_Core_DAO
::setFieldValue('CRM_SMS_DAO_Provider', $id, 'is_active', $is_active);
139 * @param int $providerID
144 public static function del($providerID) {
146 CRM_Core_Error
::fatal(ts('Invalid value passed to delete function.'));
149 $dao = new CRM_SMS_DAO_Provider();
150 $dao->id
= $providerID;
151 $dao->whereAdd
= "(domain_id = " . CRM_Core_Config
::domainID() . "OR domain_id IS NULL)";
152 if (!$dao->find(TRUE)) {
159 * @param int $providerID
160 * @param null $returnParam
161 * @param null $returnDefaultString
165 public static function getProviderInfo($providerID, $returnParam = NULL, $returnDefaultString = NULL) {
166 static $providerInfo = array();
168 if (!array_key_exists($providerID, $providerInfo)) {
169 $providerInfo[$providerID] = array();
171 $dao = new CRM_SMS_DAO_Provider();
172 $dao->id
= $providerID;
173 if ($dao->find(TRUE)) {
174 CRM_Core_DAO
::storeValues($dao, $providerInfo[$providerID]);
175 $inputLines = explode("\n", $providerInfo[$providerID]['api_params']);
176 $inputVals = array();
177 foreach ($inputLines as $value) {
179 list($key, $val) = explode("=", $value);
180 $inputVals[trim($key)] = trim($val);
183 $providerInfo[$providerID]['api_params'] = $inputVals;
185 // Replace the api_type ID with the string value
186 $apiTypes = CRM_Core_OptionGroup
::values('sms_api_type');
187 $apiTypeId = $providerInfo[$providerID]['api_type'];
188 $providerInfo[$providerID]['api_type'] = CRM_Utils_Array
::value($apiTypeId, $apiTypes, $apiTypeId);
193 return CRM_Utils_Array
::value($returnParam, $providerInfo[$providerID], $returnDefaultString);
195 return $providerInfo[$providerID];