From d3d7d23a8fb9ec754094b32305618c13ae57351a Mon Sep 17 00:00:00 2001 From: Arun Philip Date: Wed, 14 Feb 2024 21:06:03 -0500 Subject: [PATCH] update updates to use propel orm --- propel/schema.xml | 1 + src/BatchWinnerEntry.php | 8 ++- src/CSVImport.php | 29 ++++----- src/CanvassEditor.php | 35 +++++------ src/CartToFamily.php | 9 ++- src/ChurchCRM/Service/FinancialService.php | 16 +++-- src/ChurchCRM/Service/GroupService.php | 17 +++++- src/ConvertIndividualToFamily.php | 29 +++++---- src/DonatedItemEditor.php | 24 ++++++-- src/EditEventTypes.php | 11 ++-- src/EventEditor.php | 49 ++++++++------- src/FamilyEditor.php | 70 +++++++++++----------- src/FundRaiserEditor.php | 26 ++++---- src/ListEvents.php | 6 +- src/ManageEnvelopes.php | 6 +- src/PledgeEditor.php | 5 +- src/PropertyEditor.php | 12 ++-- src/UserEditor.php | 21 +++++-- src/VolunteerOpportunityEditor.php | 39 ++++++------ src/WhyCameEditor.php | 11 +++- 20 files changed, 246 insertions(+), 178 deletions(-) diff --git a/propel/schema.xml b/propel/schema.xml index b1d87fbf92..9ba9d256c3 100644 --- a/propel/schema.xml +++ b/propel/schema.xml @@ -623,6 +623,7 @@ + diff --git a/src/BatchWinnerEntry.php b/src/BatchWinnerEntry.php index 3c14d34ec0..f68e7c1e4b 100644 --- a/src/BatchWinnerEntry.php +++ b/src/BatchWinnerEntry.php @@ -13,6 +13,7 @@ require 'Include/Config.php'; require 'Include/Functions.php'; +use ChurchCRM\model\ChurchCRM\DonatedItemQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -42,8 +43,11 @@ $di = $_POST["Item$row"]; $price = $_POST["SellPrice$row"]; if ($buyer > 0 && $di > 0 && $price > 0) { - $sSQL = "UPDATE donateditem_di SET di_buyer_id=$buyer, di_sellprice=$price WHERE di_ID=$di"; - RunQuery($sSQL); + $donatedItem = DonatedItemQuery::create()->findOneById($di); + $donatedItem + ->setBuyerId($buyer) + ->setSellprice($price); + $donatedItem->save(); } } RedirectUtils::redirect($linkBack); diff --git a/src/CSVImport.php b/src/CSVImport.php index 239f914159..5547208c52 100644 --- a/src/CSVImport.php +++ b/src/CSVImport.php @@ -21,8 +21,10 @@ use ChurchCRM\dto\SystemConfig; use ChurchCRM\dto\SystemURLs; use ChurchCRM\model\ChurchCRM\FamilyCustom; +use ChurchCRM\model\ChurchCRM\FamilyQuery; use ChurchCRM\model\ChurchCRM\Note; use ChurchCRM\model\ChurchCRM\PersonCustom; +use ChurchCRM\model\ChurchCRM\PersonQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -656,8 +658,10 @@ public function assignRoles() ); $Families[$famid] = $fFamily; } - $sSQL = 'UPDATE person_per SET per_fam_ID = ' . $famid . ' WHERE per_ID = ' . $per_ID; - RunQuery($sSQL); + + $person = PersonQuery::create()->findOneById($per_ID); + $person->setFamId($famid); + $person->save(); if ($bHasFamCustom) { // Check if family_custom record exists @@ -789,26 +793,23 @@ public function assignRoles() default: $iRole = 0; } - $sSQL = 'UPDATE person_per SET per_fmr_ID = ' . $iRole . ' WHERE per_ID = ' . $member['personid']; - RunQuery($sSQL); + + $person = PersonQuery::create()->findOneById($member['personid']); + $person->setFmrId($iRole); + $person->save(); } - $valuesToUpdate = []; + $familyModel = FamilyQuery::create()->findOneById($fid); if ($family->WeddingDate !== '') { - $valuesToUpdate[] = "fam_WeddingDate='$family->WeddingDate'"; + $familyModel->setWeddingdate($family->WeddingDate); } if ($family->Phone !== '') { - $valuesToUpdate[] = "fam_HomePhone='$family->Phone'"; + $familyModel->setHomePhone($family->Phone); } if ($family->Envelope !== 0) { - $valuesToUpdate[] = "fam_Envelope='$family->Envelope'"; - } - if (!empty($valuesToUpdate)) { - $sSQL = 'UPDATE family_fam SET ' . - implode(',', $valuesToUpdate) . - " WHERE fam_ID = $fid"; - RunQuery($sSQL); + $familyModel->setEnvelope($family->Envelope); } + $familyModel->save(); } $iStage = 3; diff --git a/src/CanvassEditor.php b/src/CanvassEditor.php index 645049974a..aa3c2a437e 100644 --- a/src/CanvassEditor.php +++ b/src/CanvassEditor.php @@ -15,6 +15,7 @@ use ChurchCRM\Authentication\AuthenticationManager; use ChurchCRM\model\ChurchCRM\CanvassData; +use ChurchCRM\model\ChurchCRM\CanvassDataQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -78,26 +79,22 @@ ->setNotInterested($bNotInterested) ->setWhyNotInterested($tWhyNotInterested); $canvassData->save(); - - $sSQL = 'SELECT MAX(can_ID) AS iCanvassID FROM canvassdata_can'; - $rsLastEntry = RunQuery($sSQL); - $newRec = mysqli_fetch_array($rsLastEntry); - $iCanvassID = $newRec['iCanvassID']; + $canvassData->reload(); + $iCanvassID = $canvassData->getId(); } else { - $sSQL = 'UPDATE canvassdata_can SET can_famID=' . $iFamily . ',' . - 'can_Canvasser=' . $iCanvasser . ',' . - 'can_FYID=' . $iFYID . ',' . - 'can_date="' . $dDate . '",' . - 'can_Positive="' . $tPositive . '",' . - 'can_Critical="' . $tCritical . '",' . - 'can_Insightful="' . $tInsightful . '",' . - 'can_Financial="' . $tFinancial . '",' . - 'can_Suggestion="' . $tSuggestion . '",' . - 'can_NotInterested="' . $bNotInterested . '",' . - 'can_WhyNotInterested="' . $tWhyNotInterested . - '" WHERE can_FamID = ' . $iFamily; - //Execute the SQL - RunQuery($sSQL); + $canvassData = CanvassDataQuery::create()->findOneByFamilyId($iFamily); + $canvassData + ->setCanvasser($iCanvasser) + ->setFyid($iFYID) + ->setDate($dDate) + ->setPositive($tPositive) + ->setCritical($tCritical) + ->setInsightful($tInsightful) + ->setFinancial($tFinancial) + ->setSuggestion($tSuggestion) + ->setNotInterested($bNotInterested) + ->setWhyNotInterested($tWhyNotInterested); + $canvassData->save(); } if (isset($_POST['Submit'])) { diff --git a/src/CartToFamily.php b/src/CartToFamily.php index b663412bc0..43b39c369d 100644 --- a/src/CartToFamily.php +++ b/src/CartToFamily.php @@ -17,6 +17,7 @@ use ChurchCRM\Authentication\AuthenticationManager; use ChurchCRM\dto\SystemURLs; +use ChurchCRM\model\ChurchCRM\PersonQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -129,8 +130,12 @@ throw new \Exception(sprintf('person (%d) does not have role in post body', $iPersonID)); } - $sSQL = 'UPDATE person_per SET per_fam_ID = ' . $iFamilyID . ', per_fmr_ID = ' . $iFamilyRoleID . ' WHERE per_ID = ' . $iPersonID; - RunQuery($sSQL); + $person = PersonQuery::create()->findOneById($iPersonID); + $person + ->setFamId($iFamilyID) + ->setFmrId($iFamilyRoleID); + $person->save(); + $iCount++; } diff --git a/src/ChurchCRM/Service/FinancialService.php b/src/ChurchCRM/Service/FinancialService.php index 225ecea263..df00e2bc10 100644 --- a/src/ChurchCRM/Service/FinancialService.php +++ b/src/ChurchCRM/Service/FinancialService.php @@ -10,6 +10,7 @@ use ChurchCRM\dto\SystemURLs; use ChurchCRM\MICRFunctions; use ChurchCRM\model\ChurchCRM\Deposit; +use ChurchCRM\model\ChurchCRM\DepositQuery; use ChurchCRM\model\ChurchCRM\FamilyQuery; use ChurchCRM\model\ChurchCRM\Pledge; use ChurchCRM\model\ChurchCRM\PledgeQuery; @@ -52,14 +53,18 @@ public function getMemberByScanString($tScanString): array public function setDeposit(string $depositType, string $depositComment, string $depositDate, $iDepositSlipID = null, $depositClosed = false): void { if ($iDepositSlipID) { - $sSQL = "UPDATE deposit_dep SET dep_Date = '" . $depositDate . "', dep_Comment = '" . $depositComment . "', dep_EnteredBy = " . AuthenticationManager::getCurrentUser()->getId() . ', dep_Closed = ' . intval($depositClosed) . ' WHERE dep_ID = ' . $iDepositSlipID . ';'; - $bGetKeyBack = false; + $deposit = DepositQuery::create()->findOneById($iDepositSlipID); + $deposit + ->setDate($depositDate) + ->setComment($depositComment) + ->setEnteredby(AuthenticationManager::getCurrentUser()->getId()) + ->setClosed(intval($depositClosed)); + $deposit->save(); if ($depositClosed && ($depositType === 'CreditCard' || $depositType === 'BankDraft')) { // Delete any failed transactions on this deposit slip now that it is closing $q = 'DELETE FROM pledge_plg WHERE plg_depID = ' . $iDepositSlipID . ' AND plg_PledgeOrPayment="Payment" AND plg_aut_Cleared=0'; RunQuery($q); } - RunQuery($sSQL); } else { $deposit = new Deposit(); $deposit @@ -68,10 +73,9 @@ public function setDeposit(string $depositType, string $depositComment, string $ ->setEnteredby(AuthenticationManager::getCurrentUser()->getId()) ->setType($depositType); $deposit->save(); + $deposit->reload(); - $sSQL = 'SELECT MAX(dep_ID) AS iDepositSlipID FROM deposit_dep'; - $rsDepositSlipID = RunQuery($sSQL); - $iDepositSlipID = mysqli_fetch_array($rsDepositSlipID)[0]; + $iDepositSlipID = $deposit->getId(); } $_SESSION['iCurrentDeposit'] = $iDepositSlipID; } diff --git a/src/ChurchCRM/Service/GroupService.php b/src/ChurchCRM/Service/GroupService.php index a7dc85b922..86203483dd 100644 --- a/src/ChurchCRM/Service/GroupService.php +++ b/src/ChurchCRM/Service/GroupService.php @@ -3,6 +3,7 @@ namespace ChurchCRM\Service; use ChurchCRM\model\ChurchCRM\ListOption; +use ChurchCRM\model\ChurchCRM\Person2group2roleP2g2r; use ChurchCRM\model\ChurchCRM\PersonQuery; class GroupService @@ -72,10 +73,22 @@ public function addUserToGroup(int $iGroupID, int $iPersonID, int $iRoleID): arr $iRoleID = $Row[0]; } - $sSQL = 'INSERT INTO person2group2role_p2g2r (p2g2r_per_ID, p2g2r_grp_ID, p2g2r_rle_ID) VALUES (' . $iPersonID . ', ' . $iGroupID . ', ' . $iRoleID . ')'; - $result = RunQuery($sSQL, false); + $result = false; + try { + $person2group2role = new Person2group2roleP2g2r(); + $person2group2role + ->setPersonId($iPersonID) + ->setGroupId($iGroupID) + ->setRoleId($iRoleID); + $person2group2role->save(); + $result = true; + } catch (\Throwable $t) { + // do nothing + } + if ($result) { // Check if this group has special properties + $sSQL = 'SELECT grp_hasSpecialProps FROM group_grp WHERE grp_ID = ' . $iGroupID; $rsTemp = RunQuery($sSQL); $rowTemp = mysqli_fetch_row($rsTemp); diff --git a/src/ConvertIndividualToFamily.php b/src/ConvertIndividualToFamily.php index e03e2e6aa9..fdfd5adaca 100644 --- a/src/ConvertIndividualToFamily.php +++ b/src/ConvertIndividualToFamily.php @@ -26,6 +26,7 @@ use ChurchCRM\Authentication\AuthenticationManager; use ChurchCRM\model\ChurchCRM\Family; +use ChurchCRM\model\ChurchCRM\PersonQuery; use ChurchCRM\Utils\RedirectUtils; // Security @@ -98,21 +99,19 @@ echo '

'; // Now update person record - $sSQL = 'UPDATE person_per ' . - "SET per_fam_ID='$iFamilyID'," . - ' per_Address1=NULL,' . - ' per_Address2=NULL,' . - ' per_City=NULL,' . - ' per_State=NULL,' . - ' per_Zip=NULL,' . - ' per_Country=NULL,' . - ' per_HomePhone=NULL,' . - ' per_DateLastEdited=NOW(),' . - " per_EditedBy='$curUserId' " . - "WHERE per_ID='$per_ID'"; - - echo '
' . $sSQL; - RunQuery($sSQL); + $person = PersonQuery::create()->findOneById($per_ID); + $person + ->setFamId($iFamilyID) + ->setAddress1(null) + ->setAddress2(null) + ->setCity(null) + ->setState(null) + ->setZip(null) + ->setCountry(null) + ->setHomePhone(null) + ->setDateLastEdited(new \DateTimeImmutable()) + ->setEditedBy($curUserId); + $person->save(); echo '


'; echo "$per_FirstName $per_LastName (per_ID = $per_ID) is now part of the "; diff --git a/src/DonatedItemEditor.php b/src/DonatedItemEditor.php index da4f6ed5be..250af63c68 100644 --- a/src/DonatedItemEditor.php +++ b/src/DonatedItemEditor.php @@ -16,6 +16,7 @@ use ChurchCRM\Authentication\AuthenticationManager; use ChurchCRM\dto\SystemURLs; use ChurchCRM\model\ChurchCRM\DonatedItem; +use ChurchCRM\model\ChurchCRM\DonatedItemQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -90,15 +91,26 @@ $bGetKeyBack = true; // Existing record (update) } else { - $sSQL = 'UPDATE donateditem_di SET di_FR_ID = ' . $iCurrentFundraiser . ", di_Item = '" . $sItem . "', di_multibuy = '" . $bMultibuy . "', di_donor_ID = " . $iDonor . ', di_buyer_ID = ' . $iBuyer . ", di_title = '" . html_entity_decode($sTitle) . "', di_description = '" . html_entity_decode($sDescription) . "', di_sellprice = '" . $nSellPrice . "', di_estprice = '" . $nEstPrice . "', di_materialvalue = '" . $nMaterialValue . "', di_minimum = '" . $nMinimumPrice . "', di_picture = '" . mysqli_real_escape_string($cnInfoCentral, $sPictureURL) . "', di_EnteredBy=" . AuthenticationManager::getCurrentUser()->getId() . ", di_EnteredDate = '" . date('YmdHis') . "'"; - $sSQL .= ' WHERE di_ID = ' . $iDonatedItemID; - echo '





' . $sSQL; + $donatedItem = DonatedItemQuery::create()->findOneById($iDonatedItemID); + $donatedItem + ->setFrId($iCurrentFundraiser) + ->setItem($sItem) + ->setMultibuy($bMultibuy) + ->setDonorId($iDonor) + ->setBuyerId($iBuyer) + ->setTitle(html_entity_decode($sTitle)) + ->setDescription(html_entity_decode($sDescription)) + ->setSellprice($nSellPrice) + ->setEstprice($nEstPrice) + ->setMaterialValue($nMaterialValue) + ->setMinimum($nMinimumPrice) + ->setPicture($sPictureURL) + ->setEnteredby(AuthenticationManager::getCurrentUser()->getId()) + ->setEntereddate(date('YmdHis')); + $donatedItem->save(); $bGetKeyBack = false; } - //Execute the SQL - RunQuery($sSQL); - // If this is a new DonatedItem or deposit, get the key back if ($bGetKeyBack) { $sSQL = 'SELECT MAX(di_ID) AS iDonatedItemID FROM donateditem_di'; diff --git a/src/EditEventTypes.php b/src/EditEventTypes.php index 2474095850..1a472749b8 100644 --- a/src/EditEventTypes.php +++ b/src/EditEventTypes.php @@ -20,6 +20,7 @@ require 'Include/Functions.php'; use ChurchCRM\Authentication\AuthenticationManager; +use ChurchCRM\model\ChurchCRM\EventTypeQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -51,8 +52,9 @@ $editing = 'FALSE'; $eName = $_POST['newEvtName']; $theID = $_POST['EN_tyid']; - $sSQL = "UPDATE event_types SET type_name='" . InputUtils::legacyFilterInput($eName) . "' WHERE type_id='" . InputUtils::legacyFilterInput($theID) . "'"; - RunQuery($sSQL); + $eventType = EventTypeQuery::create()->findOneById(InputUtils::legacyFilterInput($theID)); + $eventType->setName(InputUtils::legacyFilterInput($eName)); + $eventType->save(); $theID = ''; $_POST['Action'] = ''; break; @@ -61,8 +63,9 @@ $editing = 'FALSE'; $eTime = $_POST['newEvtStartTime']; $theID = $_POST['EN_tyid']; - $sSQL = "UPDATE event_types SET type_defstarttime='" . InputUtils::legacyFilterInput($eTime) . "' WHERE type_id='" . InputUtils::legacyFilterInput($theID) . "'"; - RunQuery($sSQL); + $eventType = EventTypeQuery::create()->findOneById(InputUtils::legacyFilterInput($theID)); + $eventType->setDefStartTime(InputUtils::legacyFilterInput($eTime)); + $eventType->save(); $theID = ''; $_POST['Action'] = ''; break; diff --git a/src/EventEditor.php b/src/EventEditor.php index f31e45cfd4..924636c9b2 100644 --- a/src/EventEditor.php +++ b/src/EventEditor.php @@ -28,6 +28,7 @@ use ChurchCRM\Authentication\AuthenticationManager; use ChurchCRM\dto\SystemURLs; use ChurchCRM\model\ChurchCRM\Event; +use ChurchCRM\model\ChurchCRM\EventQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -342,18 +343,21 @@ $sCountNotes = $_POST['EventCountNotes']; // If no errors, then update. - if ($iErrors == 0) { + if ($iErrors === 0) { if ($EventExists == 0) { - $sSQL = "INSERT events_event - SET `event_type` = '" . InputUtils::legacyFilterInput($iTypeID) . "', - `event_title` = '" . InputUtils::legacyFilterInput($sEventTitle) . "', - `event_desc` = '" . InputUtils::legacyFilterInput($sEventDesc) . "', - `event_text` = '" . InputUtils::filterHTML($sEventText) . "', - `event_start` = '" . InputUtils::legacyFilterInput($sEventStart) . "', - `event_end` = '" . InputUtils::legacyFilterInput($sEventEnd) . "', - `inactive` = '" . InputUtils::legacyFilterInput($iEventStatus) . "';"; - RunQuery($sSQL); - $iEventID = mysqli_insert_id($cnInfoCentral); + $event = new Event(); + $event + ->setType(InputUtils::legacyFilterInput($iTypeID)) + ->setTitle(InputUtils::legacyFilterInput($sEventTitle)) + ->setDesc(InputUtils::legacyFilterInput($sEventDesc)) + ->setText(InputUtils::filterHTML($sEventText)) + ->setStart(InputUtils::legacyFilterInput($sEventStart)) + ->setEnd(InputUtils::legacyFilterInput($sEventEnd)) + ->setInActive(InputUtils::legacyFilterInput($iEventStatus)); + $event->save(); + $event->reload(); + + $iEventID = $event->getId(); for ($c = 0; $c < $iNumCounts; $c++) { $cCnt = ltrim(rtrim($aCountName[$c])); $sSQL = "INSERT eventcounts_evtcnt @@ -367,17 +371,16 @@ RunQuery($sSQL); } } else { - $sSQL = "UPDATE events_event - SET `event_type` = '" . InputUtils::legacyFilterInput($iTypeID) . "', - `event_title` = '" . InputUtils::legacyFilterInput($sEventTitle) . "', - `event_desc` = '" . InputUtils::legacyFilterInput($sEventDesc) . "', - `event_text` = '" . InputUtils::filterHTML($sEventText) . "', - `event_start` = '" . InputUtils::legacyFilterInput($sEventStart) . "', - `event_end` = '" . InputUtils::legacyFilterInput($sEventEnd) . "', - `inactive` = '" . InputUtils::legacyFilterInput($iEventStatus) . "' - WHERE `event_id` = '" . InputUtils::legacyFilterInput($iEventID) . "';"; - echo $sSQL; - RunQuery($sSQL); + $event = EventQuery::create()->findOneById(InputUtils::legacyFilterInput($iEventID)); + $event + ->setType(InputUtils::legacyFilterInput($iTypeID)) + ->setTitle(InputUtils::legacyFilterInput($sEventTitle)) + ->setDesc(InputUtils::legacyFilterInput($sEventDesc)) + ->setText(InputUtils::filterHTML($sEventText)) + ->setStart(InputUtils::legacyFilterInput($sEventStart)) + ->setEnd(InputUtils::legacyFilterInput($sEventEnd)) + ->setInActive(InputUtils::legacyFilterInput($iEventStatus)); + $event->save(); for ($c = 0; $c < $iNumCounts; $c++) { $cCnt = ltrim(rtrim($aCountName[$c])); $sSQL = "INSERT eventcounts_evtcnt @@ -407,7 +410,7 @@
" . gettext('There were ') . $iErrors . gettext(' errors. Please see below') . '
'; } else { echo '
' . gettext('Items with a ') . '*' . gettext(' are required') . '
'; diff --git a/src/FamilyEditor.php b/src/FamilyEditor.php index 2b9519328a..095b2b32ff 100644 --- a/src/FamilyEditor.php +++ b/src/FamilyEditor.php @@ -21,6 +21,8 @@ use ChurchCRM\Emails\NewPersonOrFamilyEmail; use ChurchCRM\model\ChurchCRM\FamilyQuery; use ChurchCRM\model\ChurchCRM\Note; +use ChurchCRM\model\ChurchCRM\Person; +use ChurchCRM\model\ChurchCRM\PersonQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -366,43 +368,31 @@ $sLastNameToEnter = $sName; } - RunQuery('LOCK TABLES person_per WRITE, person_custom WRITE'); - $sSQL = "INSERT INTO person_per ( - per_FirstName, - per_MiddleName, - per_LastName, - per_Suffix, - per_fam_ID, - per_fmr_ID, - per_DateEntered, - per_EnteredBy, - per_Gender, - per_BirthDay, - per_BirthMonth, - per_BirthYear, - per_cls_ID) - VALUES ( - '$aFirstNames[$iCount]', - '$aMiddleNames[$iCount]', - '$sLastNameToEnter', - '$aSuffix[$iCount]', - $iFamilyID, - $aRoles[$iCount], - '" . date('YmdHis') . "', - " . AuthenticationManager::getCurrentUser()->getId() . ", - $aGenders[$iCount], - $aBirthDays[$iCount], - $aBirthMonths[$iCount], - $aBirthYears[$iCount], - $aClassification[$iCount])"; - RunQuery($sSQL); - $dbPersonId = mysqli_insert_id($cnInfoCentral); + $person = new Person(); + $person + ->setFirstName($aFirstNames[$iCount]) + ->setMiddleName($aMiddleNames[$iCount]) + ->setLastName($sLastNameToEnter) + ->setSuffix($aSuffix[$iCount]) + ->setFamId($iFamilyID) + ->setFmrId($aRoles[$iCount]) + ->setDateEntered(date('YmdHis')) + ->setEnteredBy(AuthenticationManager::getCurrentUser()->getId()) + ->setGender($aGenders[$iCount]) + ->setBirthDay($aBirthDays[$iCount]) + ->setBirthMonth($aBirthMonths[$iCount]) + ->setBirthYear($aBirthYears[$iCount]) + ->setClsId($aClassification[$iCount]); + $person->save(); + $person->reload(); + $dbPersonId = $person->getId(); $note = new Note(); $note->setPerId($dbPersonId); $note->setText(gettext('Created via Family')); $note->setType('create'); $note->setEntered(AuthenticationManager::getCurrentUser()->getId()); $note->save(); + RunQuery('LOCK TABLES person_custom WRITE'); $sSQL = 'INSERT INTO person_custom (per_ID) VALUES (' . $dbPersonId . ')'; RunQuery($sSQL); @@ -432,10 +422,22 @@ } else { $sLastNameToEnter = $sName; } - $sBirthYearScript = ($aUpdateBirthYear[$iCount] & 1) ? 'per_BirthYear=' . $aBirthYears[$iCount] . ', ' : ''; //RunQuery("LOCK TABLES person_per WRITE, person_custom WRITE"); - $sSQL = "UPDATE person_per SET per_FirstName='" . $aFirstNames[$iCount] . "', per_MiddleName='" . $aMiddleNames[$iCount] . "',per_LastName='" . $aLastNames[$iCount] . "',per_Suffix='" . $aSuffix[$iCount] . "',per_Gender='" . $aGenders[$iCount] . "',per_fmr_ID='" . $aRoles[$iCount] . "',per_BirthMonth='" . $aBirthMonths[$iCount] . "',per_BirthDay='" . $aBirthDays[$iCount] . "', " . $sBirthYearScript . "per_cls_ID='" . $aClassification[$iCount] . "' WHERE per_ID=" . $aPersonIDs[$iCount]; - RunQuery($sSQL); + $person = PersonQuery::create()->findOneById($aPersonIDs[$iCount]); + $person + ->setFirstName($aFirstNames[$iCount]) + ->setMiddleName($aMiddleNames[$iCount]) + ->setLastName($aLastNames[$iCount]) + ->setSuffix($aSuffix[$iCount]) + ->setGender($aGenders[$iCount]) + ->setFmrId($aRoles[$iCount]) + ->setBirthMonth($aBirthMonths[$iCount]) + ->setBirthDay($aBirthDays[$iCount]) + ->setClsId($aClassification); + if ($aUpdateBirthYear[$iCount] & 1) { + $person->setBirthYear($aBirthYears[$iCount]); + } + $person->save(); //RunQuery("UNLOCK TABLES"); $note = new Note(); diff --git a/src/FundRaiserEditor.php b/src/FundRaiserEditor.php index 26df7ef8a0..70e4f7dab5 100644 --- a/src/FundRaiserEditor.php +++ b/src/FundRaiserEditor.php @@ -15,6 +15,7 @@ use ChurchCRM\Authentication\AuthenticationManager; use ChurchCRM\model\ChurchCRM\FundRaiser; +use ChurchCRM\model\ChurchCRM\FundRaiserQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -69,24 +70,23 @@ ->setEnteredBy(AuthenticationManager::getCurrentUser()->getId()) ->setEnteredDate(date('YmdHis')); $fundraiser->save(); + $fundraiser->reload(); - $bGetKeyBack = true; + $iFundRaiserID = $fundraiser->getId(); // Existing record (update) } else { - $sSQL = "UPDATE fundraiser_fr SET fr_date = '" . $dDate . "', fr_title = '" . $sTitle . "', fr_description = '" . $sDescription . "', fr_EnteredBy = " . AuthenticationManager::getCurrentUser()->getId() . ", fr_EnteredDate='" . date('YmdHis') . "' WHERE fr_ID = " . $iFundRaiserID . ';'; - $bGetKeyBack = false; - } - //Execute the SQL - RunQuery($sSQL); - - // If this is a new fundraiser, get the key back - if ($bGetKeyBack) { - $sSQL = 'SELECT MAX(fr_ID) AS iFundRaiserID FROM fundraiser_fr'; - $rsFundRaiserID = RunQuery($sSQL); - extract(mysqli_fetch_array($rsFundRaiserID)); - $_SESSION['iCurrentFundraiser'] = $iFundRaiserID; + $fundraiser = FundRaiserQuery::create()->findOneById($iFundRaiserID); + $fundraiser + ->setDate($dDate) + ->setTitle($sTitle) + ->setDescription($sDescription) + ->setEnteredBy(AuthenticationManager::getCurrentUser()->getId()) + ->setEnteredDate(date('YmdHis')); + $fundraiser->save(); } + $_SESSION['iCurrentFundraiser'] = $iFundRaiserID; + if (isset($_POST['FundRaiserSubmit'])) { if ($linkBack != '') { RedirectUtils::redirect($linkBack); diff --git a/src/ListEvents.php b/src/ListEvents.php index 7d4e56ab35..a3e0b8fe5b 100644 --- a/src/ListEvents.php +++ b/src/ListEvents.php @@ -23,6 +23,7 @@ use ChurchCRM\Authentication\AuthenticationManager; use ChurchCRM\dto\SystemURLs; +use ChurchCRM\model\ChurchCRM\EventQuery; use ChurchCRM\Utils\InputUtils; $eType = 'All'; @@ -65,8 +66,9 @@ $sSQL = 'DELETE FROM eventcounts_evtcnt WHERE evtcnt_eventid = ' . $eID; RunQuery($sSQL); } elseif ($action == 'Activate' && $eID) { - $sSQL = 'UPDATE events_event SET inactive = 0 WHERE event_id = ' . $eID . ' LIMIT 1'; - RunQuery($sSQL); + $event = EventQuery::create()->findOneById($eID); + $event->setInActive(0); + $event->save(); } } diff --git a/src/ManageEnvelopes.php b/src/ManageEnvelopes.php index 100468b791..ee2fbc6827 100644 --- a/src/ManageEnvelopes.php +++ b/src/ManageEnvelopes.php @@ -17,6 +17,7 @@ use ChurchCRM\Authentication\AuthenticationManager; use ChurchCRM\dto\SystemConfig; +use ChurchCRM\model\ChurchCRM\FamilyQuery; use ChurchCRM\Utils\RedirectUtils; //Set the page title @@ -46,8 +47,9 @@ } } foreach ($envelopesToWrite as $fam_ID => $envelope) { - $dSQL = "UPDATE family_fam SET fam_Envelope='" . $envelope . "' WHERE fam_ID='" . $fam_ID . "'"; - RunQuery($dSQL); + $family = FamilyQuery::create()->findOneById($fam_ID); + $family->setEnvelope($envelope); + $family->save(); } } diff --git a/src/PledgeEditor.php b/src/PledgeEditor.php index 16dbd136cf..17a32ea9de 100644 --- a/src/PledgeEditor.php +++ b/src/PledgeEditor.php @@ -438,8 +438,9 @@ $tScanString = InputUtils::legacyFilterInput($_POST['ScanInput']); $routeAndAccount = $micrObj->findRouteAndAccount($tScanString); // use routing and account number for matching $iFamily = InputUtils::legacyFilterInput($_POST['FamilyID'], 'int'); - $sSQL = 'UPDATE family_fam SET fam_scanCheck="' . $routeAndAccount . '" WHERE fam_ID = ' . $iFamily; - RunQuery($sSQL); + $family = \ChurchCRM\model\ChurchCRM\FamilyQuery::create()->findOneById($iFamily); + $family->setScanCheck($routeAndAccount); + $family->save(); } } diff --git a/src/PropertyEditor.php b/src/PropertyEditor.php index c09e5811cc..70b9111c78 100644 --- a/src/PropertyEditor.php +++ b/src/PropertyEditor.php @@ -15,6 +15,7 @@ use ChurchCRM\Authentication\AuthenticationManager; use ChurchCRM\model\ChurchCRM\Property; +use ChurchCRM\model\ChurchCRM\PropertyQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -91,10 +92,13 @@ ->setProPrompt($sPrompt); $property->save(); } else { - $sSQL = 'UPDATE property_pro SET pro_prt_ID = ' . $iClass . ", pro_Name = '" . $sName . "', pro_Description = '" . $sDescription . "', pro_Prompt = '" . $sPrompt . "' WHERE pro_ID = " . $iPropertyID; - - //Execute the SQL - RunQuery($sSQL); + $property = PropertyQuery::create()->findOneByProId($iPropertyID); + $property + ->setProPrtId($iClass) + ->setProName($sName) + ->setProDescription($sDescription) + ->setProPrompt($sPrompt); + $property->save(); } //Route back to the list diff --git a/src/UserEditor.php b/src/UserEditor.php index 1ea58bfed8..bdd429b0d6 100644 --- a/src/UserEditor.php +++ b/src/UserEditor.php @@ -159,10 +159,23 @@ } } else { if ($undupCount == 0) { - $sSQL = 'UPDATE user_usr SET usr_AddRecords = ' . $AddRecords . ', usr_EditRecords = ' . $EditRecords . ', usr_DeleteRecords = ' . $DeleteRecords . ', usr_MenuOptions = ' . $MenuOptions . ', usr_ManageGroups = ' . $ManageGroups . ', usr_Finance = ' . $Finance . ', usr_Notes = ' . $Notes . ', usr_Admin = ' . $Admin . ', usr_Style = "' . $Style . '", usr_UserName = "' . $sUserName . '", usr_EditSelf = "' . $EditSelf . '", usr_Canvasser = ' . $Canvasser . ' WHERE usr_per_ID = ' . $iPersonID; - // Execute the SQL - RunQuery($sSQL); - $user = UserQuery::create()->findPk($iPersonID); + $user = UserQuery::create()->findOneByPersonId($iPersonID); + $user + ->setAddRecords($AddRecords) + ->setEditRecords($EditRecords) + ->setDeleteRecords($DeleteRecords) + ->setMenuOptions($MenuOptions) + ->setManageGroups($ManageGroups) + ->setFinance($Finance) + ->setNotes($Notes) + ->setAdmin($Admin) + ->setUserStyle($Style) + ->setUserName($sUserName) + ->setEditSelf($EditSelf) + ->setCanvasser($Canvasser); + $user->save(); + $user->reload(); + $user->createTimeLineNote("updated"); } else { // Set the error text for duplicate when currently existing diff --git a/src/VolunteerOpportunityEditor.php b/src/VolunteerOpportunityEditor.php index 8926c16d8b..3e5653bfa5 100644 --- a/src/VolunteerOpportunityEditor.php +++ b/src/VolunteerOpportunityEditor.php @@ -13,6 +13,7 @@ use ChurchCRM\Authentication\AuthenticationManager; use ChurchCRM\model\ChurchCRM\VolunteerOpportunity; +use ChurchCRM\model\ChurchCRM\VolunteerOpportunityQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -156,10 +157,9 @@ $aRow = mysqli_fetch_array($rsOrder); extract($aRow); $num_vol_Order = $Max_vol_Order + $row; - $sSQL = 'UPDATE `volunteeropportunity_vol` ' . - "SET `vol_Order` = '" . $num_vol_Order . "' " . - "WHERE `vol_ID` = '" . $vol_ID . "'"; - RunQuery($sSQL); + $volunteerOpp = VolunteerOpportunityQuery::create()->findOneById($vol_ID); + $volunteerOpp->setOrder($num_vol_Order); + $volunteerOpp->save(); } } @@ -174,10 +174,9 @@ $aRow = mysqli_fetch_array($rsOpps); extract($aRow); if ($orderCounter != $vol_Order) { // found hole, update all records to the end - $sSQL = 'UPDATE `volunteeropportunity_vol` ' . - "SET `vol_Order` = '" . $orderCounter . "' " . - "WHERE `vol_ID` = '" . $vol_ID . "'"; - RunQuery($sSQL); + $volunteerOpp = VolunteerOpportunityQuery::create()->findOneById($vol_ID); + $volunteerOpp->setOrder($orderCounter); + $volunteerOpp->save(); } ++$orderCounter; } @@ -217,11 +216,11 @@ if (!$bErrorFlag) { for ($iFieldID = 1; $iFieldID <= $numRows; $iFieldID++) { if (array_key_exists($iFieldID, $aNameFields)) { - $sSQL = "UPDATE volunteeropportunity_vol - SET vol_Name = '" . $aNameFields[$iFieldID] . "', - vol_Description = '" . $aDescFields[$iFieldID] . - "' WHERE vol_ID = '" . $aIDFields[$iFieldID] . "';"; - RunQuery($sSQL); + $volunteerOpp = VolunteerOpportunityQuery::create()->findOneById($aIDFields[$iFieldID]); + $volunteerOpp + ->setName($aNameFields[$iFieldID]) + ->setDescription($aDescFields[$iFieldID]); + $volunteerOpp->save(); } } } @@ -291,17 +290,15 @@ } if (array_key_exists($swapRow, $aIDFields)) { - $sSQL = "UPDATE volunteeropportunity_vol - SET vol_Order = '" . $newRow . "' " . - "WHERE vol_ID = '" . $aIDFields[$swapRow] . "';"; - RunQuery($sSQL); + $volunteerOpp = VolunteerOpportunityQuery::create()->findOneById($aIDFields[$swapRow]); + $volunteerOpp->setOrder($newRow); + $volunteerOpp->save(); } if (array_key_exists($newRow, $aIDFields)) { - $sSQL = "UPDATE volunteeropportunity_vol - SET vol_Order = '" . $swapRow . "' " . - "WHERE vol_ID = '" . $aIDFields[$newRow] . "';"; - RunQuery($sSQL); + $volunteerOpp = VolunteerOpportunityQuery::create()->findOneById($aIDFields[$newRow]); + $volunteerOpp->setOrder($swapRow); + $volunteerOpp->save(); } // now update internal data to match diff --git a/src/WhyCameEditor.php b/src/WhyCameEditor.php index 5381c5b409..3f7d8938e7 100644 --- a/src/WhyCameEditor.php +++ b/src/WhyCameEditor.php @@ -19,6 +19,7 @@ require 'Include/Functions.php'; use ChurchCRM\model\ChurchCRM\WhyCame; +use ChurchCRM\model\ChurchCRM\WhyCameQuery; use ChurchCRM\Utils\InputUtils; use ChurchCRM\Utils\RedirectUtils; @@ -52,9 +53,13 @@ $whyCame->save(); // Existing record (update) } else { - $sSQL = 'UPDATE whycame_why SET why_join = "' . $tJoin . '", why_come = "' . $tCome . '", why_suggest = "' . $tSuggest . '", why_hearOfUs = "' . $tHearOfUs . '" WHERE why_per_ID = ' . $iPerson; - //Execute the SQL - RunQuery($sSQL); + $whyCame = WhyCameQuery::create()->findOneByPerId($iPerson); + $whyCame + ->setJoin($tJoin) + ->setCome($tCome) + ->setSuggest($tSuggest) + ->setHearOfUs($tHearOfUs); + $whyCame->save(); } if (isset($_POST['Submit'])) {