protected function SetupPanel() { // Get and Validate the Marriage Object $this->objRelationship = Relationship::Load($this->strUrlHashArgument); if (!$this->objRelationship) { // Trying to create a NEW relationship $this->objRelationship = new Relationship(); $this->objRelationship->Person = $this->objPerson; $this->blnEditMode = false; $this->btnSave->Text = 'Create'; } else { // Ensure the Relationship object belongs to the person if ($this->objRelationship->PersonId != $this->objPerson->Id) { return $this->ReturnTo('#general/view_family'); } $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->lstRelation = new QListBox($this); $this->lstRelation->Name = 'Relationship'; if (!$this->objRelationship->RelationshipTypeId) { $this->lstRelation->AddItem('- Select One -', null); } $this->lstRelation->Required = true; foreach (RelationshipType::$NameArray as $intId => $strName) { $this->lstRelation->AddItem($strName, $intId, $intId == $this->objRelationship->RelationshipTypeId); } // Create "Married To" Controls if ($this->objRelationship->RelatedToPerson) { $this->lblRelatedTo = new QLabel($this); $this->lblRelatedTo->Name = 'Related To'; $this->lblRelatedTo->Text = $this->objRelationship->RelatedToPerson->LinkHtml; $this->lblRelatedTo->HtmlEntities = false; } else { $this->pnlRelatedTo = new SelectPersonPanel($this); $this->pnlRelatedTo->Name = 'Related To'; $this->pnlRelatedTo->AllowCreate = true; $this->pnlRelatedTo->Required = true; } }
/** * 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 RelationshipMetaControl * @param integer $intId primary key value * @param QMetaControlCreateType $intCreateType rules governing Relationship object creation - defaults to CreateOrEdit * @return RelationshipMetaControl */ public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intId)) { $objRelationship = Relationship::Load($intId); // Relationship was found -- return it! if ($objRelationship) { return new RelationshipMetaControl($objParentObject, $objRelationship); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a Relationship 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 RelationshipMetaControl($objParentObject, new Relationship()); }
/** * Reload this Relationship 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 Relationship object.'); } // Reload the Object $objReloaded = Relationship::Load($this->intId); // Update $this's local variables to match $this->PersonId = $objReloaded->PersonId; $this->RelatedToPersonId = $objReloaded->RelatedToPersonId; $this->RelationshipTypeId = $objReloaded->RelationshipTypeId; }