/** * 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 HouseholdParticipationMetaControl * @param integer $intId primary key value * @param QMetaControlCreateType $intCreateType rules governing HouseholdParticipation object creation - defaults to CreateOrEdit * @return HouseholdParticipationMetaControl */ public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intId)) { $objHouseholdParticipation = HouseholdParticipation::Load($intId); // HouseholdParticipation was found -- return it! if ($objHouseholdParticipation) { return new HouseholdParticipationMetaControl($objParentObject, $objHouseholdParticipation); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a HouseholdParticipation 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 HouseholdParticipationMetaControl($objParentObject, new HouseholdParticipation()); }
protected function btnSave_Click($strFormId, $strControlId, $strParameter) { $this->dlgMessage->RemoveAllButtons(); $radSelected = null; foreach ($this->radSelectArray as $radSelect) { if ($radSelect->Checked) { if ($radSelected) { $this->dlgMessage->MessageHtml = 'You cannot remove more than one person at a time.'; $this->dlgMessage->ShowDialogBox(); return; } $radSelected = $radSelect; } } if (!$radSelected) { $this->dlgMessage->MessageHtml = 'You must select a person to remove.'; $this->dlgMessage->ShowDialogBox(); return; } $objParticipation = HouseholdParticipation::Load($radSelected->ActionParameter); if ($objParticipation->HouseholdId != $this->objHousehold->Id) { $this->dlgMessage->MessageHtml = 'Participation record not for this household.'; $this->dlgMessage->ShowDialogBox(); return; } $this->objPersonToRemove = $objParticipation->Person; switch ($this->objPersonToRemove->GetHouseholdStatus()) { case Person::HouseholdStatusMemberOfOne: $this->dlgMessage->MessageHtml = sprintf('<strong>%s</strong> does not belong to any other household records. Make %s an individual with no household records, or delete %s record altogether?', QApplication::HtmlEntities($this->objPersonToRemove->Name), $this->objPersonToRemove->PronounIndirectObject, $this->objPersonToRemove->PronounAdjective); $this->dlgMessage->AddButton('Make Individual', MessageDialog::ButtonPrimary, 'RemoveFromHousehold'); $this->dlgMessage->AddButton('Delete Record', MessageDialog::ButtonPrimary, 'DeletePerson'); $this->dlgMessage->AddButton('Cancel', MessageDialog::ButtonSecondary, 'HideDialogBox', $this->dlgMessage); break; case Person::HouseholdStatusMemberOfMultiple: if ($this->objPersonToRemove->CountHouseholdParticipations() == 2) { $this->dlgMessage->MessageHtml = '<strong>%s</strong> belongs to another household. After removing %s from the %s, %s will still be a member of the other household.'; } else { $this->dlgMessage->MessageHtml = '<strong>%s</strong> belongs to other households. After removing %s from the %s, %s will still be a member of these other households.'; } $this->dlgMessage->MessageHtml = sprintf($this->dlgMessage->MessageHtml, QApplication::HtmlEntities($this->objPersonToRemove->Name), $this->objPersonToRemove->PronounIndirectObject, QApplication::HtmlEntities($this->objHousehold->Name), $this->objPersonToRemove->PronounSubject); $this->dlgMessage->AddButton('Okay', MessageDialog::ButtonPrimary, 'RemoveFromHousehold'); $this->dlgMessage->AddButton('Cancel', MessageDialog::ButtonSecondary, 'HideDialogBox', $this->dlgMessage); break; case Person::HouseholdStatusNone: case Person::HouseholdStatusHeadOfOne: case Person::HouseholdStatusHeadOfFamily: case Person::HouseholdStatusError: default: $this->dlgMessage->MessageHtml = sprintf('An unknown data error occurred while trying to remove <strong>%s</strong> from this "%s" household. Please contact a ChMS Administrator to report the issue.', QApplication::HtmlEntities($this->objPersonToRemove->Name), QApplication::HtmlEntities($this->objHousehold->Name)); break; } $this->dlgMessage->ShowDialogBox(); }
/** * Reload this HouseholdParticipation from the database. * @return void */ public function Reload() { // Make sure we are actually Restored from the database if (!$this->__blnRestored) { throw new QCallerException('Cannot call Reload() on a new, unsaved HouseholdParticipation object.'); } // Reload the Object $objReloaded = HouseholdParticipation::Load($this->intId); // Update $this's local variables to match $this->PersonId = $objReloaded->PersonId; $this->HouseholdId = $objReloaded->HouseholdId; $this->strRole = $objReloaded->strRole; $this->strRoleOverride = $objReloaded->strRoleOverride; }
protected function btnNext_Click($strFormId, $strControlId, $strParameter) { // Get Participation Records $this->objSelectedPersonArray = array(); foreach ($this->chkSelectArray as $chkSelect) { if ($chkSelect->Checked) { $objParticipation = HouseholdParticipation::Load($chkSelect->ActionParameter); if ($objParticipation->HouseholdId != $this->objHousehold->Id) { throw new Exception('Invalid Participation Selected'); } $this->objSelectedPersonArray[] = $objParticipation->Person; } } if (!count($this->objSelectedPersonArray)) { $this->dlgMessage->RemoveAllButtons(); $this->dlgMessage->MessageHtml = 'You must select at least one person.'; $this->dlgMessage->ShowDialogBox(); return; } else { $strNameArray = array(); foreach ($this->objSelectedPersonArray as $objPerson) { $strNameArray[] = $objPerson->FirstName; } $this->lblHeadline->Text = 'Selected: ' . implode(', ', $strNameArray); $this->dtgMembers->Visible = false; $this->lstHead->Visible = true; $this->pnlAddress->Visible = true; $this->pnlAddress->objDelegate = new EditHomeAddressDelegate($this->pnlAddress, null, null, false); // Since this HomeAddress panel/delegate is really for a NEW household's address, we want to set it to null $this->pnlAddress->objDelegate->mctAddress->Address->Household = null; $this->btnNext->Visible = false; $this->btnSave->Visible = true; $this->lstHead->RemoveAllItems(); foreach ($this->objSelectedPersonArray as $objPerson) { $this->lstHead->AddItem($objPerson->Name, $objPerson->Id); } $this->lstHead->SelectedIndex = 0; } }