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 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * This class contains function for Open Id | |
22 | */ | |
23 | class CRM_Core_BAO_OpenID extends CRM_Core_DAO_OpenID { | |
24 | ||
25 | /** | |
fe482240 | 26 | * Takes an associative array and adds OpenID. |
6a488035 | 27 | * |
6a0b768e TO |
28 | * @param array $params |
29 | * (reference ) an assoc array of name/value pairs. | |
6a488035 | 30 | * |
a6c01b45 CW |
31 | * @return object |
32 | * CRM_Core_BAO_OpenID object on success, null otherwise | |
6a488035 | 33 | */ |
00be9182 | 34 | public static function add(&$params) { |
6a488035 | 35 | $hook = empty($params['id']) ? 'create' : 'edit'; |
12445e1c | 36 | CRM_Utils_Hook::pre($hook, 'OpenID', CRM_Utils_Array::value('id', $params), $params); |
6a488035 TO |
37 | |
38 | $openId = new CRM_Core_DAO_OpenID(); | |
39 | $openId->copyValues($params); | |
40 | $openId->save(); | |
41 | ||
12445e1c | 42 | CRM_Utils_Hook::post($hook, 'OpenID', $openId->id, $openId); |
6a488035 TO |
43 | return $openId; |
44 | } | |
45 | ||
46 | /** | |
47 | * Given the list of params in the params array, fetch the object | |
48 | * and store the values in the values array | |
49 | * | |
6a0b768e TO |
50 | * @param array $entityBlock |
51 | * Input parameters to find object. | |
6a488035 TO |
52 | * |
53 | * @return mixed | |
6a488035 | 54 | */ |
00be9182 | 55 | public static function &getValues($entityBlock) { |
6a488035 TO |
56 | return CRM_Core_BAO_Block::getValues('openid', $entityBlock); |
57 | } | |
58 | ||
59 | /** | |
fe482240 | 60 | * Returns whether or not this OpenID is allowed to login. |
6a488035 | 61 | * |
6a0b768e TO |
62 | * @param string $identity_url |
63 | * The OpenID to check. | |
6a488035 | 64 | * |
8d7a9d07 | 65 | * @return bool |
6a488035 | 66 | */ |
00be9182 | 67 | public static function isAllowedToLogin($identity_url) { |
6a488035 TO |
68 | $openId = new CRM_Core_DAO_OpenID(); |
69 | $openId->openid = $identity_url; | |
70 | if ($openId->find(TRUE)) { | |
71 | return $openId->allowed_to_login == 1; | |
72 | } | |
73 | return FALSE; | |
74 | } | |
75 | ||
76 | /** | |
77 | * Get all the openids for a specified contact_id, with the primary openid being first | |
78 | * | |
6a0b768e TO |
79 | * @param int $id |
80 | * The contact id. | |
6a488035 | 81 | * |
77b97be7 EM |
82 | * @param bool $updateBlankLocInfo |
83 | * | |
a6c01b45 CW |
84 | * @return array |
85 | * the array of openid's | |
6a488035 | 86 | */ |
00be9182 | 87 | public static function allOpenIDs($id, $updateBlankLocInfo = FALSE) { |
6a488035 TO |
88 | if (!$id) { |
89 | return NULL; | |
90 | } | |
91 | ||
92 | $query = " | |
cbb7c7e0 | 93 | SELECT civicrm_openid.openid, civicrm_location_type.name as locationType, civicrm_openid.is_primary as is_primary, |
94 | civicrm_openid.allowed_to_login as allowed_to_login, civicrm_openid.id as openid_id, | |
6a488035 TO |
95 | civicrm_openid.location_type_id as locationTypeId |
96 | FROM civicrm_contact | |
97 | LEFT JOIN civicrm_openid ON ( civicrm_openid.contact_id = civicrm_contact.id ) | |
98 | LEFT JOIN civicrm_location_type ON ( civicrm_openid.location_type_id = civicrm_location_type.id ) | |
99 | WHERE | |
100 | civicrm_contact.id = %1 | |
101 | ORDER BY | |
102 | civicrm_openid.is_primary DESC, openid_id ASC "; | |
be2fb01f | 103 | $params = [1 => [$id, 'Integer']]; |
6a488035 | 104 | |
be2fb01f | 105 | $openids = $values = []; |
353ffa53 TO |
106 | $dao = CRM_Core_DAO::executeQuery($query, $params); |
107 | $count = 1; | |
6a488035 | 108 | while ($dao->fetch()) { |
be2fb01f | 109 | $values = [ |
6a488035 TO |
110 | 'locationType' => $dao->locationType, |
111 | 'is_primary' => $dao->is_primary, | |
112 | 'id' => $dao->openid_id, | |
113 | 'openid' => $dao->openid, | |
114 | 'locationTypeId' => $dao->locationTypeId, | |
115 | 'allowed_to_login' => $dao->allowed_to_login, | |
be2fb01f | 116 | ]; |
6a488035 TO |
117 | |
118 | if ($updateBlankLocInfo) { | |
119 | $openids[$count++] = $values; | |
120 | } | |
121 | else { | |
122 | $openids[$dao->openid_id] = $values; | |
123 | } | |
124 | } | |
125 | return $openids; | |
126 | } | |
12445e1c CW |
127 | |
128 | /** | |
fe482240 | 129 | * Call common delete function. |
ad37ac8e | 130 | * |
131 | * @param int $id | |
132 | * | |
133 | * @return bool | |
12445e1c | 134 | */ |
00be9182 | 135 | public static function del($id) { |
a65e2e55 | 136 | return CRM_Contact_BAO_Contact::deleteObjectWithPrimary('OpenID', $id); |
12445e1c | 137 | } |
96025800 | 138 | |
6a488035 | 139 | } |