Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * This class contains function for Open Id | |
20 | */ | |
21 | class CRM_Core_BAO_OpenID extends CRM_Core_DAO_OpenID { | |
22 | ||
23 | /** | |
6a5fec96 | 24 | * Create or update OpenID record. |
6a488035 | 25 | * |
6a0b768e | 26 | * @param array $params |
a725865d | 27 | * |
6a5fec96 | 28 | * @return CRM_Core_DAO_OpenID |
a725865d | 29 | * |
30 | * @throws \API_Exception | |
31 | * @throws \CRM_Core_Exception | |
6a488035 | 32 | */ |
9f8f650e | 33 | public static function create($params) { |
3bec4854 | 34 | CRM_Core_BAO_Block::handlePrimary($params, __CLASS__); |
6a5fec96 | 35 | return self::writeRecord($params); |
6a488035 TO |
36 | } |
37 | ||
9f8f650e | 38 | /** |
39 | * Create or update OpenID record. | |
40 | * | |
41 | * @deprecated | |
42 | * | |
43 | * @param array $params | |
44 | * | |
45 | * @return \CRM_Core_DAO|\CRM_Core_DAO_IM | |
46 | * @throws \CRM_Core_Exception | |
47 | * @throws \API_Exception | |
48 | */ | |
49 | public static function add($params) { | |
50 | CRM_Core_Error::deprecatedFunctionWarning('use the v4 api'); | |
51 | return self::create($params); | |
52 | } | |
53 | ||
6a488035 TO |
54 | /** |
55 | * Given the list of params in the params array, fetch the object | |
56 | * and store the values in the values array | |
57 | * | |
6a0b768e TO |
58 | * @param array $entityBlock |
59 | * Input parameters to find object. | |
6a488035 TO |
60 | * |
61 | * @return mixed | |
a725865d | 62 | * @throws \CRM_Core_Exception |
6a488035 | 63 | */ |
00be9182 | 64 | public static function &getValues($entityBlock) { |
6a488035 TO |
65 | return CRM_Core_BAO_Block::getValues('openid', $entityBlock); |
66 | } | |
67 | ||
6a488035 TO |
68 | /** |
69 | * Get all the openids for a specified contact_id, with the primary openid being first | |
70 | * | |
6a0b768e TO |
71 | * @param int $id |
72 | * The contact id. | |
6a488035 | 73 | * |
77b97be7 EM |
74 | * @param bool $updateBlankLocInfo |
75 | * | |
a6c01b45 CW |
76 | * @return array |
77 | * the array of openid's | |
6a488035 | 78 | */ |
00be9182 | 79 | public static function allOpenIDs($id, $updateBlankLocInfo = FALSE) { |
6a488035 TO |
80 | if (!$id) { |
81 | return NULL; | |
82 | } | |
83 | ||
84 | $query = " | |
cbb7c7e0 | 85 | SELECT civicrm_openid.openid, civicrm_location_type.name as locationType, civicrm_openid.is_primary as is_primary, |
86 | civicrm_openid.allowed_to_login as allowed_to_login, civicrm_openid.id as openid_id, | |
6a488035 TO |
87 | civicrm_openid.location_type_id as locationTypeId |
88 | FROM civicrm_contact | |
89 | LEFT JOIN civicrm_openid ON ( civicrm_openid.contact_id = civicrm_contact.id ) | |
90 | LEFT JOIN civicrm_location_type ON ( civicrm_openid.location_type_id = civicrm_location_type.id ) | |
91 | WHERE | |
92 | civicrm_contact.id = %1 | |
93 | ORDER BY | |
94 | civicrm_openid.is_primary DESC, openid_id ASC "; | |
be2fb01f | 95 | $params = [1 => [$id, 'Integer']]; |
6a488035 | 96 | |
be2fb01f | 97 | $openids = $values = []; |
353ffa53 TO |
98 | $dao = CRM_Core_DAO::executeQuery($query, $params); |
99 | $count = 1; | |
6a488035 | 100 | while ($dao->fetch()) { |
be2fb01f | 101 | $values = [ |
6a488035 TO |
102 | 'locationType' => $dao->locationType, |
103 | 'is_primary' => $dao->is_primary, | |
104 | 'id' => $dao->openid_id, | |
105 | 'openid' => $dao->openid, | |
106 | 'locationTypeId' => $dao->locationTypeId, | |
107 | 'allowed_to_login' => $dao->allowed_to_login, | |
be2fb01f | 108 | ]; |
6a488035 TO |
109 | |
110 | if ($updateBlankLocInfo) { | |
111 | $openids[$count++] = $values; | |
112 | } | |
113 | else { | |
114 | $openids[$dao->openid_id] = $values; | |
115 | } | |
116 | } | |
117 | return $openids; | |
118 | } | |
12445e1c CW |
119 | |
120 | /** | |
fe482240 | 121 | * Call common delete function. |
ad37ac8e | 122 | * |
123 | * @param int $id | |
124 | * | |
125 | * @return bool | |
12445e1c | 126 | */ |
00be9182 | 127 | public static function del($id) { |
a65e2e55 | 128 | return CRM_Contact_BAO_Contact::deleteObjectWithPrimary('OpenID', $id); |
12445e1c | 129 | } |
96025800 | 130 | |
6a488035 | 131 | } |