* Base class for UF system integrations
*/
abstract class CRM_Utils_System_Base {
+
/**
- * Deprecated property to check if this is a drupal install. The correct method is to have functions on the UF classes for all UF specific
+ * Deprecated property to check if this is a drupal install.
+ *
+ * The correct method is to have functions on the UF classes for all UF specific
* functions and leave the codebase oblivious to the type of CMS
*
* @deprecated
/**
* Load user into session.
*
- * @param $user
+ * @param obj $user
*
* @return bool
*/
}
/**
- * Immediately stop script execution and display a 401 "Access Denied" page
+ * Immediately stop script execution and display a 401 "Access Denied" page.
*/
public function permissionDenied() {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
/**
- * Immediately stop script execution, log out the user and redirect to the home page
+ * Immediately stop script execution, log out the user and redirect to the home page.
*
* @deprecated
* This function should be removed in favor of linking to the CMS's logout page
}
/**
- * If we are using a theming system, invoke theme, else just print the
- * content
+ * If we are using a theming system, invoke theme, else just print the content.
*
* @param string $content
* The content that will be themed.
print theme('maintenance_page', array('content' => $content));
exit();
}
- $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints
+ // TODO: Figure out why D7 returns but everyone else prints
+ $ret = TRUE;
}
$out = $content;
public abstract function getLoginURL($destination = '');
/**
- * Get the login destination string. When this is passed in the
- * URL the user will be directed to it after filling in the CMS form
+ * Get the login destination string.
+ *
+ * When this is passed in the URL the user will be directed to it after filling in the CMS form.
*
* @param CRM_Core_Form $form
* Form object representing the 'current' form - to which the user will be returned.
+ *
* @return string|NULL
* destination value for URL
*/
}
/**
- * Reset any system caches that may be required for proper CiviCRM
- * integration.
+ * Reset any system caches that may be required for proper CiviCRM integration.
*/
public function flush() {
// nullop by default
}
/**
- * Flush css/js caches
+ * Flush css/js caches.
*/
public function clearResourceCache() {
// nullop by default
* Note: This function is not to be called directly
* @see CRM_Core_Region::render()
*
- * @param $url : string, absolute path to file
+ * @param string $url absolute path to file
* @param string $region
* location within the document: 'html-header', 'page-header', 'page-footer'.
*
* Note: This function is not to be called directly
* @see CRM_Core_Region::render()
*
- * @param $code : string, javascript code
+ * @param string $code javascript code
* @param string $region
* location within the document: 'html-header', 'page-header', 'page-footer'.
*
* Note: This function is not to be called directly
* @see CRM_Core_Region::render()
*
- * @param $url : string, absolute path to file
+ * @param string $url absolute path to file
* @param string $region
* location within the document: 'html-header', 'page-header', 'page-footer'.
*
* Note: This function is not to be called directly
* @see CRM_Core_Region::render()
*
- * @param $code : string, css code
+ * @param string $code css code
* @param string $region
* location within the document: 'html-header', 'page-header', 'page-footer'.
*
}
/**
- * Perform any post login activities required by the CMS -
+ * Perform any post login activities required by the CMS.
+ *
* e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
* calls hook_user op 'login' and generates a new session.
*
}
/**
- * Get Unique Identifier from UserFramework system (CMS)
+ * Get Unique Identifier from UserFramework system (CMS).
+ *
* @param object $user
* Object as described by the User Framework.
+ *
* @return mixed
- * $uniqueIdentifer Unique identifier from the user Framework system
+ * Unique identifier from the user Framework system
*/
public function getUniqueIdentifierFromUserObject($user) {
return NULL;
}
/**
- * Get User ID from UserFramework system (CMS)
+ * Get User ID from UserFramework system (CMS).
+ *
* @param object $user
+ *
* Object as described by the User Framework.
* @return null|int
*/
return NULL;
}
+ /**
+ * Get an array of user details for a contact, containing at minimum the user ID & name.
+ *
+ * @param int $contactID
+ *
+ * @return array
+ * CMS user details including
+ * - id
+ * - name (ie the system user name.
+ */
+ public function getUser($contactID) {
+ $ufMatch = civicrm_api3('UFMatch', 'getsingle', array(
+ 'contact_id' => $contactID,
+ 'domain_id' => CRM_Core_Config::domainID(),
+ ));
+ return array(
+ 'id' => $ufMatch['uf_id'],
+ 'name' => $ufMatch['uf_name'],
+ );
+ }
+
/**
* Get currently logged in user uf id.
*
}
/**
- * Return a UFID (user account ID from the UserFramework / CMS system being based on the user object
- * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
- * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
- * the function
+ * Return a UFID (user account ID from the UserFramework / CMS system.
+ *
+ * ID is based on the user object passed, defaulting to the logged in user if not passed.
+ *
+ * Note that ambiguous situation occurs in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would
+ * seem to be resolving the user id before calling the function.
*
* Note there is already a function getUFId which takes $username as a param - we could add $user
- * as a second param to it but it seems messy - just overloading it because the name is taken
+ * as a second param to it but it seems messy - just overloading it because the name is taken.
+ *
* @param object $user
+ *
* @return int
- * $ufid - user ID of UF System
+ * User ID of UF System
*/
public function getBestUFID($user = NULL) {
if ($user) {
}
/**
- * Return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
- * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
- * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
- * the function
+ * Return a unique identifier (usually an email address or username) from the UserFramework / CMS system.
+ *
+ * This is based on the user object passed, defaulting to the logged in user if not passed.
+ *
+ * Note that ambiguous situation occurs in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be
+ * resolving the unique identifier before calling the function.
*
* @param object $user
+ *
* @return string
* unique identifier from the UF System
*/
/**
* Get Url to view user record.
+ *
* @param int $contactID
* Contact ID.
*
/**
* Is the current user permitted to add a user.
+ *
* @return bool
*/
public function checkPermissionAddUser() {
/**
* Output code from error function.
+ *
* @param string $content
*/
public function outputError($content) {
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * This api exposes CiviCRM the user framework user account.
+ *
+ * @package CiviCRM_APIv3
+ */
+
+/**
+ * Get details about the CMS User entity.
+ *
+ * @param array $params
+ *
+ * @return array
+ */
+function civicrm_api3_user_get($params) {
+ if (empty($params['contact_id'])) {
+ $params['contact_id'] = civicrm_api3('UFMatch', 'getvalue', array(
+ 'uf_id' => $params['id'],
+ 'domain_id' => CRM_Core_Config::domainID(),
+ 'return' => 'contact_id',
+ ));
+ }
+ $result = CRM_Core_Config::singleton()->userSystem->getUser($params['contact_id']);
+ $result['contact_id'] = $params['contact_id'];
+ return civicrm_api3_create_success(
+ array($result['id'] => $result),
+ $params,
+ 'user',
+ 'get'
+ );
+
+}
+
+/**
+ * Adjust Metadata for Get action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $params
+ * Array of parameters determined by getfields.
+ */
+function _civicrm_api3_user_get_spec(&$params) {
+ // At this stage contact-id is required - we may be able to loosen this.
+ $params['contact_id'] = array(
+ 'title' => 'Contact ID',
+ 'type' => CRM_Utils_Type::T_INT,
+ 'api.required' => 1,
+ );
+ $params['id'] = array(
+ 'title' => 'CMS User ID',
+ 'type' => CRM_Utils_Type::T_INT,
+ );
+ $params['name'] = array(
+ 'title' => 'Username',
+ 'type' => CRM_Utils_Type::T_STRING,
+ );
+}