Skip to content

Commit

Permalink
Merge pull request #4988 from ChurchCRM/feature-link-custom-person-fi…
Browse files Browse the repository at this point in the history
…eld-to-the-person

Refactor or the Logic to display Custom fields for Person/Family
  • Loading branch information
DawoudIO committed Sep 15, 2019
2 parents 14a42af + 1fec972 commit 59b9f75
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 32 deletions.
82 changes: 65 additions & 17 deletions demo/ChurchCRM-Database.sql

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion propel/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
<column name="fam_custom_Special" phpName="CustomSpecial" type="SMALLINT" size="8"
sqlType="mediumint(8) unsigned"/>
<column name="fam_custom_FieldSec" phpName="FieldSecurity" type="TINYINT" required="true" defaultValue="1"/>
<column name="type_ID" phpName="Id" type="TINYINT" required="true" defaultValue="0"/>
<column name="type_ID" phpName="TypeId" type="TINYINT" required="true" defaultValue="0"/>
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
Expand Down
93 changes: 93 additions & 0 deletions src/ChurchCRM/dto/PeopleCustomField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace ChurchCRM\dto;

use ChurchCRM\PersonQuery;

Class PeopleCustomField {

private $name;
private $value;
private $formattedValue;
private $link;
private $icon = "fa fa-tag";
private $displayValue;

/**
* PeopleCustomField constructor.
* @param $name
*/
public function __construct($masterField, $value)
{
$this->value = trim($value);
$this->formattedValue = $this->value;
$this->displayValue = $masterField->getName();
$masterField->getName();

if ($masterField->getTypeId() == 9) {
$this->icon = "fa fa-user";
$this->link = SystemURLs::getRootPath() .'/PersonView.php?PersonID=' . $this->value;
$person = PersonQuery::create()->findPk($this->value);
if ($person) {
$this->formattedValue = $person->getFullName();
} else {
$this->formattedValue = gettext("Unexpected Person Id"). " : " . $this->value;
}
} elseif ($masterField->getTypeId() == 11) {
//$custom_Special = $sPhoneCountry;
$this->icon = "fa fa-phone";
$this->link = "tel:".$this->value;
}
}

/**
* @return mixed
*/
public function getFormattedValue()
{
return $this->formattedValue;
}

/**
* @return mixed
*/
public function getLink()
{
return $this->link;
}

/**
* @return mixed
*/
public function getName()
{
return $this->name;
}

/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}

/**
* @return mixed
*/
public function getIcon()
{
return $this->icon;
}

/**
* @return mixed
*/
public function getDisplayValue()
{
return $this->displayValue;
}



}
22 changes: 19 additions & 3 deletions src/FamilyView.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,26 @@ class="fa fa-<?= ($fam_SendNewsLetter == "TRUE" ? "check" : "times") ?>"></i></s
extract($Row);
if (SessionUser::getUser()->isEnabledSecurity($aSecurityType[$fam_custom_FieldSec])) {
$currentData = trim($aFamCustomData[$fam_custom_Field]);
if ($type_ID == 11) {
$fam_custom_Special = $sPhoneCountry;
$displayIcon = "fa fa-tag";
$displayLink = "";
if ($currentData != '') {
if ($type_ID == 9) {
$displayIcon = "fa fa-user";
$displayLink = SystemURLs::getRootPath() .'/PersonView.php?PersonID=' . $currentData;
} elseif ($type_ID == 11) {
$custom_Special = $sPhoneCountry;
$displayIcon = "fa fa-phone";
$displayLink = "tel:".$currentData;
}
echo '<li><i class="fa-li ' . $displayIcon . '"></i>'.$fam_custom_Name.': <span>';
$temp_string=nl2br((displayCustomField($type_ID, $currentData, $fam_custom_Special)));
if ($displayLink) {
echo "<a href=\"" . $displayLink . "\">" . $temp_string . "</a>";
} else {
echo $temp_string;
}
echo '</span></li>';
}
echo "<li><i class=\"fa-li fa fa-tag\"></i>" . $fam_custom_Name . ": <span>" . displayCustomField($type_ID, $currentData, $fam_custom_Special) . "</span></li>";
}
} ?>
</ul>
Expand Down
15 changes: 11 additions & 4 deletions src/PersonView.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,21 @@ class="initials-image profile-user-img img-responsive img-rounded profile-user-i
while ($Row = mysqli_fetch_array($rsCustomFields)) {
extract($Row);
$currentData = trim($aCustomData[$custom_Field]);
$displayIcon = "fa fa-tag";
$displayLink = "";
if ($currentData != '') {
if ($type_ID == 11) {
if ($type_ID == 9) {
$displayIcon = "fa fa-user";
$displayLink = SystemURLs::getRootPath() .'/PersonView.php?PersonID=' . $currentData;
} elseif ($type_ID == 11) {
$custom_Special = $sPhoneCountry;
$displayIcon = "fa-phone";
$displayLink = "tel:".$temp_string;
}
echo '<li><i class="fa-li '.(($type_ID == 11)?'fa fa-phone':'fa fa-tag').'"></i>'.$custom_Name.': <span>';
echo '<li><i class="fa-li ' . $displayIcon . '"></i>'.$custom_Name.': <span>';
$temp_string=nl2br((displayCustomField($type_ID, $currentData, $custom_Special)));
if ($type_ID == 11) {
echo "<a href=\"tel:".$temp_string."\">".$temp_string."</a>";
if ($displayLink) {
echo "<a href=\"" . $displayLink . "\">" . $temp_string . "</a>";
} else {
echo $temp_string;
}
Expand Down
11 changes: 8 additions & 3 deletions src/v2/routes/family.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Propel\Runtime\ActiveQuery\Criteria;
use ChurchCRM\FamilyCustomMasterQuery;
use ChurchCRM\FamilyCustomQuery;
use ChurchCRM\dto\PeopleCustomField;
use ChurchCRM\SessionUser;

$app->group('/family', function () {
$this->get('','listFamilies');
Expand Down Expand Up @@ -88,9 +90,12 @@ function viewFamily(Request $request, Response $response, array $args)
if ($thisFamilyCustomFields) {
$familyCustom = [];
foreach ($allFamilyCustomFields as $customfield ) {
$value = $thisFamilyCustomFields->getVirtualColumn($customfield->getField());
if (!empty($value)) {
array_push($familyCustom, $customfield->getName() . ": " . $value);
if (SessionUser::getUser()->isEnabledSecurity($customfield->getFieldSecurity())) {
$value = $thisFamilyCustomFields->getVirtualColumn($customfield->getField());
if (!empty($value)) {
$item = new PeopleCustomField($customfield, $value);
array_push($familyCustom, $item);
}
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/v2/templates/people/family-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,15 @@ class="fa fa-<?= (!$family->getSendNewsletter() ? "check" : "times") ?>"></i></s
* <?php
* }*/
}

foreach ($familyCustom as $customField) { ?>
<li><i class="fa-li fa fa-tag"></i><?= $customField ?></li>
<?php } ?>
foreach ($familyCustom as $customField) {
echo '<li><i class="fa-li ' . $customField->getIcon() . '"></i>'. $customField->getDisplayValue().': <span>';
if ($customField->getLink()) {
echo "<a href=\"" . $customField->getLink() . "\">" . $customField->getFormattedValue() . "</a>";
} else {
echo $customField->getFormattedValue();
}
echo '</span></li>';
} ?>
</ul>
</div>
</div>
Expand Down

0 comments on commit 59b9f75

Please sign in to comment.