本文整理汇总了PHP中CRM_Utils_Array类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Array类的具体用法?PHP CRM_Utils_Array怎么用?PHP CRM_Utils_Array使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Utils_Array类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: route
/**
* @param array $cxn
* @param string $entity
* @param string $action
* @param array $params
* @return mixed
*/
public static function route($cxn, $entity, $action, $params)
{
$SUPER_PERM = array('administer CiviCRM');
require_once 'api/v3/utils.php';
// FIXME: Shouldn't the X-Forwarded-Proto check be part of CRM_Utils_System::isSSL()?
if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL') && !CRM_Utils_System::isSSL() && strtolower(CRM_Utils_Array::value('X_FORWARDED_PROTO', CRM_Utils_System::getRequestHeaders())) != 'https') {
return civicrm_api3_create_error('System policy requires HTTPS.');
}
// Note: $cxn and cxnId are authenticated before router is called.
$dao = new CRM_Cxn_DAO_Cxn();
$dao->cxn_id = $cxn['cxnId'];
if (empty($cxn['cxnId']) || !$dao->find(TRUE) || !$dao->cxn_id) {
return civicrm_api3_create_error('Failed to lookup connection authorizations.');
}
if (!$dao->is_active) {
return civicrm_api3_create_error('Connection is inactive.');
}
if (!is_string($entity) || !is_string($action) || !is_array($params)) {
return civicrm_api3_create_error('API parameters are malformed.');
}
if (empty($cxn['perm']['api']) || !is_array($cxn['perm']['api']) || empty($cxn['perm']['grant']) || !(is_array($cxn['perm']['grant']) || is_string($cxn['perm']['grant']))) {
return civicrm_api3_create_error('Connection has no permissions.');
}
$whitelist = \Civi\API\WhitelistRule::createAll($cxn['perm']['api']);
\Civi::service('dispatcher')->addSubscriber(new \Civi\API\Subscriber\WhitelistSubscriber($whitelist));
CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp();
if ($cxn['perm']['grant'] === '*') {
CRM_Core_Config::singleton()->userPermissionTemp->grant($SUPER_PERM);
} else {
CRM_Core_Config::singleton()->userPermissionTemp->grant($cxn['perm']['grant']);
}
$params['check_permissions'] = 'whitelist';
return civicrm_api($entity, $action, $params);
}
示例2: run
function run()
{
session_start();
require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton();
require_once 'Console/Getopt.php';
$shortOptions = "n:p:k:pre";
$longOptions = array('name=', 'pass=', 'key=', 'prefix=');
$getopt = new Console_Getopt();
$args = $getopt->readPHPArgv();
array_shift($args);
list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);
$vars = array('name' => 'n', 'pass' => 'p', 'key' => 'k', 'prefix' => 'pre');
foreach ($vars as $var => $short) {
${$var} = NULL;
foreach ($valid as $v) {
if ($v[0] == $short || $v[0] == "--{$var}") {
${$var} = $v[1];
break;
}
}
if (!${$var}) {
${$var} = CRM_Utils_Array::value($var, $_REQUEST);
}
$_REQUEST[$var] = ${$var};
}
// this does not return on failure
// require_once 'CRM/Utils/System.php';
CRM_Utils_System::authenticateScript(TRUE, $name, $pass);
//log the execution of script
CRM_Core_Error::debug_log_message('NormalizePhone.php');
// process all phones
processPhones($config, $prefix);
}
示例3: where
/**
* Method to build where part of query
*/
function where()
{
$clauses = array();
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('filters', $table)) {
foreach ($table['filters'] as $fieldName => $field) {
$clause = NULL;
$op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
// if user id value contains 0 for current user, replace value with current user
if ($fieldName == 'account_id') {
foreach ($this->_params['account_id_value'] as $paramKey => $userIdValue) {
if ($userIdValue == 0) {
$session = CRM_Core_Session::singleton();
$this->_params['account_id_value'][$paramKey] = $session->get('userID');
}
}
}
$clause = $this->whereClause($field, $op, CRM_Utils_Array::value("{$fieldName}_value", $this->_params), CRM_Utils_Array::value("{$fieldName}_min", $this->_params), CRM_Utils_Array::value("{$fieldName}_max", $this->_params));
if (!empty($clause)) {
$clauses[] = $clause;
}
}
}
}
if (empty($clauses)) {
$this->_where = "";
} else {
$this->_where = "WHERE " . implode(' AND ', $clauses);
}
}
示例4: select
function select()
{
$select = array();
$this->_columnHeaders = array();
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
if ($tableName == 'civicrm_email') {
$this->_emailField = TRUE;
} elseif ($tableName == 'civicrm_phone') {
$this->_phoneField = TRUE;
} elseif ($tableName == 'civicrm_country') {
$this->_countryField = TRUE;
}
$alias = "{$tableName}_{$fieldName}";
$select[] = "{$field['dbAlias']} as {$alias}";
$this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
$this->_selectAliases[] = $alias;
}
}
}
}
$this->_select = "SELECT " . implode(', ', $select) . " ";
}
示例5: setDefaultValues
/**
* Set default values for the form.
* The default values are retrieved from the database.
*
*
* @return void
*/
public function setDefaultValues()
{
$defaults = $this->_values;
if (empty($defaults['pdf_format_id'])) {
$defaults['pdf_format_id'] = 'null';
}
$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $defaults);
$this->assign('workflow_id', $this->_workflow_id);
if ($this->_action & CRM_Core_Action::ADD) {
$defaults['is_active'] = 1;
//set the context for redirection after form submit or cancel
$session = CRM_Core_Session::singleton();
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));
}
// FIXME: we need to fix the Cancel button here as we don’t know whether it’s a workflow template in buildQuickForm()
if ($this->_action & CRM_Core_Action::UPDATE) {
if ($this->_workflow_id) {
$selectedChild = 'workflow';
} else {
$selectedChild = 'user';
}
$cancelURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', "selectedChild={$selectedChild}&reset=1");
$cancelURL = str_replace('&', '&', $cancelURL);
$this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"))));
}
return $defaults;
}
示例6: importableFields
static function importableFields($contactType = 'HRJobContractRevision', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE)
{
if (empty($contactType)) {
$contactType = 'HRJobContractRevision';
}
$cacheKeyString = "";
$cacheKeyString .= $status ? '_1' : '_0';
$cacheKeyString .= $showAll ? '_1' : '_0';
$cacheKeyString .= $isProfile ? '_1' : '_0';
$cacheKeyString .= $checkPermission ? '_1' : '_0';
$fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields);
if (!$fields) {
$fields = CRM_Hrjobcontract_DAO_HRJobContractRevision::import();
$fields = array_merge($fields, CRM_Hrjobcontract_DAO_HRJobContractRevision::import());
//Sorting fields in alphabetical order(CRM-1507)
$fields = CRM_Utils_Array::crmArraySortByField($fields, 'title');
$fields = CRM_Utils_Array::index(array('name'), $fields);
CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString);
}
self::$_importableFields[$cacheKeyString] = $fields;
if (!$isProfile) {
$fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]);
}
return $fields;
}
示例7: buildQuickForm
/**
* Function to build the form
*
* @return None
* @access public
*/
static function buildQuickForm(&$form)
{
// required for subsequent AJAX requests.
$ajaxRequestBlocks = array();
$generateAjaxRequest = 0;
//build 1 instance of all blocks, without using ajax ...
foreach ($form->_blocks as $blockName => $label) {
require_once str_replace('_', DIRECTORY_SEPARATOR, 'CRM_Contact_Form_Edit_' . $blockName) . '.php';
$name = strtolower($blockName);
$instances = array(1);
if (CRM_Utils_Array::value($name, $_POST) && is_array($_POST[$name])) {
$instances = array_keys($_POST[$name]);
} elseif (property_exists($form, '_values') && CRM_Utils_Array::value($name, $form->_values) && is_array($form->_values[$name])) {
$instances = array_keys($form->_values[$name]);
}
foreach ($instances as $instance) {
if ($instance == 1) {
$form->assign('addBlock', FALSE);
$form->assign('blockId', $instance);
} else {
//we are going to build other block instances w/ AJAX
$generateAjaxRequest++;
$ajaxRequestBlocks[$blockName][$instance] = TRUE;
}
$form->set($blockName . '_Block_Count', $instance);
$formName = 'CRM_Contact_Form_Edit_' . $blockName;
$formName::buildQuickForm($form);
}
}
//assign to generate AJAX request for building extra blocks.
$form->assign('generateAjaxRequest', $generateAjaxRequest);
$form->assign('ajaxRequestBlocks', $ajaxRequestBlocks);
}
示例8: postProcess
/**
* Function to process the form
*
* @access public
* @return None
*/
public function postProcess()
{
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_LocationType::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'));
return;
}
// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, false);
// action is taken depending upon the mode
$locationType =& new CRM_Core_DAO_LocationType();
$locationType->name = $params['name'];
$locationType->vcard_name = $params['vcard_name'];
$locationType->description = $params['description'];
$locationType->is_active = $params['is_active'];
$locationType->is_default = $params['is_default'];
if ($params['is_default']) {
$query = "UPDATE civicrm_location_type SET is_default = 0";
CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$locationType->id = $this->_id;
}
$locationType->save();
CRM_Core_Session::setStatus(ts('The location type \'%1\' has been saved.', array(1 => $locationType->name)));
}
示例9: getBatchList
/**
* Retrieve records.
*/
public static function getBatchList()
{
$sortMapper = array(0 => 'batch.title', 1 => 'batch.type_id', 2 => '', 3 => 'batch.total', 4 => 'batch.status_id', 5 => '');
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
$offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
$rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
$sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
$sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
$context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL;
$params = $_REQUEST;
if ($sort && $sortOrder) {
$params['sortBy'] = $sort . ' ' . $sortOrder;
}
$params['page'] = $offset / $rowCount + 1;
$params['rp'] = $rowCount;
if ($context != 'financialBatch') {
// data entry status batches
$params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status', 'Data Entry', 'name');
}
$params['context'] = $context;
// get batch list
$batches = CRM_Batch_BAO_Batch::getBatchListSelector($params);
$iFilteredTotal = $iTotal = $params['total'];
if ($context == 'financialBatch') {
$selectorElements = array('check', 'batch_name', 'payment_instrument', 'item_count', 'total', 'status', 'created_by', 'links');
} else {
$selectorElements = array('batch_name', 'type', 'item_count', 'total', 'status', 'created_by', 'links');
}
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
示例10: postProcess
/**
* Process the form submission.
*/
public function postProcess()
{
CRM_Utils_System::flushCache('CRM_Core_DAO_LocationType');
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_LocationType::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success');
return;
}
// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
// action is taken depending upon the mode
$locationType = new CRM_Core_DAO_LocationType();
$locationType->name = $params['name'];
$locationType->display_name = $params['display_name'];
$locationType->vcard_name = $params['vcard_name'];
$locationType->description = $params['description'];
$locationType->is_active = $params['is_active'];
$locationType->is_default = $params['is_default'];
if ($params['is_default']) {
$query = "UPDATE civicrm_location_type SET is_default = 0";
CRM_Core_DAO::executeQuery($query);
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$locationType->id = $this->_id;
}
$locationType->save();
CRM_Core_Session::setStatus(ts("The location type '%1' has been saved.", array(1 => $locationType->name)), ts('Saved'), 'success');
}
示例11: selectUnselectRelationships
/**
* Used to store selected contacts across multiple pages in advanced search.
*/
public static function selectUnselectRelationships()
{
$name = CRM_Utils_Array::value('name', $_REQUEST);
$cacheKey = CRM_Utils_Array::value('qfKey', $_REQUEST);
$state = CRM_Utils_Array::value('state', $_REQUEST, 'checked');
$variableType = CRM_Utils_Array::value('variableType', $_REQUEST, 'single');
$actionToPerform = CRM_Utils_Array::value('action', $_REQUEST, 'select');
if ($variableType == 'multiple') {
// action post value only works with multiple type variable
if ($name) {
//multiple names like mark_x_1-mark_x_2 where 1,2 are cids
$elements = explode('-', $name);
foreach ($elements as $key => $element) {
$elements[$key] = self::_convertToId($element);
}
CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, $elements, 'civicrm_relationship');
} else {
CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, NULL, 'civicrm_relationship');
}
} elseif ($variableType == 'single') {
$cId = self::_convertToId($name);
$action = $state == 'checked' ? 'select' : 'unselect';
CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $action, $cId, 'civicrm_relationship');
}
$contactIds = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, 'get', 'civicrm_relationship');
$countSelectionCids = count($contactIds[$cacheKey]);
$arrRet = array('getCount' => $countSelectionCids);
CRM_Utils_JSON::output($arrRet);
}
示例12: select
function select()
{
$select = array();
$this->_columnHeaders = array();
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
if ($tableName == 'civicrm_hrjobcontract_leave' && $fieldName == 'leave_leave_type') {
$select[] = "GROUP_CONCAT(DISTINCT hrjobcontract_leave_civireport.leave_type SEPARATOR ',') AS {$tableName}_{$fieldName}";
} elseif ($tableName == 'civicrm_hrjobcontract_leave' && $fieldName == 'leave_leave_amount') {
$select[] = "GROUP_CONCAT(DISTINCT hrjobcontract_leave_civireport.leave_type , ':', hrjobcontract_leave_civireport.leave_amount SEPARATOR ',') AS {$tableName}_{$fieldName}";
} elseif ($tableName == 'civicrm_hrjobcontract_health' && $fieldName == 'health_provider') {
$select[] = "CONCAT({$this->_aliases['civicrm_contact']}_health1.sort_name, ' (InternalID: ', hrjobcontract_health_civireport.provider , ', Email: ', COALESCE({$this->_aliases['civicrm_email']}_health1.email, '-'), ', ExternalID: ', COALESCE({$this->_aliases['civicrm_contact']}_health1.external_identifier, '-'), ')') AS {$tableName}_{$fieldName}";
} elseif ($tableName == 'civicrm_hrjobcontract_health' && $fieldName == 'health_provider_life_insurance') {
$select[] = "CONCAT({$this->_aliases['civicrm_contact']}_health2.sort_name, ' (InternalID: ', hrjobcontract_health_civireport.provider_life_insurance , ', Email: ', COALESCE({$this->_aliases['civicrm_email']}_health2.email, '-'), ', ExternalID: ', COALESCE({$this->_aliases['civicrm_contact']}_health2.external_identifier, '-'), ')') AS {$tableName}_{$fieldName}";
} else {
$alias = "{$tableName}_{$fieldName}";
$select[] = "{$field['dbAlias']} as {$alias}";
}
$this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
$this->_selectAliases[] = $alias;
}
}
}
}
$this->_select = "SELECT " . implode(', ', $select) . " ";
}
示例13: add
/**
* takes an associative array and creates a contact object
*
* the function extract all the params it needs to initialize the create a
* contact object. the params array could contain additional unused name/value
* pairs
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $ids the array that holds all the db ids
*
* @return object CRM_Contact_BAO_Household object
* @access public
* @static
*/
function add(&$params, &$ids)
{
$household =& new CRM_Contact_BAO_Household();
$household->copyValues($params);
$household->id = CRM_Utils_Array::value('household', $ids);
return $household->save();
}
示例14: create
/**
* process website
*
* @param array $params associated array
* @param int $contactID contact id
*
* @return void
* @access public
* @static
*/
static function create(&$params, $contactID, $skipDelete)
{
if (empty($params)) {
return FALSE;
}
$ids = self::allWebsites($contactID);
foreach ($params as $key => $values) {
$websiteId = CRM_Utils_Array::value('id', $values);
if ($websiteId) {
if (array_key_exists($websiteId, $ids)) {
unset($ids[$websiteId]);
} else {
unset($values['id']);
}
}
if (!CRM_Utils_Array::value('id', $values) && is_array($ids) && !empty($ids)) {
foreach ($ids as $id => $value) {
if ($value['website_type_id'] == $values['website_type_id']) {
$values['id'] = $id;
unset($ids[$id]);
break;
}
}
}
$values['contact_id'] = $contactID;
self::add($values);
}
if ($skipDelete && !empty($ids)) {
self::del(array_keys($ids));
}
}
示例15: run
public function run()
{
// lets get around the time limit issue if possible for upgrades
if (!ini_get('safe_mode')) {
set_time_limit(0);
}
$upgrade = new CRM_Upgrade_Form();
list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
$template = CRM_Core_Smarty::singleton();
$template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
$template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
$action = CRM_Utils_Array::value('action', $_REQUEST, 'intro');
switch ($action) {
case 'intro':
$this->runIntro();
break;
case 'begin':
$this->runBegin();
break;
case 'finish':
$this->runFinish();
break;
default:
CRM_Core_Error::fatal(ts('Unrecognized upgrade action'));
}
}