3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
35 class CRM_SMS_BAO_Provider
extends CRM_SMS_DAO_Provider
{
37 function __construct() {
38 parent
::__construct();
41 static function activeProviderCount() {
42 $activeProviders = CRM_Core_DAO
::singleValueQuery('SELECT MAX(id) FROM civicrm_sms_provider WHERE is_active = 1');
43 return $activeProviders;
47 * Retrieves the list of providers from the database
50 * $selectArr array of coloumns to fetch
51 * $getActive boolean to get active providers
53 static function getProviders($selectArr = NULL, $filter = NULL, $getActive = TRUE, $orderBy = 'id') {
57 $dao = new CRM_SMS_DAO_Provider();
58 if ($filter && !array_key_exists('is_active', $filter) && $getActive) {
61 if ($filter && is_array($filter)) {
62 foreach ($filter as $key => $value) {
66 if ($selectArr && is_array($selectArr)) {
67 $select = implode(',', $selectArr);
68 $dao->selectAdd($select);
70 $dao->orderBy($orderBy);
72 while ($dao->fetch()) {
73 CRM_Core_DAO
::storeValues($dao, $temp);
79 static function saveRecord($values) {
80 $dao = new CRM_SMS_DAO_Provider();
81 $dao->copyValues($values);
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);
94 static function setIsActive($id, $is_active) {
95 return CRM_Core_DAO
::setFieldValue('CRM_SMS_DAO_Provider', $id, 'is_active', $is_active);
98 static function del($providerID) {
100 CRM_Core_Error
::fatal(ts('Invalid value passed to delete function'));
103 $dao = new CRM_SMS_DAO_Provider();
104 $dao->id
= $providerID;
105 if (!$dao->find(TRUE)) {
111 public static function getProviderInfo($providerID, $returnParam = NULL, $returnDefaultString = NULL) {
112 static $providerInfo = array();
114 if (!array_key_exists($providerID, $providerInfo)) {
115 $providerInfo[$providerID] = array();
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) {
125 list($key, $val) = explode("=", $value);
126 $inputVals[trim($key)] = trim($val);
129 $providerInfo[$providerID]['api_params'] = $inputVals;
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);
139 return CRM_Utils_Array
::value($returnParam, $providerInfo[$providerID], $returnDefaultString);
141 return $providerInfo[$providerID];