3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
35 * Form helper class for an OpenID object.
37 class CRM_Contact_Form_Inline_OpenID
extends CRM_Contact_Form_Inline
{
40 * Ims of the contact that is been viewed.
42 private $_openids = [];
45 * No of openid blocks for inline edit.
47 private $_blockCount = 6;
52 public function preProcess() {
55 //get all the existing openids
56 $openid = new CRM_Core_BAO_OpenID();
57 $openid->contact_id
= $this->_contactId
;
59 $this->_openids
= CRM_Core_BAO_Block
::retrieveBlock($openid, NULL);
63 * Build the form object elements for openID object.
65 public function buildQuickForm() {
66 parent
::buildQuickForm();
68 $totalBlocks = $this->_blockCount
;
69 $actualBlockCount = 1;
70 if (count($this->_openids
) > 1) {
71 $actualBlockCount = $totalBlocks = count($this->_openids
);
72 if ($totalBlocks < $this->_blockCount
) {
73 $additionalBlocks = $this->_blockCount
- $totalBlocks;
74 $totalBlocks +
= $additionalBlocks;
82 $this->assign('actualBlockCount', $actualBlockCount);
83 $this->assign('totalBlocks', $totalBlocks);
85 $this->applyFilter('__ALL__', 'trim');
87 for ($blockId = 1; $blockId < $totalBlocks; $blockId++
) {
88 CRM_Contact_Form_Edit_OpenID
::buildQuickForm($this, $blockId, TRUE);
91 $this->addFormRule(['CRM_Contact_Form_Inline_OpenID', 'formRule']);
95 * Global validation rules for the form.
97 * @param array $fields
98 * Posted values of the form.
99 * @param array $errors
100 * List of errors to be posted back to the form.
104 public static function formRule($fields, $errors) {
105 $hasData = $hasPrimary = $errors = [];
106 if (!empty($fields['openid']) && is_array($fields['openid'])) {
107 foreach ($fields['openid'] as $instance => $blockValues) {
108 $dataExists = CRM_Contact_Form_Contact
::blockDataExists($blockValues);
111 $hasData[] = $instance;
112 if (!empty($blockValues['is_primary'])) {
113 $hasPrimary[] = $instance;
114 if (!$primaryID && !empty($blockValues['openid'])) {
115 $primaryID = $blockValues['openid'];
121 if (empty($hasPrimary) && !empty($hasData)) {
122 $errors["openid[1][is_primary]"] = ts('One OpenID should be marked as primary.');
125 if (count($hasPrimary) > 1) {
126 $errors["openid[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one OpenID can be marked as primary.');
133 * Set defaults for the form.
137 public function setDefaultValues() {
139 if (!empty($this->_openids
)) {
140 foreach ($this->_openids
as $id => $value) {
141 $defaults['openid'][$id] = $value;
145 // get the default location type
146 $locationType = CRM_Core_BAO_LocationType
::getDefault();
147 $defaults['openid'][1]['location_type_id'] = $locationType->id
;
155 public function postProcess() {
156 $params = $this->exportValues();
158 // Process / save openID
159 $params['contact_id'] = $this->_contactId
;
160 $params['updateBlankLocInfo'] = TRUE;
161 $params['openid']['isIdSet'] = TRUE;
162 foreach ($this->_openids
as $count => $value) {
163 if (!empty($value['id']) && isset($params['openid'][$count])) {
164 $params['openid'][$count]['id'] = $value['id'];
167 CRM_Core_BAO_Block
::create('openid', $params);