3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * form helper class for an OpenID object
39 class CRM_Contact_Form_Inline_OpenID
extends CRM_Contact_Form_Inline
{
42 * Ims of the contact that is been viewed
44 private $_openids = array();
47 * No of openid blocks for inline edit
49 private $_blockCount = 6;
54 public function preProcess() {
57 //get all the existing openids
58 $openid = new CRM_Core_BAO_OpenID();
59 $openid->contact_id
= $this->_contactId
;
61 $this->_openids
= CRM_Core_BAO_Block
::retrieveBlock($openid, NULL);
65 * Build the form object elements for openID object
69 public function buildQuickForm() {
70 parent
::buildQuickForm();
72 $totalBlocks = $this->_blockCount
;
73 $actualBlockCount = 1;
74 if (count($this->_openids
) > 1) {
75 $actualBlockCount = $totalBlocks = count($this->_openids
);
76 if ($totalBlocks < $this->_blockCount
) {
77 $additionalBlocks = $this->_blockCount
- $totalBlocks;
78 $totalBlocks +
= $additionalBlocks;
86 $this->assign('actualBlockCount', $actualBlockCount);
87 $this->assign('totalBlocks', $totalBlocks);
89 $this->applyFilter('__ALL__', 'trim');
91 for ($blockId = 1; $blockId < $totalBlocks; $blockId++
) {
92 CRM_Contact_Form_Edit_OpenID
::buildQuickForm($this, $blockId, TRUE);
95 $this->addFormRule(array('CRM_Contact_Form_Inline_OpenID', 'formRule'));
99 * Global validation rules for the form
101 * @param array $fields posted values of the form
102 * @param array $errors list of errors to be posted back to the form
104 * @return array $errors@static
106 public static function formRule($fields, $errors) {
107 $hasData = $hasPrimary = $errors = array();
108 if (!empty($fields['openid']) && is_array($fields['openid'])) {
109 foreach ($fields['openid'] as $instance => $blockValues) {
110 $dataExists = CRM_Contact_Form_Contact
::blockDataExists($blockValues);
113 $hasData[] = $instance;
114 if (!empty($blockValues['is_primary'])) {
115 $hasPrimary[] = $instance;
116 if (!$primaryID && !empty($blockValues['openid'])) {
117 $primaryID = $blockValues['openid'];
123 if (empty($hasPrimary) && !empty($hasData)) {
124 $errors["openid[1][is_primary]"] = ts('One OpenID should be marked as primary.');
127 if (count($hasPrimary) > 1) {
128 $errors["openid[".array_pop($hasPrimary)."][is_primary]"] = ts('Only one OpenID can be marked as primary.');
135 * Set defaults for the form
139 public function setDefaultValues() {
141 if (!empty($this->_openids
)) {
142 foreach ($this->_openids
as $id => $value) {
143 $defaults['openid'][$id] = $value;
147 // get the default location type
148 $locationType = CRM_Core_BAO_LocationType
::getDefault();
149 $defaults['openid'][1]['location_type_id'] = $locationType->id
;
159 public function postProcess() {
160 $params = $this->exportValues();
162 // Process / save openID
163 $params['contact_id'] = $this->_contactId
;
164 $params['updateBlankLocInfo'] = TRUE;
165 CRM_Core_BAO_Block
::create('openid', $params);