Merge pull request #21965 from civicrm/5.43
[civicrm-core.git] / CRM / Core / BAO / OpenID.php
CommitLineData
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 */
21class CRM_Core_BAO_OpenID extends CRM_Core_DAO_OpenID {
1d3cbc3c 22 use CRM_Contact_AccessTrait;
6a488035
TO
23
24 /**
6a5fec96 25 * Create or update OpenID record.
6a488035 26 *
6a0b768e 27 * @param array $params
a725865d 28 *
6a5fec96 29 * @return CRM_Core_DAO_OpenID
a725865d 30 *
31 * @throws \API_Exception
32 * @throws \CRM_Core_Exception
6a488035 33 */
9f8f650e 34 public static function create($params) {
3bec4854 35 CRM_Core_BAO_Block::handlePrimary($params, __CLASS__);
6a5fec96 36 return self::writeRecord($params);
6a488035
TO
37 }
38
9f8f650e 39 /**
40 * Create or update OpenID record.
41 *
42 * @deprecated
43 *
44 * @param array $params
45 *
46 * @return \CRM_Core_DAO|\CRM_Core_DAO_IM
47 * @throws \CRM_Core_Exception
48 * @throws \API_Exception
49 */
50 public static function add($params) {
51 CRM_Core_Error::deprecatedFunctionWarning('use the v4 api');
52 return self::create($params);
53 }
54
6a488035
TO
55 /**
56 * Given the list of params in the params array, fetch the object
57 * and store the values in the values array
58 *
6a0b768e
TO
59 * @param array $entityBlock
60 * Input parameters to find object.
6a488035
TO
61 *
62 * @return mixed
a725865d 63 * @throws \CRM_Core_Exception
6a488035 64 */
00be9182 65 public static function &getValues($entityBlock) {
6a488035
TO
66 return CRM_Core_BAO_Block::getValues('openid', $entityBlock);
67 }
68
6a488035
TO
69 /**
70 * Get all the openids for a specified contact_id, with the primary openid being first
71 *
6a0b768e
TO
72 * @param int $id
73 * The contact id.
6a488035 74 *
77b97be7
EM
75 * @param bool $updateBlankLocInfo
76 *
a6c01b45
CW
77 * @return array
78 * the array of openid's
6a488035 79 */
00be9182 80 public static function allOpenIDs($id, $updateBlankLocInfo = FALSE) {
6a488035
TO
81 if (!$id) {
82 return NULL;
83 }
84
85 $query = "
cbb7c7e0 86SELECT civicrm_openid.openid, civicrm_location_type.name as locationType, civicrm_openid.is_primary as is_primary,
87civicrm_openid.allowed_to_login as allowed_to_login, civicrm_openid.id as openid_id,
6a488035
TO
88civicrm_openid.location_type_id as locationTypeId
89FROM civicrm_contact
90LEFT JOIN civicrm_openid ON ( civicrm_openid.contact_id = civicrm_contact.id )
91LEFT JOIN civicrm_location_type ON ( civicrm_openid.location_type_id = civicrm_location_type.id )
92WHERE
93 civicrm_contact.id = %1
94ORDER BY
95 civicrm_openid.is_primary DESC, openid_id ASC ";
be2fb01f 96 $params = [1 => [$id, 'Integer']];
6a488035 97
be2fb01f 98 $openids = $values = [];
353ffa53
TO
99 $dao = CRM_Core_DAO::executeQuery($query, $params);
100 $count = 1;
6a488035 101 while ($dao->fetch()) {
be2fb01f 102 $values = [
6a488035
TO
103 'locationType' => $dao->locationType,
104 'is_primary' => $dao->is_primary,
105 'id' => $dao->openid_id,
106 'openid' => $dao->openid,
107 'locationTypeId' => $dao->locationTypeId,
108 'allowed_to_login' => $dao->allowed_to_login,
be2fb01f 109 ];
6a488035
TO
110
111 if ($updateBlankLocInfo) {
112 $openids[$count++] = $values;
113 }
114 else {
115 $openids[$dao->openid_id] = $values;
116 }
117 }
118 return $openids;
119 }
12445e1c
CW
120
121 /**
fe482240 122 * Call common delete function.
ad37ac8e 123 *
7a592535 124 * @see \CRM_Contact_BAO_Contact::on_hook_civicrm_post
ad37ac8e 125 *
7a592535
CW
126 * @param int $id
127 * @deprecated
ad37ac8e 128 * @return bool
12445e1c 129 */
00be9182 130 public static function del($id) {
7a592535 131 return (bool) self::deleteRecord(['id' => $id]);
12445e1c 132 }
96025800 133
6a488035 134}