/** * Deletes all associated StewardshipPostLineItems * @return void */ public function DeleteAllStewardshipPostLineItems() { if (is_null($this->intId)) { throw new QUndefinedPrimaryKeyException('Unable to call UnassociateStewardshipPostLineItem on this unsaved StewardshipPost.'); } // Get the Database Object for this Class $objDatabase = StewardshipPost::GetDatabase(); // Journaling if ($objDatabase->JournalingDatabase) { foreach (StewardshipPostLineItem::LoadArrayByStewardshipPostId($this->intId) as $objStewardshipPostLineItem) { $objStewardshipPostLineItem->Journal('DELETE'); } } // Perform the SQL Query $objDatabase->NonQuery(' DELETE FROM `stewardship_post_line_item` WHERE `stewardship_post_id` = ' . $objDatabase->SqlVariable($this->intId) . ' '); }
public static function GetSoapArrayFromArray($objArray) { if (!$objArray) { return null; } $objArrayToReturn = array(); foreach ($objArray as $objObject) { array_push($objArrayToReturn, StewardshipPostLineItem::GetSoapObjectFromObject($objObject, true)); } return unserialize(serialize($objArrayToReturn)); }
/** * Main utility method to aid with data binding. It is used by the default BindAllRows() databinder but * could and should be used by any custom databind methods that would be used for instances of this * MetaDataGrid, by simply passing in a custom QQCondition and/or QQClause. * * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used. * It will also perform any sorting (if applicable). * * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query * @return void */ public function MetaDataBinder(QQCondition $objCondition = null, $objOptionalClauses = null) { // Setup input parameters to default values if none passed in if (!$objCondition) { $objCondition = QQ::All(); } $objClauses = $objOptionalClauses ? $objOptionalClauses : array(); // We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below if ($this->Paginator) { $this->TotalItemCount = StewardshipPostLineItem::QueryCount($objCondition, $objClauses); } // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add // the OrderByClause to the $objClauses array if ($objClause = $this->OrderByClause) { array_push($objClauses, $objClause); } // Add the LimitClause information, as well if ($objClause = $this->LimitClause) { array_push($objClauses, $objClause); } // Set the DataSource to be a Query result from StewardshipPostLineItem, given the clauses above $this->DataSource = StewardshipPostLineItem::QueryArray($objCondition, $objClauses); }
/** * Static Helper Method to Create using PK arguments * You must pass in the PK arguments on an object to load, or leave it blank to create a new one. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to * edit, or if we are also allowed to create a new one, etc. * * @param mixed $objParentObject QForm or QPanel which will be using this StewardshipPostLineItemMetaControl * @param integer $intId primary key value * @param QMetaControlCreateType $intCreateType rules governing StewardshipPostLineItem object creation - defaults to CreateOrEdit * @return StewardshipPostLineItemMetaControl */ public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intId)) { $objStewardshipPostLineItem = StewardshipPostLineItem::Load($intId); // StewardshipPostLineItem was found -- return it! if ($objStewardshipPostLineItem) { return new StewardshipPostLineItemMetaControl($objParentObject, $objStewardshipPostLineItem); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a StewardshipPostLineItem object with PK arguments: ' . $intId); } } // If EditOnly is specified, throw an exception } else { if ($intCreateType == QMetaControlCreateType::EditOnly) { throw new QCallerException('No PK arguments specified'); } } // If we are here, then we need to create a new record return new StewardshipPostLineItemMetaControl($objParentObject, new StewardshipPostLineItem()); }
/** * Given this "unposted" Contribution entry, this will create PostLineItem(s) for this contribution entry * for a given StewardshipPost object. * * This will also update the UnpostedFlag to false and save. * * This will return a boolean specifying whether or not anything was actually posted. * * @param StewardshipPost $objPost the post to submit post-line-items for * @return boolean */ public function PostLineItems(StewardshipPost $objPost) { // Note that all fltArrays are multidimensional arrays that track amounts based on PersonId and FundId // e.g. $fltArray[$intPersonId][$intFundId] = $fltAmount // Calculate Posted-thus-far $fltPostedArray = array(); foreach (StewardshipPostLineItem::LoadArrayByStewardshipContributionId($this->intId) as $objPostLineItem) { if (!array_key_exists($objPostLineItem->PersonId, $fltPostedArray)) { $fltPostedArray[$objPostLineItem->PersonId] = array(); } if (!array_key_exists($objPostLineItem->StewardshipFundId, $fltPostedArray[$objPostLineItem->PersonId])) { $fltPostedArray[$objPostLineItem->PersonId][$objPostLineItem->StewardshipFundId] = $objPostLineItem->Amount; } else { $fltPostedArray[$objPostLineItem->PersonId][$objPostLineItem->StewardshipFundId] += $objPostLineItem->Amount; } } // Calculate the Actuals $fltActualArray = array(); $fltActualArray[$this->PersonId] = array(); foreach ($this->GetStewardshipContributionAmountArray() as $objAmount) { if (!array_key_exists($objAmount->StewardshipFundId, $fltActualArray[$this->PersonId])) { $fltActualArray[$this->PersonId][$objAmount->StewardshipFundId] = $objAmount->Amount; } else { $fltActualArray[$this->PersonId][$objAmount->StewardshipFundId] += $objAmount->Amount; } } // Calculate Difference/Discrepancies to Post foreach ($fltPostedArray as $intPersonId => $fltAmountByFundArray) { if (!array_key_exists($intPersonId, $fltActualArray)) { $fltActualArray[$intPersonId] = array(); } foreach ($fltAmountByFundArray as $intFundId => $fltAmount) { if (!array_key_exists($intFundId, $fltActualArray[$intPersonId])) { $fltActualArray[$intPersonId][$intFundId] = 0; } } } foreach ($fltActualArray as $intPersonId => $fltAmountByFundArray) { if (!array_key_exists($intPersonId, $fltPostedArray)) { $fltPostedArray[$intPersonId] = array(); } foreach ($fltAmountByFundArray as $intFundId => $fltAmount) { if (!array_key_exists($intFundId, $fltPostedArray[$intPersonId])) { $fltPostedArray[$intPersonId][$intFundId] = 0; } } } $fltDifferenceArray = array(); foreach ($fltActualArray as $intPersonId => $fltAmountByFundArray) { foreach ($fltAmountByFundArray as $intFundId => $fltAmount) { if ($fltAmount != $fltPostedArray[$intPersonId][$intFundId]) { $fltDifferenceArray[$intPersonId][$intFundId] = $fltAmount - $fltPostedArray[$intPersonId][$intFundId]; } } } // Post any differences that were calculated (if applicable) $blnPosted = false; foreach ($fltDifferenceArray as $intPersonId => $fltAmountByFundArray) { foreach ($fltAmountByFundArray as $intFundId => $fltAmount) { $objPostLineItem = new StewardshipPostLineItem(); $objPostLineItem->StewardshipPost = $objPost; $objPostLineItem->StewardshipContribution = $this; $objPostLineItem->PersonId = $intPersonId; $objPostLineItem->StewardshipFundId = $intFundId; $objPostLineItem->Description = $this->PostLineItemDescription; $objPostLineItem->Amount = $fltAmount; $objPostLineItem->Save(); $blnPosted = true; } } $this->blnUnpostedFlag = false; $this->Save(); return $blnPosted; }