本文整理汇总了PHP中CRM_Core_BAO_CustomGroup::formatGroupTree方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_CustomGroup::formatGroupTree方法的具体用法?PHP CRM_Core_BAO_CustomGroup::formatGroupTree怎么用?PHP CRM_Core_BAO_CustomGroup::formatGroupTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_CustomGroup
的用法示例。
在下文中一共展示了CRM_Core_BAO_CustomGroup::formatGroupTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preProcess
/**
* Pre processing work done here.
*
* gets session variables for group or field id
*
* @return void
*/
public function preProcess()
{
// get the controller vars
$this->_groupId = $this->get('groupId');
$this->_fieldId = $this->get('fieldId');
if ($this->_fieldId) {
// field preview
$defaults = array();
$params = array('id' => $this->_fieldId);
$fieldDAO = new CRM_Core_DAO_CustomField();
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
if (!empty($defaults['is_view'])) {
CRM_Core_Error::statusBounce(ts('This field is view only so it will not display on edit form.'));
} elseif (CRM_Utils_Array::value('is_active', $defaults) == 0) {
CRM_Core_Error::statusBounce(ts('This field is inactive so it will not display on edit form.'));
}
$groupTree = array();
$groupTree[$this->_groupId]['id'] = 0;
$groupTree[$this->_groupId]['fields'] = array();
$groupTree[$this->_groupId]['fields'][$this->_fieldId] = $defaults;
$this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
$this->assign('preview_type', 'field');
} else {
$groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($this->_groupId);
$this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, TRUE, $this);
$this->assign('preview_type', 'group');
}
}
示例2: preProcess
static function preProcess(&$form, $subName = NULL, $subType = NULL, $groupCount = NULL, $type = NULL, $entityID = NULL)
{
if ($type) {
$form->_type = $type;
} else {
$form->_type = CRM_Utils_Request::retrieve('type', 'String', $form);
}
if (isset($subType)) {
$form->_subType = $subType;
} else {
$form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form);
}
if ($form->_subType == 'null') {
$form->_subType = NULL;
}
if (isset($subName)) {
$form->_subName = $subName;
} else {
$form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form);
}
if ($form->_subName == 'null') {
$form->_subName = NULL;
}
if ($groupCount) {
$form->_groupCount = $groupCount;
} else {
$form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form);
}
$form->assign('cgCount', $form->_groupCount);
//carry qf key, since this form is not inhereting core form.
if ($qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject)) {
$form->assign('qfKey', $qfKey);
}
if ($entityID) {
$form->_entityId = $entityID;
} else {
$form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form);
}
$form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form);
$subType = $form->_subType;
if (!is_array($subType) && strstr($subType, CRM_Core_DAO::VALUE_SEPARATOR)) {
$subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR));
}
$groupTree =& CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $form->_groupID, $subType, $form->_subName);
// we should use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
if (isset($form->_groupTree) && is_array($form->_groupTree)) {
$keys = array_keys($groupTree);
foreach ($keys as $key) {
$form->_groupTree[$key] = $groupTree[$key];
}
} else {
$form->_groupTree = $groupTree;
}
}
示例3: preProcess
static function preProcess(&$form, $subName = null, $subType = null, $groupCount = null, $type = null, $entityID = null)
{
if ($type) {
$form->_type = $type;
} else {
$form->_type = CRM_Utils_Request::retrieve('type', 'String', $form);
}
if (isset($subType)) {
$form->_subType = $subType;
} else {
$form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form);
}
if ($form->_subType == 'null') {
$form->_subType = null;
}
if (isset($subName)) {
$form->_subName = $subName;
} else {
$form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form);
}
if ($form->_subName == 'null') {
$form->_subName = null;
}
if ($groupCount) {
$form->_groupCount = $groupCount;
} else {
$form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form);
}
$form->assign('cgCount', $form->_groupCount);
if ($entityID) {
$form->_entityId = $entityID;
} else {
$form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form);
}
$form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form);
$groupTree =& CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $form->_groupID, $form->_subType, $form->_subName);
// we should use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
if (isset($form->_groupTree) && is_array($form->_groupTree)) {
$keys = array_keys($groupTree);
foreach ($keys as $key) {
$form->_groupTree[$key] = $groupTree[$key];
}
} else {
$form->_groupTree = $groupTree;
}
}
示例4: __construct
/**
* Class constructor.
*
* @param array $formValues
*/
public function __construct(&$formValues)
{
$this->_formValues = $formValues;
/**
* Define the columns for search result rows
*/
$this->_columns = array(ts('Name') => 'sort_name', ts('Status') => 'activity_status', ts('Activity Type') => 'activity_type', ts('Activity Subject') => 'activity_subject', ts('Scheduled By') => 'source_contact', ts('Scheduled Date') => 'activity_date', ' ' => 'activity_id', ' ' => 'activity_type_id', ' ' => 'case_id', ts('Location') => 'location', ts('Duration') => 'duration', ts('Details') => 'details', ts('Assignee') => 'assignee');
$this->_groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_status', 'id', 'name');
//Add custom fields to columns array for inclusion in export
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity');
//use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree);
//cycle through custom fields and assign to _columns array
foreach ($groupTree as $key) {
foreach ($key['fields'] as $field) {
$fieldlabel = $key['title'] . ": " . $field['label'];
$this->_columns[$fieldlabel] = $field['column_name'];
}
}
}
示例5: preProcess
/**
* pre processing work done here.
*
* gets session variables for table name, id of entity in table, type of entity and stores them.
*
* @param
*
* @return void
*
* @access public
*
*/
function preProcess()
{
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE);
$this->_entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', $this, TRUE);
$this->_subTypeID = CRM_Utils_Request::retrieve('subType', 'Positive', $this, TRUE);
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$groupTree =& CRM_Core_BAO_CustomGroup::getTree('Case', $this, $this->_entityID, $this->_groupID, $this->_subTypeID);
// simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
foreach ($groupTree as $groupValues) {
$this->_customTitle = $groupValues['title'];
}
$this->_defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults);
$this->setDefaults($this->_defaults);
CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree, FALSE, 1);
//need to assign custom data type and subtype to the template
$this->assign('entityID', $this->_entityID);
$this->assign('groupID', $this->_groupID);
$this->assign('subType', $this->_subTypeID);
$this->assign('contactID', $this->_contactID);
}
示例6: setDefaultValues
/**
* Set the default form values.
*
*
* @return array
* the default array reference
*/
public function setDefaultValues()
{
if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
if ($this->_copyValueId) {
// cached tree is fetched
$groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_type, $this, $this->_entityId, $this->_groupID);
$valueIdDefaults = array();
$groupTreeValueId = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $this->_copyValueId, $this);
CRM_Core_BAO_CustomGroup::setDefaults($groupTreeValueId, $valueIdDefaults, FALSE, FALSE, $this->get('action'));
$tableId = $groupTreeValueId[$this->_groupID]['table_id'];
foreach ($valueIdDefaults as $valueIdElementName => $value) {
// build defaults for COPY action for new record saving
$valueIdElementNamePieces = explode('_', $valueIdElementName);
$valueIdElementNamePieces[2] = "-{$this->_groupCount}";
$elementName = implode('_', $valueIdElementNamePieces);
$customDefaultValue[$elementName] = $value;
}
} else {
$customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this);
}
return $customDefaultValue;
}
$groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType);
if (empty($_POST['hidden_custom_group_count'])) {
// custom data building in edit mode (required to handle multi-value)
$groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType);
$customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, TRUE, $this->_groupID, NULL, NULL, $this->_tableID);
} else {
$customValueCount = $_POST['hidden_custom_group_count'][$this->_groupID];
}
$this->assign('customValueCount', $customValueCount);
$defaults = array();
return $defaults;
}
示例7: setComponentDefaults
/**
* This function is used to setDefault componet specific profile fields.
*
* @param array $fields profile fields.
* @param int $componentId componetID
* @param string $component component name
* @param array $defaults an array of default values.
*
* @return void.
*/
function setComponentDefaults(&$fields, $componentId, $component, &$defaults)
{
if (!$componentId || !in_array($component, array('Contribute', 'Membership', 'Event'))) {
return;
}
$componentBAO = $componentSubType = null;
switch ($component) {
case 'Membership':
$componentBAO = 'CRM_Member_BAO_Membership';
$componentBAOName = 'Membership';
$componentSubType = array('membership_type_id');
break;
case 'Contribute':
$componentBAO = 'CRM_Contribute_BAO_Contribution';
$componentBAOName = 'Contribution';
$componentSubType = array('contribution_type_id');
break;
case 'Event':
$componentBAO = 'CRM_Event_BAO_Participant';
$componentBAOName = 'Participant';
$componentSubType = array('role_id', 'event_id');
break;
}
$values = array();
$params = array('id' => $componentId);
//get the component values.
CRM_Core_DAO::commonRetrieve($componentBAO, $params, $values);
$formattedGroupTree = array();
foreach ($fields as $name => $field) {
$fldName = "field[{$componentId}][{$name}]";
if ($name == 'participant_register_date') {
$timefldName = "field[{$componentId}][{$name}_time]";
list($defaults[$fldName], $defaults[$timefldName]) = CRM_Utils_Date::setDateDefaults($values[$name]);
} else {
if (array_key_exists($name, $values)) {
$defaults[$fldName] = $values[$name];
} else {
if ($name == 'participant_note') {
require_once "CRM/Core/BAO/Note.php";
$noteDetails = array();
$noteDetails = CRM_Core_BAO_Note::getNote($componentId, 'civicrm_participant');
$defaults[$fldName] = array_pop($noteDetails);
} else {
if (in_array($name, array('contribution_type', 'payment_instrument'))) {
$defaults[$fldName] = $values["{$name}_id"];
} else {
if ($customFieldInfo = CRM_Core_BAO_CustomField::getKeyID($name, true)) {
if (empty($formattedGroupTree)) {
//get the groupTree as per subTypes.
$groupTree = array();
require_once 'CRM/Core/BAO/CustomGroup.php';
foreach ($componentSubType as $subType) {
$subTree = CRM_Core_BAO_CustomGroup::getTree($componentBAOName, CRM_Core_DAO::$_nullObject, $componentId, 0, $values[$subType]);
$groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $subTree);
}
$formattedGroupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
CRM_Core_BAO_CustomGroup::setDefaults($formattedGroupTree, $defaults);
}
//FIX ME: We need to loop defaults, but once we move to custom_1_x convention this code can be simplified.
foreach ($defaults as $customKey => $customValue) {
if ($customFieldDetails = CRM_Core_BAO_CustomField::getKeyID($customKey, true)) {
if ($name == 'custom_' . $customFieldDetails[0]) {
//hack to set default for checkbox
//basically this is for weired field name like field[33][custom_19]
//we are converting this field name to array structure and assign value.
$skipValue = false;
foreach ($formattedGroupTree as $tree) {
if ('CheckBox' == CRM_Utils_Array::value('html_type', $tree['fields'][$customFieldDetails[0]])) {
$skipValue = true;
$defaults['field'][$componentId][$name] = $customValue;
break;
} else {
if (CRM_Utils_Array::value('data_type', $tree['fields'][$customFieldDetails[0]]) == 'Date') {
$skipValue = true;
$customValue = $tree['fields'][$customFieldDetails[0]]['element_value'];
list($defaults['field'][$componentId][$name], $defaults['field'][$componentId][$name . '_time']) = CRM_Utils_Date::setDateDefaults($customValue);
}
}
}
if (!$skipValue) {
$defaults[$fldName] = $customValue;
}
unset($defaults[$customKey]);
break;
}
}
}
}
}
}
//.........这里部分代码省略.........
示例8: templateCustomDataValues
public function templateCustomDataValues($templateId)
{
$defaults = array();
if (!$templateId) {
return $defaults;
}
// pull template custom data as a default for event, CRM-5596
$groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_type, $this, $templateId, null, $this->_subType);
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $this->_groupCount, $this);
$customValues = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $customValues);
foreach ($customValues as $key => $val) {
if ($fieldKey = CRM_Core_BAO_CustomField::getKeyID($key)) {
$defaults["custom_{$fieldKey}_-1"] = $val;
}
}
return $defaults;
}
示例9: setGroupTree
/**
* @param $form
* @param $subType
* @param $gid
* @param $onlySubType
* @param $getCachedTree
*
* @return array
*/
public static function setGroupTree(&$form, $subType, $gid, $onlySubType, $getCachedTree = FALSE)
{
$groupTree = CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $gid, $subType, $form->_subName, $getCachedTree, $onlySubType);
if (property_exists($form, '_customValueCount') && !empty($groupTree)) {
$form->_customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, TRUE, NULL, NULL);
}
// we should use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
if (isset($form->_groupTree) && is_array($form->_groupTree)) {
$keys = array_keys($groupTree);
foreach ($keys as $key) {
$form->_groupTree[$key] = $groupTree[$key];
}
return array($form, $groupTree);
} else {
$form->_groupTree = $groupTree;
return array($form, $groupTree);
}
}
示例10: preProcess
/**
* @param CRM_Core_Form $form
* @param null|string $subName
* @param null|string $subType
* @param null|int $groupCount
* @param string $type
* @param null|int $entityID
* @param null $onlySubType
*/
public static function preProcess(&$form, $subName = NULL, $subType = NULL, $groupCount = NULL, $type = NULL, $entityID = NULL, $onlySubType = NULL)
{
if ($type) {
$form->_type = $type;
} else {
$form->_type = CRM_Utils_Request::retrieve('type', 'String', $form);
}
if (isset($subType)) {
$form->_subType = $subType;
} else {
$form->_subType = CRM_Utils_Request::retrieve('subType', 'String', $form);
}
if ($form->_subType == 'null') {
$form->_subType = NULL;
}
if (isset($subName)) {
$form->_subName = $subName;
} else {
$form->_subName = CRM_Utils_Request::retrieve('subName', 'String', $form);
}
if ($form->_subName == 'null') {
$form->_subName = NULL;
}
if ($groupCount) {
$form->_groupCount = $groupCount;
} else {
$form->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $form);
}
$form->assign('cgCount', $form->_groupCount);
//carry qf key, since this form is not inhereting core form.
if ($qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject)) {
$form->assign('qfKey', $qfKey);
}
if ($entityID) {
$form->_entityId = $entityID;
} else {
$form->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $form);
}
$typeCheck = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject);
$urlGroupId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject);
if (isset($typeCheck) && $urlGroupId) {
$form->_groupID = $urlGroupId;
} else {
$form->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $form);
}
$gid = isset($form->_groupID) ? $form->_groupID : NULL;
$getCachedTree = isset($form->_getCachedTree) ? $form->_getCachedTree : TRUE;
$subType = $form->_subType;
if (!is_array($subType) && strstr($subType, CRM_Core_DAO::VALUE_SEPARATOR)) {
$subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR));
}
$groupTree =& CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $gid, $subType, $form->_subName, $getCachedTree, $onlySubType);
if (property_exists($form, '_customValueCount') && !empty($groupTree)) {
$form->_customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, TRUE, NULL, NULL);
}
// we should use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $form->_groupCount, $form);
if (isset($form->_groupTree) && is_array($form->_groupTree)) {
$keys = array_keys($groupTree);
foreach ($keys as $key) {
$form->_groupTree[$key] = $groupTree[$key];
}
} else {
$form->_groupTree = $groupTree;
}
}
示例11: civicrm_contact_relationship_get
/**
* Function to get the relationship
*
* @param array $contact_a (reference ) input parameters.
* @param array $contact_b (reference ) input parameters.
* @param array $relationshipTypes an array of Relationship Type Name.
* @param string $sort sort all relationship by relationshipId (eg asc/desc)
*
* @return Array of all relationship.
*
* @access public
*/
function civicrm_contact_relationship_get($contact_a, $contact_b = NULL, $relationshipTypes = NULL, $sort = NULL)
{
if (!is_array($contact_a)) {
return civicrm_create_error(ts('Input parameter is not an array'));
}
if (!isset($contact_a['contact_id'])) {
return civicrm_create_error(ts('Could not find contact_id in input parameters.'));
}
require_once 'CRM/Contact/BAO/Relationship.php';
$contactID = $contact_a['contact_id'];
$relationships = CRM_Contact_BAO_Relationship::getRelationship($contactID);
if (!empty($relationshipTypes)) {
$result = array();
foreach ($relationshipTypes as $relationshipName) {
foreach ($relationships as $key => $relationship) {
if ($relationship['relation'] == $relationshipName) {
$result[$key] = $relationship;
}
}
}
$relationships = $result;
}
if (isset($contact_b['contact_id'])) {
$cid = $contact_b['contact_id'];
$result = array();
foreach ($relationships as $key => $relationship) {
if ($relationship['cid'] == $cid) {
$result[$key] = $relationship;
}
}
$relationships = $result;
}
//sort by relationship id
if ($sort) {
if (strtolower($sort) == 'asc') {
ksort($relationships);
} elseif (strtolower($sort) == 'desc') {
krsort($relationships);
}
}
//handle custom data.
require_once 'CRM/Core/BAO/CustomGroup.php';
foreach ($relationships as $relationshipId => $values) {
$groupTree =& CRM_Core_BAO_CustomGroup::getTree('Relationship', CRM_Core_DAO::$_nullObject, $relationshipId, FALSE, $values['civicrm_relationship_type_id']);
$formatTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
$defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($formatTree, $defaults);
if (!empty($defaults)) {
foreach ($defaults as $key => $val) {
$relationships[$relationshipId][$key] = $val;
}
}
}
if ($relationships) {
return civicrm_create_success($relationships);
} else {
return civicrm_create_error(ts('Invalid Data'));
}
}
示例12: civicrm_event_search
/**
* Get Event record.
*
*
* @param array $params an associative array of name/value property values of civicrm_event
*
* @return Array of all found event property values.
* @access public
*/
function civicrm_event_search(&$params)
{
if (!is_array($params)) {
return civicrm_create_error(ts('Input parameters is not an array.'));
}
$inputParams = array();
$returnProperties = array();
$returnCustomProperties = array();
$otherVars = array('sort', 'offset', 'rowCount');
$sort = false;
// don't check if empty, more meaningful error for API user instead of siletn defaults
$offset = array_key_exists('return.offset', $params) ? $params['return.offset'] : 0;
$rowCount = array_key_exists('return.max_results', $params) ? $params['return.max_results'] : 25;
foreach ($params as $n => $v) {
if (substr($n, 0, 7) == 'return.') {
if (substr($n, 0, 14) == 'return.custom_') {
//take custom return properties separate
$returnCustomProperties[] = substr($n, 7);
} elseif (!in_array(substr($n, 7), array('offset', 'max_results'))) {
$returnProperties[] = substr($n, 7);
}
} elseif (in_array($n, $otherVars)) {
${$n} = $v;
} else {
$inputParams[$n] = $v;
}
}
if (!empty($returnProperties)) {
$returnProperties[] = 'id';
$returnProperties[] = 'event_type_id';
}
$returnProperties[] = 'is_template';
require_once 'CRM/Core/BAO/CustomGroup.php';
require_once 'CRM/Event/BAO/Event.php';
$eventDAO = new CRM_Event_BAO_Event();
$eventDAO->copyValues($inputParams);
$event = array();
if (!empty($returnProperties)) {
$eventDAO->selectAdd();
$eventDAO->selectAdd(implode(',', $returnProperties));
}
$eventDAO->orderBy($sort);
$eventDAO->limit((int) $offset, (int) $rowCount);
$eventDAO->find();
while ($eventDAO->fetch()) {
// ignore event templates
// ideally need to put this in the query, but not sure how to do this with the below
// ( ( is_template IS NULL ) OR ( is_template = 0 ) )
// hence doing this here for now, please fix on a future rewrite
if ($eventDAO->is_template) {
continue;
}
$event[$eventDAO->id] = array();
CRM_Core_DAO::storeValues($eventDAO, $event[$eventDAO->id]);
$groupTree =& CRM_Core_BAO_CustomGroup::getTree('Event', CRM_Core_DAO::$_nullObject, $eventDAO->id, false, $eventDAO->event_type_id);
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
$defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
if (!empty($defaults)) {
foreach ($defaults as $key => $val) {
if (!empty($returnCustomProperties)) {
$customKey = explode('_', $key);
//show only return properties
if (in_array('custom_' . $customKey['1'], $returnCustomProperties)) {
$event[$eventDAO->id][$key] = $val;
}
} else {
$event[$eventDAO->id][$key] = $val;
}
}
}
}
//end of the loop
$eventDAO->free();
return $event;
}
示例13: civicrm_event_search
/**
* Get Event record.
*
*
* @param array $params an associative array of name/value property values of civicrm_event
*
* @return Array of all found event property values.
* @access public
*/
function civicrm_event_search(&$params)
{
if (!is_array($params)) {
return civicrm_create_error(ts('Input parameters is not an array.'));
}
$inputParams = array();
$returnProperties = array();
$returnCustomProperties = array();
$otherVars = array('sort', 'offset', 'rowCount', 'isCurrent');
$sort = array_key_exists('return.sort', $params) ? $params['return.sort'] : FALSE;
// don't check if empty, more meaningful error for API user instead of silent defaults
$offset = array_key_exists('return.offset', $params) ? $params['return.offset'] : 0;
$rowCount = array_key_exists('return.max_results', $params) ? $params['return.max_results'] : 25;
$isCurrent = array_key_exists('isCurrent', $params) ? $params['isCurrent'] : 0;
foreach ($params as $n => $v) {
if (substr($n, 0, 7) == 'return.') {
if (substr($n, 0, 14) == 'return.custom_') {
//take custom return properties separate
$returnCustomProperties[] = substr($n, 7);
} elseif (!in_array(substr($n, 7), array('sort', 'offset', 'max_results'))) {
$returnProperties[] = substr($n, 7);
}
} elseif (in_array($n, $otherVars)) {
${$n} = $v;
} else {
$inputParams[$n] = $v;
}
}
if (!empty($returnProperties)) {
$returnProperties[] = 'id';
$returnProperties[] = 'event_type_id';
}
require_once 'CRM/Core/BAO/CustomGroup.php';
require_once 'CRM/Event/BAO/Event.php';
$eventDAO = new CRM_Event_BAO_Event();
$eventDAO->copyValues($inputParams);
$event = array();
if (!empty($returnProperties)) {
$eventDAO->selectAdd();
$eventDAO->selectAdd(implode(',', $returnProperties));
}
$eventDAO->whereAdd('( is_template IS NULL ) OR ( is_template = 0 )');
if ($isCurrent) {
$eventDAO->whereAdd('(start_date >= CURDATE() || end_date >= CURDATE())');
}
$eventDAO->orderBy($sort);
$eventDAO->limit((int) $offset, (int) $rowCount);
$eventDAO->find();
while ($eventDAO->fetch()) {
$event[$eventDAO->id] = array();
CRM_Core_DAO::storeValues($eventDAO, $event[$eventDAO->id]);
$groupTree =& CRM_Core_BAO_CustomGroup::getTree('Event', CRM_Core_DAO::$_nullObject, $eventDAO->id, FALSE, $eventDAO->event_type_id);
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
$defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
if (!empty($defaults)) {
foreach ($defaults as $key => $val) {
if (!empty($returnCustomProperties)) {
$customKey = explode('_', $key);
//show only return properties
if (in_array('custom_' . $customKey['1'], $returnCustomProperties)) {
$event[$eventDAO->id][$key] = $val;
}
} else {
$event[$eventDAO->id][$key] = $val;
}
}
}
}
//end of the loop
$eventDAO->free();
return $event;
}
示例14: buildQuickForm
/**
* build form for address input fields
*
* @param object $form - CRM_Core_Form (or subclass)
* @param array reference $location - location array
* @param int $locationId - location id whose block needs to be built.
* @return none
*
* @access public
* @static
*/
static function buildQuickForm(&$form, $addressBlockCount = null)
{
// passing this via the session is AWFUL. we need to fix this
if (!$addressBlockCount) {
$blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
} else {
$blockId = $addressBlockCount;
}
$config = CRM_Core_Config::singleton();
$countryDefault = $config->defaultContactCountry;
$form->applyFilter('__ALL__', 'trim');
$js = array('onChange' => 'checkLocation( this.id );');
$form->addElement('select', "address[{$blockId}][location_type_id]", ts('Location Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::locationType(), $js);
$js = array('id' => "Address_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );');
$form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js);
$js = array('id' => "Address_" . $blockId . "_IsBilling", 'onClick' => 'singleSelect( this.id );');
$form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js);
// hidden element to store master address id
$form->addElement('hidden', "address[{$blockId}][master_id]");
require_once 'CRM/Core/BAO/Preferences.php';
$addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
$elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], null), 'street_address' => array(ts('Street Address'), $attributes['street_address'], null), 'supplemental_address_1' => array(ts('Addt\'l Address 1'), $attributes['supplemental_address_1'], null), 'supplemental_address_2' => array(ts('Addt\'l Address 2'), $attributes['supplemental_address_2'], null), 'city' => array(ts('City'), $attributes['city'], null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12), null), 'county_id' => array(ts('County'), $attributes['county_id'], 'county'), 'state_province_id' => array(ts('State / Province'), $attributes['state_province_id'], null), 'country_id' => array(ts('Country'), $attributes['country_id'], null), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 10), null), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 10), null), 'street_number' => array(ts('Street Number'), $attributes['street_number'], null), 'street_name' => array(ts('Street Name'), $attributes['street_name'], null), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], null));
$stateCountryMap = array();
foreach ($elements as $name => $v) {
list($title, $attributes, $select) = $v;
$nameWithoutID = strpos($name, '_id') !== false ? substr($name, 0, -3) : $name;
if (!CRM_Utils_Array::value($nameWithoutID, $addressOptions)) {
$continue = true;
if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && CRM_Utils_Array::value('street_address_parsing', $addressOptions)) {
$continue = false;
}
if ($continue) {
continue;
}
}
if (!$attributes) {
$attributes = $attributes[$name];
}
//build normal select if country is not present in address block
if ($name == 'state_province_id' && !$addressOptions['country']) {
$select = 'stateProvince';
}
if (!$select) {
if ($name == 'country_id' || $name == 'state_province_id') {
if ($name == 'country_id') {
$stateCountryMap[$blockId]['country'] = "address_{$blockId}_{$name}";
$selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
} else {
$stateCountryMap[$blockId]['state_province'] = "address_{$blockId}_{$name}";
if ($countryDefault) {
$selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
} else {
$selectOptions = array('' => ts('- select a country -'));
}
}
$form->addElement('select', "address[{$blockId}][{$name}]", $title, $selectOptions);
} else {
if ($name == 'address_name') {
$name = "name";
}
$form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes);
}
} else {
$form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select());
}
}
require_once 'CRM/Core/BAO/Address.php';
require_once 'CRM/Core/BAO/CustomGroup.php';
CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
$entityId = null;
if (!empty($form->_values['address'])) {
$entityId = $form->_values['address'][$blockId]['id'];
}
// Process any address custom data -
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId);
if (isset($groupTree) && is_array($groupTree)) {
// use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
// make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
foreach ($groupTree as $id => $group) {
foreach ($group['fields'] as $fldId => $field) {
$groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
$groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]";
}
}
$defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
// For some of the custom fields like checkboxes, the defaults doesn't populate
//.........这里部分代码省略.........
示例15: civicrm_membership_contact_get
/**
* Get contact membership record.
*
* This api is used for finding an existing membership record.
* This api will also return the mebership records for the contacts
* having mebership based on the relationship with the direct members.
*
* @param Array $params key/value pairs for contact_id and some
* options affecting the desired results; has legacy support
* for just passing the contact_id itself as the argument
*
* @return Array of all found membership property values.
* @access public
*/
function civicrm_membership_contact_get(&$params)
{
_civicrm_initialize();
$activeOnly = false;
if (is_array($params)) {
$contactID = CRM_Utils_Array::value('contact_id', $params);
$activeOnly = CRM_Utils_Array::value('active_only', $params, false);
if ($activeOnly == 1) {
$activeOnly = true;
} else {
$activeOnly = false;
}
} elseif (CRM_Utils_Rule::integer($params)) {
$contactID = $params;
} else {
return civicrm_create_error('Paramers can be only of type array or integer');
}
if (empty($contactID)) {
return civicrm_create_error('Invalid value for ContactID.');
}
// get the membership for the given contact ID
require_once 'CRM/Member/BAO/Membership.php';
$membership = array('contact_id' => $contactID);
$membershipValues = array();
CRM_Member_BAO_Membership::getValues($membership, $membershipValues, $activeOnly);
$recordCount = 0;
if (empty($membershipValues)) {
# No results is NOT an error!
# return civicrm_create_error('No memberships for this contact.');
$membershipValues['record_count'] = $recordCount;
return $membershipValues;
}
$members[$contactID] = array();
$relationships = array();
foreach ($membershipValues as $membershipId => $values) {
// populate the membership type name for the membership type id
require_once 'CRM/Member/BAO/MembershipType.php';
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
$membershipValues[$membershipId]['membership_name'] = $membershipType['name'];
if (CRM_Utils_Array::value('relationship_type_id', $membershipType)) {
$relationships[$membershipType['relationship_type_id']] = $membershipId;
}
// populating relationship type name.
require_once 'CRM/Contact/BAO/RelationshipType.php';
$relationshipType = new CRM_Contact_BAO_RelationshipType();
$relationshipType->id = CRM_Utils_Array::value('relationship_type_id', $membershipType);
if ($relationshipType->find(true)) {
$membershipValues[$membershipId]['relationship_name'] = $relationshipType->name_a_b;
}
require_once 'CRM/Core/BAO/CustomGroup.php';
$groupTree =& CRM_Core_BAO_CustomGroup::getTree('Membership', CRM_Core_DAO::$_nullObject, $membershipId, false, $values['membership_type_id']);
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
$defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
if (!empty($defaults)) {
foreach ($defaults as $key => $val) {
$membershipValues[$membershipId][$key] = $val;
}
}
$recordCount++;
}
$members[$contactID] = $membershipValues;
// populating contacts in members array based on their relationship with direct members.
require_once 'CRM/Contact/BAO/Relationship.php';
if (!empty($relationships)) {
foreach ($relationships as $relTypeId => $membershipId) {
// As members are not direct members, there should not be
// membership id in the result array.
unset($membershipValues[$membershipId]['id']);
$relationship = new CRM_Contact_BAO_Relationship();
$relationship->contact_id_b = $contactID;
$relationship->relationship_type_id = $relTypeId;
if ($relationship->find()) {
while ($relationship->fetch()) {
clone $relationship;
$membershipValues[$membershipId]['contact_id'] = $relationship->contact_id_a;
$members[$contactID][$relationship->contact_id_a] = $membershipValues[$membershipId];
}
}
$recordCount++;
}
}
$members['record_count'] = $recordCount;
return $members;
}