Skip to content

Commit

Permalink
Polish on survey and core admin tools
Browse files Browse the repository at this point in the history
Many survey aspects polished quite a bit, and code files organized and
cleaned up ever more.
  • Loading branch information
Morgan Lesko authored and Morgan Lesko committed Feb 11, 2019
1 parent 648d21d commit f43a49d
Show file tree
Hide file tree
Showing 59 changed files with 6,030 additions and 5,391 deletions.
155 changes: 155 additions & 0 deletions src/Controllers/OpenComplaintConditions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php
namespace OpenPolice\Controllers;

use DB;
use Auth;
use App\Models\SLEmailed;
use OpenPolice\Controllers\OpenSessDataOverride;

class OpenComplaintConditions extends OpenSessDataOverride
{
// CUSTOM={OnlyIfNoAllegationsOtherThan:WrongStop,Miranda,PoliceRefuseID]
protected function checkNodeConditionsCustom($nID, $condition = '')
{
if ($condition == '#VehicleStop') { // could be replaced by OR functionality
if (isset($this->sessData->dataSets["Scenes"]) && sizeof($this->sessData->dataSets["Scenes"]) > 0) {
if (isset($this->sessData->dataSets["Scenes"][0]->ScnIsVehicle)
&& trim($this->sessData->dataSets["Scenes"][0]->ScnIsVehicle) == 'Y') {
return 1;
}
if (isset($this->sessData->dataSets["Scenes"][0]->ScnIsVehicleAccident)
&& trim($this->sessData->dataSets["Scenes"][0]->ScnIsVehicleAccident) == 'Y') {
return 1;
}
}
return 0;
} elseif ($condition == '#LawyerInvolved') {
if ((isset($this->sessData->dataSets["Complaints"][0]->ComAttorneyHas)
&& in_array(trim($this->sessData->dataSets["Complaints"][0]->ComAttorneyHas), ['Y', '?']))
|| (isset($this->sessData->dataSets["Complaints"][0]->ComAttorneyWant)
&& in_array(trim($this->sessData->dataSets["Complaints"][0]->ComAttorneyWant), ['Y', '?']))) {
return 1;
}
if ((isset($this->sessData->dataSets["Complaints"][0]->ComAnyoneCharged)
&& in_array(trim($this->sessData->dataSets["Complaints"][0]->ComAnyoneCharged), ['Y', '?']))
&& (!isset($this->sessData->dataSets["Complaints"][0]->ComAllChargesResolved)
|| trim($this->sessData->dataSets["Complaints"][0]->ComAllChargesResolved) != 'Y')) {
return 1;
}
if (isset($this->sessData->dataSets["Complaints"][0]->ComAnyoneCharged)
&& trim($this->sessData->dataSets["Complaints"][0]->ComAnyoneCharged) == 'N'
&& isset($this->sessData->dataSets["Complaints"][0]->ComFileLawsuit)
&& trim($this->sessData->dataSets["Complaints"][0]->ComFileLawsuit) == 'Y') {
return 1;
}
return 0;
} elseif ($condition == '#NoSexualAllegation') {
$noSexAlleg = true;
if (isset($this->sessData->dataSets["Allegations"])
&& sizeof($this->sessData->dataSets["Allegations"]) > 0) {
foreach ($this->sessData->dataSets["Allegations"] as $alleg) {
if (in_array($alleg->AlleType, [
$GLOBALS["SL"]->def->getID('Allegation Type', 'Sexual Assault'),
$GLOBALS["SL"]->def->getID('Allegation Type', 'Sexual Harassment')
])) {
$noSexAlleg = false;
}
}
}
return ($noSexAlleg) ? 1 : 0;
} elseif ($condition == '#IncidentHasAddress') {
if (isset($this->sessData->dataSets["Incidents"])
&& isset($this->sessData->dataSets["Incidents"][0]->IncAddress)
&& trim($this->sessData->dataSets["Incidents"][0]->IncAddress) != '') {
return 1;
} else {
return 0;
}
} elseif ($condition == '#HasArrestOrForce') {
if ($this->sessData->dataHas('Arrests') || $this->sessData->dataHas('Force')) {
return 1;
} else {
return 0;
}
} elseif ($condition == '#CivHasForce') {
if (isset($GLOBALS["SL"]->closestLoop["itemID"])) {
return $this->chkCivHasForce($GLOBALS["SL"]->closestLoop["itemID"]);
}
return 0;
} elseif ($condition == '#HasForceHuman') {
$ret = 0;
if (isset($this->sessData->dataSets["Civilians"]) && sizeof($this->sessData->dataSets["Civilians"]) > 0) {
foreach ($this->sessData->dataSets["Civilians"] as $civ) {
if ($civ->CivRole == 'Victim' && $this->chkCivHasForce($civ->CivID) == 1) {
$ret = 1;
}
}
}
return $ret;
} elseif ($condition == '#HasInjury') {
if (isset($this->sessData->dataSets["Civilians"]) && sizeof($this->sessData->dataSets["Civilians"]) > 0) {
foreach ($this->sessData->dataSets["Civilians"] as $civ) {
if ($civ->CivRole == 'Victim' && isset($civ->CivHasInjury) && trim($civ->CivHasInjury) == 'Y') {
return 1;
}
}
}
return 0;
} elseif ($condition == '#MedicalCareNotYou') {
$civ = $this->sessData->getDataBranchRow('Civilians');
if ($civ && isset($civ->CivIsCreator) && trim($civ->CivIsCreator) == 'Y') {
return 0;
}
} elseif ($condition == '#Property') {
$search = $this->sessData->getChildRow('EventSequence', $GLOBALS["SL"]->closestLoop["itemID"], 'Searches');
if ((isset($search->SrchSeized) && trim($search->SrchSeized) == 'Y')
|| (isset($search->SrchDamage) && trim($search->SrchDamage) == 'Y')) {
return 1;
} else {
return 0;
}
} elseif ($condition == '#EmailConfirmSentToday') {
if (isset($this->v["user"]) && isset($this->v["user"]->id)) {
$cutoff = date("Y-m-d H:i:s",
mktime(date("H"), date("i"), date("s"), date("n"), date("j")-1, date("Y")));
$chk = SLEmailed::where('EmailedEmailID', 1)
->where('EmailedFromUser', $this->v["user"]->id)
->where('created_at', '>', $cutoff)
->get();
if ($chk->isNotEmpty()) {
return 1;
}
}
return 0;
} elseif ($condition == '#HasUploads') {
$uploads = $this->getUploadsMultNodes($this->cmplntUpNodes, $this->v["isAdmin"], $this->v["isOwner"]);
if ($uploads && sizeof($uploads) > 0) {
return 1;
}
return 0;
} elseif ($condition == '#PrintAnonOnly') {
if (isset($GLOBALS["SL"]->x["pageView"]) && in_array($GLOBALS["SL"]->x["pageView"], ['public', 'pdf'])
&& isset($this->sessData->dataSets["Complaints"][0]->ComStatus)
&& in_array(trim($this->sessData->dataSets["Complaints"][0]->ComStatus),
$this->getUnPublishedStatusList())) {
return 1;
}
if (isset($GLOBALS["SL"]->x["pageView"]) && in_array($GLOBALS["SL"]->x["pageView"], ['public', 'pdf'])
&& isset($this->sessData->dataSets["Complaints"][0]->ComPrivacy)
&& $this->sessData->dataSets["Complaints"][0]->ComPrivacy
!= $GLOBALS["SL"]->def->getID('Privacy Types', 'Submit Publicly')) {
return 1;
}
return 0;
} elseif ($condition == '#PrintSensitiveReport') {
if (isset($GLOBALS["SL"]->x["pageView"]) && in_array($GLOBALS["SL"]->x["pageView"], ['full', 'full-pdf'])) {
return 1;
}
return 0;
} elseif ($condition == '#IsOversightAgency') {
return (($this->v["uID"] > 0 && $this->v["user"]->hasRole('oversight')) ? 1 : 0);
}
return -1;
}

}
70 changes: 55 additions & 15 deletions src/Controllers/OpenComplaintPrints.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ protected function initBlnkAllegsSilv()
if (isset($this->sessData->dataSets["Allegations"])
&& sizeof($this->sessData->dataSets["Allegations"]) > 0) {
foreach ($this->sessData->dataSets["Allegations"] as $i => $alleRow) {
if ($alle[0] == $alleRow->AlleType) $found = true;
if ($alle[0] == $alleRow->AlleType) {
$found = true;
}
}
}
if (!$found) {
Expand Down Expand Up @@ -85,7 +87,15 @@ protected function customLabels($nIDtxt = '', $str = '')
}
if (strpos($str, '[ForceType]') !== false) {
$forceDesc = $GLOBALS["SL"]->def->getVal('Force Type', $event[0]["Event"]->ForType);
if ($forceDesc == 'Other') $forceDesc = $event[0]["Event"]->ForTypeOther;
if ($forceDesc == 'Other') {
$forceDesc = $event[0]["Event"]->ForTypeOther;
}
if (strpos($nIDtxt, '343') !== false) {
$eveSeq = $this->sessData->getDataBranchRow('EventSequence');
if ($eveSeq && isset($eveSeq->EveID)) {
$forceDesc .= ' used on ' . $this->getCivNamesFromEvent($eveSeq->EveID);
}
}
$str = str_replace('[ForceType]', '<span class="slBlueDark"><b>' . $forceDesc .'</b></span>', $str);
}
} elseif (strpos($str, '[LoopItemLabel]') !== false) {
Expand Down Expand Up @@ -129,32 +139,53 @@ protected function customLabels($nIDtxt = '', $str = '')
$str = str_replace('anybody was', 'anybody was', $str);
}
} elseif (in_array($nIDtxt, ['591'])) {
if ($complainantVic && !$multipleVic) $str = str_replace('anybody', 'you', $str);
if ($complainantVic && !$multipleVic) {
$str = str_replace('anybody', 'you', $str);
}
} elseif (in_array($nIDtxt, ['228'])) {
if ($complainantVic && !$multipleVic) $str = str_replace('anybody was', 'you were', $str);
if ($complainantVic && !$multipleVic) {
$str = str_replace('anybody was', 'you were', $str);
}
}
$str = str_replace('Did you who was not arrested get a ticket or citation?',
'Did you get a ticket or citation?', $str);
}
}

if (strpos($str, '[[PartnerUrl]]') !== false && isset($this->sessData->dataSets["Partners"])
&& isset($this->sessData->dataSets["Partners"][0]->PartSlug)) {
$url = $GLOBALS["SL"]->sysOpts["app-url"] . '/';
switch ($this->sessData->dataSets["Partners"][0]->PartType) {
case $GLOBALS["SL"]->def->getID('Partner Types', 'Attorney'): $url .= 'attorney/'; break;
case $GLOBALS["SL"]->def->getID('Partner Types', 'Organization'): $url .= 'org/'; break;
}
$url .= $this->sessData->dataSets["Partners"][0]->PartSlug;
$str = str_replace('[[PartnerUrl]]', $GLOBALS["SL"]->swapURLwrap($url, false), $str);
}
return $str;
}

protected function getLoopItemLabelCustom($loop, $itemRow = null, $itemInd = -3)
{
//echo '<br /><br /><br />getLoopItemLabelCustom(' . $loop . '<br /><pre>'; print_r($itemRow); echo '</pre>';
//if ($itemIndex < 0) return '';
if (!$itemRow) return '';
if (!$itemRow) {
return '';
}
if (in_array($loop, ['Victims', 'Witnesses'])) {
return $this->getCivName($loop, $itemRow, $itemInd);
} elseif ($loop == 'Civilians') {
if (isset($itemRow->CivID)) return $this->getCivilianNameFromID($itemRow->CivID);
if (isset($itemRow->CivID)) {
return $this->getCivilianNameFromID($itemRow->CivID);
}
} elseif (in_array($loop, ['Officers', 'Excellent Officers'])) {
return $this->getOfficerName($itemRow, $itemInd);
} elseif ($loop == 'Departments') {
return $this->getDeptName($itemRow, $itemInd);
} elseif ($loop == 'Events') {
if (isset($itemRow->EveID)) return $this->getEventLabel($itemRow->EveID);
if (isset($itemRow->EveID)) {
return $this->getEventLabel($itemRow->EveID);
}
} elseif ($loop == 'Citations') { // why isn't this working?!
if (isset($itemRow->StopEventSequenceID) && intVal($itemRow->StopEventSequenceID) > 0) {
$eveID = $itemRow->StopEventSequenceID;
Expand All @@ -163,7 +194,9 @@ protected function getLoopItemLabelCustom($loop, $itemRow = null, $itemInd = -3)
return $this->getCivilianNameFromID($EveSeq[0]["Civilians"][0]);
}
$civList = '';
foreach ($EveSeq[0]["Civilians"] as $civID) $civList .= ', ' . $this->getCivilianNameFromID($civID);
foreach ($EveSeq[0]["Civilians"] as $civID) {
$civList .= ', ' . $this->getCivilianNameFromID($civID);
}
return substr($civList, 1);
}
}
Expand All @@ -177,7 +210,7 @@ protected function printSetLoopNavRowCustom($nID, $loopItem, $setIndex)
"loopItem" => $this->sessData->getChildRow('LinksComplaintDept', $loopItem->getKey(), 'Departments'),
"setIndex" => $setIndex,
"itemID" => $loopItem->getKey()
])->render();
])->render();
}
return '';
}
Expand All @@ -186,9 +219,13 @@ protected function getTableRecLabelCustom($tbl, $rec = [], $ind = -3)
{
if ($tbl == 'Vehicles' && isset($rec->VehicTransportation)) {
return $GLOBALS["SL"]->def->getValById($rec->VehicTransportation)
. ((isset($rec->VehicVehicleMake)) ? ' ' . $rec->VehicVehicleMake : '')
. ((isset($rec->VehicVehicleModel)) ? ' ' . $rec->VehicVehicleModel : '')
. ((isset($rec->VehicVehicleDesc)) ? ' ' . $rec->VehicVehicleDesc : '');
. ((isset($rec->VehicUnmarked) && $rec->VehicUnmarked == 'Y') ? ' Unmarked' : '')
. ((isset($rec->VehicVehicleMake) && trim($rec->VehicVehicleMake) != '')
? ' ' . $rec->VehicVehicleMake : '')
. ((isset($rec->VehicVehicleModel) && trim($rec->VehicVehicleModel) != '')
? ' ' . $rec->VehicVehicleModel : '') . ' (Vehicle #' . (1+$ind) . ')';
} elseif ($tbl == 'Civilians' && isset($rec->CivID)) {
return $this->getCivilianNameFromID($rec->CivID);
}
return '';
}
Expand All @@ -197,8 +234,12 @@ protected function loadUpDeetPrivacy($upRow = NULL)
{
if ($upRow && isset($upRow->UpPrivacy)) {
if ($upRow->UpTreeID == 1) {
if ($GLOBALS["SL"]->x["dataPerms"] == 'public') return 'Block';
if ($GLOBALS["SL"]->x["pageView"] == 'public') return 'Public';
if ($GLOBALS["SL"]->x["dataPerms"] == 'public') {
return 'Block';
}
if ($GLOBALS["SL"]->x["pageView"] == 'public') {
return 'Public';
}
if ($upRow->UpPrivacy == 'Private') {
if (in_array($GLOBALS["SL"]->x["pageView"], ['sensitive', 'internal'])) {
return 'Public';
Expand All @@ -212,5 +253,4 @@ protected function loadUpDeetPrivacy($upRow = NULL)
return 'Block';
}


}
Loading

0 comments on commit f43a49d

Please sign in to comment.