/** * Reload this Membership 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 Membership object.'); } // Reload the Object $objReloaded = Membership::Load($this->intId); // Update $this's local variables to match $this->PersonId = $objReloaded->PersonId; $this->dttDateStart = $objReloaded->dttDateStart; $this->dttDateEnd = $objReloaded->dttDateEnd; $this->strTerminationReason = $objReloaded->strTerminationReason; }
protected function SetupPanel() { // Ensure the User is allowed to Edit Memberships if (!QApplication::IsLoginHasPermission(PermissionType::EditMembershipStatus)) { return $this->ReturnTo('#general/view_membership'); } // Get and Validate the Membership Object $this->objMembership = Membership::Load($this->strUrlHashArgument); if (!$this->objMembership) { // Trying to create a NEW membership // Let's make sure this person doesn't have a current membership if ($this->objPerson->CurrentMembershipInfo) { return $this->ReturnTo('#general/view_membership'); } $this->objMembership = new Membership(); $this->objMembership->Person = $this->objPerson; $this->blnEditMode = false; $this->btnSave->Text = 'Create'; } else { // Ensure the Membership object belongs to the person if ($this->objMembership->PersonId != $this->objPerson->Id) { return $this->ReturnTo('#general/view_membership'); } $this->blnEditMode = true; $this->btnSave->Text = 'Update'; $this->btnDelete = new QLinkButton($this); $this->btnDelete->Text = 'Delete'; $this->btnDelete->CssClass = 'delete'; $this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction('Are you SURE you want to permenantly DELETE this record?')); $this->btnDelete->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click')); $this->btnDelete->AddAction(new QClickEvent(), new QTerminateAction()); } // Create Controls $this->dtxDateStart = new QDateTimeTextBox($this); $this->dtxDateStart->Name = 'Membership Started'; $this->dtxDateStart->Required = true; $this->dtxDateStart->Text = $this->objMembership->DateStart ? $this->objMembership->DateStart->__toString() : null; $this->calDateStart = new QCalendar($this, $this->dtxDateStart); $this->dtxDateEnd = new QDateTimeTextBox($this); $this->dtxDateEnd->Name = 'Membership Ended'; $this->dtxDateEnd->Text = $this->objMembership->DateEnd ? $this->objMembership->DateEnd->__toString() : null; $this->dtxDateEnd->AddAction(new QBlurEvent(), new QAjaxControlAction($this, 'dtxDateEnd_Blur')); $this->calDateEnd = new QCalendar($this, $this->dtxDateEnd); $this->dtxDateStart->RemoveAllActions(QClickEvent::EventName); $this->dtxDateEnd->RemoveAllActions(QClickEvent::EventName); $this->lstTermination = new QListBox($this); $this->lstTermination->Name = 'Reason for Termination'; $this->lstTermination->AddItem('- Select One -', null); if ($strTerminationReasons = Registry::GetValue('membership_termination_reason')) { foreach (explode(',', $strTerminationReasons) as $strReason) { $strReason = trim($strReason); $this->lstTermination->AddItem($strReason, $strReason, strtolower($strReason) == strtolower($this->objMembership->TerminationReason)); } } $this->lstTermination->AddItem('- Other... -', -1); // Setup "Other" textbox $this->txtTermination = new QTextBox($this); $this->txtTermination->Name = ' '; // Pre-Select "Other" if applicable if ($this->objMembership->TerminationReason && is_null($this->lstTermination->SelectedValue)) { $this->lstTermination->SelectedValue = -1; $this->txtTermination->Text = $this->objMembership->TerminationReason; } // Setup and Call Actions $this->lstTermination->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'txtTermination_Refresh')); $this->txtTermination_Refresh(); $this->dtxDateEnd_Blur(); }
/** * 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 MembershipMetaControl * @param integer $intId primary key value * @param QMetaControlCreateType $intCreateType rules governing Membership object creation - defaults to CreateOrEdit * @return MembershipMetaControl */ public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intId)) { $objMembership = Membership::Load($intId); // Membership was found -- return it! if ($objMembership) { return new MembershipMetaControl($objParentObject, $objMembership); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a Membership 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 MembershipMetaControl($objParentObject, new Membership()); }