Skip to content

Commit

Permalink
[Smarty Variables] Remove isset from location type form
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 30, 2021
1 parent 55144d4 commit 0529308
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 63 deletions.
21 changes: 21 additions & 0 deletions CRM/Admin/Page/LocationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,25 @@ public function userContext($mode = NULL) {
return 'civicrm/admin/locationType';
}


/**
* @param $sort
* @param $action
* @param array $links
*
* @return array
*/
protected function getRows($sort, $action, array $links): array {
$rows = parent::getRows($sort, $action, $links);
foreach ($rows as &$row) {
// prevent smarty notices.
foreach (['is_default', 'class', 'vcard_name'] as $expectedField) {
if (!isset($row['is_default'])) {
$row[$expectedField] = NULL;
}
}
}
return $rows;
}

}
132 changes: 72 additions & 60 deletions CRM/Core/Page/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,67 +203,8 @@ public function browse() {
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));
}

/**
Expand Down Expand Up @@ -395,4 +336,75 @@ public function edit($mode, $id = NULL, $imageUpload = FALSE, $pushUserContext =
$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;
}

}
6 changes: 3 additions & 3 deletions templates/CRM/Admin/Page/LocationType.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
</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}&nbsp;{/if}</td>
<td class="crmf-is_default">{if $row.is_default}{icon condition=$row.is_default}{ts}Default{/ts}{/icon}&nbsp;{/if}</td>
<td>{$row.action|replace:'xx':$row.id}</td>
</tr>
{/foreach}
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/CRM/Core/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function formList(): array {
'Add New Tag' => [
'civicrm/tag/edit?action=add&parent_id=',
],
'Location Type' => [
'civicrm/admin/locationType?reset=1',
],
'Assign Account to Financial Type' => [
'civicrm/admin/financial/financialType/accounts?action=add&reset=1&aid=1',
],
Expand Down

0 comments on commit 0529308

Please sign in to comment.