if ($action & CRM_Core_Action::ENABLE) {
$action -= CRM_Core_Action::ENABLE;
}
- $baoString = $this->getBAOName();
- $object = new $baoString();
-
- $values = [];
-
- // lets make sure we get the stuff sorted by name if it exists
- $fields = &$object->fields();
- $key = '';
- if (!empty($fields['title'])) {
- $key = 'title';
- }
- elseif (!empty($fields['label'])) {
- $key = 'label';
- }
- elseif (!empty($fields['name'])) {
- $key = 'name';
- }
-
- if (trim($sort)) {
- $object->orderBy($sort);
- }
- elseif ($key) {
- $object->orderBy($key . ' asc');
- }
- $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE);
- // find all objects
- $object->find();
- while ($object->fetch()) {
- if (!isset($object->mapping_type_id) ||
- // "1 for Search Builder"
- $object->mapping_type_id != 1
- ) {
- $permission = CRM_Core_Permission::EDIT;
- if ($key) {
- $permission = $this->checkPermission($object->id, $object->$key);
- }
- if ($permission) {
- $values[$object->id] = [];
- CRM_Core_DAO::storeValues($object, $values[$object->id]);
-
- if (is_a($object, 'CRM_Contact_DAO_RelationshipType')) {
- if (isset($values[$object->id]['contact_type_a'])) {
- $values[$object->id]['contact_type_a_display'] = $contactTypes[$values[$object->id]['contact_type_a']];
- }
- if (isset($values[$object->id]['contact_type_b'])) {
- $values[$object->id]['contact_type_b_display'] = $contactTypes[$values[$object->id]['contact_type_b']];
- }
- }
-
- // populate action links
- $this->action($object, $action, $values[$object->id], $links, $permission);
-
- if (isset($object->mapping_type_id)) {
- $mappintTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Mapping', 'mapping_type_id');
- $values[$object->id]['mapping_type'] = $mappintTypes[$object->mapping_type_id];
- }
- }
- }
- }
- $this->assign('rows', $values);
+ $this->assign('rows', $this->getRows($sort, $action, $links));
}
/**
$controller->run();
}
+ /**
+ * @param $sort
+ * @param $action
+ * @param array $links
+ *
+ * @return array
+ */
+ protected function getRows($sort, $action, array $links): array {
+ $baoString = $this->getBAOName();
+ $object = new $baoString();
+
+ $values = [];
+
+ // lets make sure we get the stuff sorted by name if it exists
+ $fields = &$object->fields();
+ $key = '';
+ if (!empty($fields['title'])) {
+ $key = 'title';
+ }
+ elseif (!empty($fields['label'])) {
+ $key = 'label';
+ }
+ elseif (!empty($fields['name'])) {
+ $key = 'name';
+ }
+
+ if (trim($sort)) {
+ $object->orderBy($sort);
+ }
+ elseif ($key) {
+ $object->orderBy($key . ' asc');
+ }
+
+ $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE);
+ // find all objects
+ $object->find();
+ while ($object->fetch()) {
+ if (!isset($object->mapping_type_id) ||
+ // "1 for Search Builder"
+ $object->mapping_type_id != 1
+ ) {
+ $permission = CRM_Core_Permission::EDIT;
+ if ($key) {
+ $permission = $this->checkPermission($object->id, $object->$key);
+ }
+ if ($permission) {
+ $values[$object->id] = [];
+ CRM_Core_DAO::storeValues($object, $values[$object->id]);
+
+ if (is_a($object, 'CRM_Contact_DAO_RelationshipType')) {
+ if (isset($values[$object->id]['contact_type_a'])) {
+ $values[$object->id]['contact_type_a_display'] = $contactTypes[$values[$object->id]['contact_type_a']];
+ }
+ if (isset($values[$object->id]['contact_type_b'])) {
+ $values[$object->id]['contact_type_b_display'] = $contactTypes[$values[$object->id]['contact_type_b']];
+ }
+ }
+
+ // populate action links
+ $this->action($object, $action, $values[$object->id], $links, $permission);
+
+ if (isset($object->mapping_type_id)) {
+ $mappintTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Mapping', 'mapping_type_id');
+ $values[$object->id]['mapping_type'] = $mappintTypes[$object->mapping_type_id];
+ }
+ }
+ }
+ }
+ return $values;
+ }
+
}
</tr>
</thead>
{foreach from=$rows item=row}
- <tr id="location_type-{$row.id}" data-action="setvalue" class="{cycle values="odd-row,even-row"}{if !empty($row.class)} {$row.class}{/if} crm-entity {if NOT $row.is_active} disabled{/if}">
+ <tr id="location_type-{$row.id}" data-action="setvalue" class="{cycle values="odd-row,even-row"} {$row.class} crm-entity {if NOT $row.is_active} disabled{/if}">
<td class="crmf-name">{$row.name}</td>
<td class="crmf-display_name crm-editable">{$row.display_name}</td>
- <td class="crmf-vcard_name crm-editable">{if !empty($row.vcard_name)}{$row.vcard_name}{/if}</td>
+ <td class="crmf-vcard_name crm-editable">{$row.vcard_name}</td>
<td class="crmf-description crm-editable">{$row.description}</td>
<td id="row_{$row.id}_status" class="crmf-is_active">{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
- <td class="crmf-is_default">{if isset($row.is_default)}{icon condition=$row.is_default}{ts}Default{/ts}{/icon} {/if}</td>
+ <td class="crmf-is_default">{if $row.is_default}{icon condition=$row.is_default}{ts}Default{/ts}{/icon} {/if}</td>
<td>{$row.action|replace:'xx':$row.id}</td>
</tr>
{/foreach}