//Custom Groups Inline
$entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
$entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
- $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId,
- $this->_groupId, $entitySubType
- );
$recId = NULL;
if ($this->_multiRecordDisplay == 'single') {
$groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId);
CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle)));
+ $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId,
+ $this->_groupId, $entitySubType, NULL, TRUE, NULL, FALSE, TRUE, $this->_cgcount
+ );
$recId = $this->_recId;
$this->assign('multiRecordDisplay', $this->_multiRecordDisplay);
$this->assign('skipTitle', 1);
}
+ else {
+ $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId,
+ $this->_groupId, $entitySubType
+ );
+ }
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId, $this->_contactId);
}
}
* api - through which it is properly tested - so can be refactored with some comfort.)
*
* @param bool $checkPermission
+ * @param varchar $singleRecord
+ * holds 'new' or id if view/edit/copy form for a single record is being loaded.
*
* @return array
* Custom field 'tree'.
$fromCache = TRUE,
$onlySubType = NULL,
$returnAll = FALSE,
- $checkPermission = TRUE
+ $checkPermission = TRUE,
+ $singleRecord = NULL
) {
if ($entityID) {
$entityID = CRM_Utils_Type::escape($entityID, 'Integer');
// add info to groupTree
if (isset($groupTree['info']) && !empty($groupTree['info']) &&
- !empty($groupTree['info']['tables'])
+ !empty($groupTree['info']['tables']) && $singleRecord != 'new'
) {
$select = $from = $where = array();
$groupTree['info']['where'] = NULL;
}
$multipleFieldTablesWithEntityData = array_keys($entityMultipleSelectClauses);
if (!empty($multipleFieldTablesWithEntityData)) {
- self::buildEntityTreeMultipleFields($groupTree, $entityID, $entityMultipleSelectClauses, $multipleFieldTablesWithEntityData);
+ self::buildEntityTreeMultipleFields($groupTree, $entityID, $entityMultipleSelectClauses, $multipleFieldTablesWithEntityData, $singleRecord);
}
}
* Array of select clauses relevant to the entity.
* @param array $multipleFieldTablesWithEntityData
* Array of tables in which this entity has data.
+ * @param varchar $singleRecord
+ * holds 'new' or id if view/edit/copy form for a single record is being loaded.
*/
- static public function buildEntityTreeMultipleFields(&$groupTree, $entityID, $entityMultipleSelectClauses, $multipleFieldTablesWithEntityData) {
+ static public function buildEntityTreeMultipleFields(&$groupTree, $entityID, $entityMultipleSelectClauses, $multipleFieldTablesWithEntityData, $singleRecord = NULL) {
foreach ($entityMultipleSelectClauses as $table => $selectClauses) {
$select = implode(',', $selectClauses);
$query = "
FROM $table
WHERE entity_id = $entityID
";
- self::buildTreeEntityDataFromQuery($groupTree, $query, array($table));
+ if ($singleRecord) {
+ $offset = $singleRecord - 1;
+ $query .= " LIMIT {$offset}, 1";
+ }
+ self::buildTreeEntityDataFromQuery($groupTree, $query, array($table), $singleRecord);
}
}
* @param array $includedTables
* Tables to include - required because the function (for historical reasons).
* iterates through the group tree
+ * @param varchar $singleRecord
+ * holds 'new' OR id if view/edit/copy form for a single record is being loaded.
*/
- static public function buildTreeEntityDataFromQuery(&$groupTree, $query, $includedTables) {
+ static public function buildTreeEntityDataFromQuery(&$groupTree, $query, $includedTables, $singleRecord = NULL) {
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
foreach ($groupTree as $groupID => $group) {
continue;
}
foreach ($group['fields'] as $fieldID => $dontCare) {
- self::buildCustomFieldData($dao, $groupTree, $table, $groupID, $fieldID);
+ self::buildCustomFieldData($dao, $groupTree, $table, $groupID, $fieldID, $singleRecord);
}
}
}
* Custom group ID.
* @param int $fieldID
* Custom field ID.
+ * @param varchar $singleRecord
+ * holds 'new' or id if loading view/edit/copy for a single record.
*/
- static public function buildCustomFieldData($dao, &$groupTree, $table, $groupID, $fieldID) {
+ static public function buildCustomFieldData($dao, &$groupTree, $table, $groupID, $fieldID, $singleRecord = NULL) {
$column = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
$idName = "{$table}_id";
$fieldName = "{$table}_{$column}";
if (!array_key_exists('customValue', $groupTree[$groupID]['fields'][$fieldID])) {
$groupTree[$groupID]['fields'][$fieldID]['customValue'] = array();
}
- if (empty($groupTree[$groupID]['fields'][$fieldID]['customValue'])) {
+ if (empty($groupTree[$groupID]['fields'][$fieldID]['customValue']) && !empty($singleRecord)) {
+ $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array($singleRecord => $customValue);
+ }
+ elseif (empty($groupTree[$groupID]['fields'][$fieldID]['customValue'])) {
$groupTree[$groupID]['fields'][$fieldID]['customValue'] = array(1 => $customValue);
}
else {