Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize on display of FamilyString to disambiguate famililes #2564

Merged
merged 10 commits into from
Jun 21, 2017
2 changes: 1 addition & 1 deletion src/ChurchCRM/Service/FinancialService.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function getPayments($depID)
$values = new \stdClass();
$values->plg_plgID = $plg_plgID;
$values->plg_FamID = $plg_FamID;
$values->familyName = $family->getName();
$values->familyString = $family->getFamilyString();
$values->plg_FYID = $plg_FYID;
$values->FiscalYear = MakeFYString($plg_FYID);
$values->plg_date = $plg_date;
Expand Down
36 changes: 35 additions & 1 deletion src/ChurchCRM/model/ChurchCRM/Family.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,25 @@ public function verify()
}

public function getFamilyString()
{
{
$HoH = $this->getHeadPeople();
if (count($HoH) == 1)
{
return $this->getName(). ": " . $HoH[0]->getFirstName() . " - " . $this->getAddress();
}
elseif (count($HoH) > 1)
{
$HoHs = [];
foreach ($HoH as $person) {
array_push($HoHs, $person->getFirstName());
}

return $this->getName(). ": " . join(",", $HoHs) . " - " . $this->getAddress();
}
else
{
return $this->getName(). " " . $this->getAddress();
}
}

public function hasLatitudeAndLongitude() {
Expand All @@ -307,4 +324,21 @@ public function updateLanLng() {
}
}
}

public function toArray()
{
$array = parent::toArray();
$array['FamilyString']=$this->getFamilyString();
return $array;
}

public function toSearchArray()
{
$searchArray=[
"Id" => $this->getId(),
"displayName" => $this->getFamilyString(),
"uri" => SystemURLs::getRootPath() . 'FamilyView.php?FamilyID=' . $this->getId()
];
return $searchArray;
}
}
13 changes: 13 additions & 0 deletions src/ChurchCRM/model/ChurchCRM/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,17 @@ public function preDelete()
throw new PropelException('Cannot delete a payment from a closed deposit', 500);
}
}

public function toArray()
{
$array = parent::toArray();
$family = $this->getFamily();

if($family)
{
$array['FamilyString']=$family->getFamilyString();
}

return $array;
}
}
8 changes: 4 additions & 4 deletions src/api/routes/deposits.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@

$this->get('/{id:[0-9]+}/pledges', function ($request, $response, $args) {
$id = $args['id'];
echo \ChurchCRM\PledgeQuery::create()
$Pledges = \ChurchCRM\PledgeQuery::create()
->filterByDepid($id)
->groupByGroupkey()
->withColumn('SUM(Pledge.Amount)', 'sumAmount')
->joinFamily(null, Propel\Runtime\ActiveQuery\Criteria::LEFT_JOIN)
->withColumn('Family.Name')
->joinDonationFund()
->withColumn('DonationFund.Name')
->find()
->toJSON();
->toArray();
return $response->withJSON($Pledges);

});
});
26 changes: 17 additions & 9 deletions src/api/routes/families.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@
use Propel\Runtime\ActiveQuery\Criteria;

$app->group('/families', function () {

$this->get('/{familyId:[0-9]+}', function($request, $response, $args) {
$family = FamilyQuery::create()->findPk($args['familyId']);
return $response->withJSON($family->toJSON());
});

$this->get('/search/{query}', function ($request, $response, $args) {
$query = $args['query'];
$q = FamilyQuery::create()
->filterByName("%$query%", Criteria::LIKE)
->limit(15)
->withColumn('CONCAT( Family.Name, " - ", Family.Address1," / ", Family.City, " ", Family.State)', 'displayName')
->withColumn('CONCAT("'.SystemURLs::getRootPath().'FamilyView.php?FamilyID=",Family.Id)', 'uri')
->select(['displayName', 'uri','Id'])
->find();

return $response->withJSON($q->toJSON());
$results = [];
$q = FamilyQuery::create()
->filterByName("%$query%", Propel\Runtime\ActiveQuery\Criteria::LIKE)
->limit(15)
->find();
foreach ($q as $family)
{
array_push($results,$family->toSearchArray());
}

return $response->withJSON(json_encode(["Families"=>$results]));
});

$this->get('/byCheckNumber/{scanString}', function ($request, $response, $args) {
Expand Down
20 changes: 11 additions & 9 deletions src/api/routes/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
} catch (Exception $e) {
}

//family search
try {
$q = FamilyQuery::create()
->filterByName("%$query%", Propel\Runtime\ActiveQuery\Criteria::LIKE)
->limit(15)
->withColumn('fam_Name', 'displayName')
->withColumn('CONCAT("' . SystemURLs::getRootPath() . 'FamilyView.php?FamilyID=",Family.Id)', 'uri')
->select(['displayName', 'uri'])
->find();

array_push($resultsArray, $q->toJSON());
$results = [];
$q = FamilyQuery::create()
->filterByName("%$query%", Propel\Runtime\ActiveQuery\Criteria::LIKE)
->limit(15)
->find();
foreach ($q as $family)
{
array_push($results,$family->toSearchArray());
}
array_push($resultsArray, json_encode(["families"=>$results]));
} catch (Exception $e) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/skin/js/DepositSlipEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ function initPaymentTable()
{
width: 'auto',
title:'Family',
data:'FamilyName',
data:'FamilyString',
render: function(data, type, full, meta) {
var familyName = data ? data : "<?= gettext('Anonymous')?>";
var familyName = data ? data : i18next.t('Anonymous');
return '<a href=\'PledgeEditor.php?linkBack=DepositSlipEditor.php?DepositSlipID=' + depositSlipID +
'&GroupKey=' + full.Groupkey + '\'><span class="fa-stack"><i class="fa fa-square fa-stack-2x"></i><i class="fa '+ (isDepositClosed ? "fa-search-plus": "fa-pencil" ) +' fa-stack-1x fa-inverse"></i></span></a>' + familyName;
}
Expand Down Expand Up @@ -47,7 +47,7 @@ function initPaymentTable()
dataT = $("#paymentsTable").DataTable({
ajax:{
url :window.CRM.root+"/api/deposits/"+depositSlipID+"/pledges",
dataSrc:"Pledges"
dataSrc:''
},
columns: colDef,
responsive: true,
Expand Down