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