本文整理汇总了PHP中Relationship::Save方法的典型用法代码示例。如果您正苦于以下问题:PHP Relationship::Save方法的具体用法?PHP Relationship::Save怎么用?PHP Relationship::Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Relationship
的用法示例。
在下文中一共展示了Relationship::Save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: UpdateLinkedRelationship
/**
* Given this relationship record, this will update the "linked" relationship record with the same stats and details.
*
* This will CREATE the Linked Relationship record if none yet exists.
*
*/
public function UpdateLinkedRelationship()
{
$objPerson = $this->Person;
$objRelatedPerson = $this->RelatedToPerson;
$objLinkedRelationship = Relationship::LoadByPersonIdRelatedToPersonId($objRelatedPerson->Id, $objPerson->Id);
if (!$objLinkedRelationship) {
$objLinkedRelationship = new Relationship();
$objLinkedRelationship->Person = $objRelatedPerson;
$objLinkedRelationship->RelatedToPerson = $objPerson;
}
// Figure out the "Opposite" relationship to create
switch ($this->intRelationshipTypeId) {
case RelationshipType::Child:
$objLinkedRelationship->RelationshipTypeId = RelationshipType::Parental;
break;
case RelationshipType::Parental:
$objLinkedRelationship->RelationshipTypeId = RelationshipType::Child;
break;
case RelationshipType::Sibling:
$objLinkedRelationship->RelationshipTypeId = RelationshipType::Sibling;
break;
case RelationshipType::Grandchild:
$objLinkedRelationship->RelationshipTypeId = RelationshipType::Grandparent;
break;
case RelationshipType::Grandparent:
$objLinkedRelationship->RelationshipTypeId = RelationshipType::Grandchild;
break;
default:
throw new Exception('Invalid Relationship Type Id: ' . $intRelationshipTypeId);
}
$objLinkedRelationship->Save();
}
示例2: AddRelationship
/**
* Given a Person to be related to an a RelationshipTypeId, this will create BOTH ends of
* the relationship (e.g. TWO relationship records).
*
* If a relationship of any kind is already defined between these two individuals, this will
* return null and make no changes.
*
* Otherwise, this will return the relationship record for this person.
*
* If either THIS or $objWithPerson has not yet been saved, this will throw a QCallerException
*
* @param Person $objWithPerson
* @param integer $intRelationshipTypeId
* @return Relationship
*/
public function AddRelationship(Person $objWithPerson, $intRelationshipTypeId)
{
if (!$objWithPerson->Id) {
throw new QCallerException('Attempting to add relationship with an unsaved Person record');
}
if (!$this->intId) {
throw new QCallerException('Attempting to add relationship for an unsaved Person record');
}
// Ensure no relationship already exists
if (Relationship::LoadByPersonIdRelatedToPersonId($this->intId, $objWithPerson->Id)) {
return null;
}
if (Relationship::LoadByPersonIdRelatedToPersonId($objWithPerson->Id, $this->intId)) {
return null;
}
// Figure out the "Opposite" relationship to create
switch ($intRelationshipTypeId) {
case RelationshipType::Child:
$intOppositeRelationship = RelationshipType::Parental;
break;
case RelationshipType::Parental:
$intOppositeRelationship = RelationshipType::Child;
break;
case RelationshipType::Sibling:
$intOppositeRelationship = RelationshipType::Sibling;
break;
case RelationshipType::Grandchild:
$intOppositeRelationship = RelationshipType::Grandparent;
break;
case RelationshipType::Grandparent:
$intOppositeRelationship = RelationshipType::Grandchild;
break;
default:
throw new Exception('Invalid Relationship Type Id: ' . $intRelationshipTypeId);
}
// Create the relationship
$objRelationship = new Relationship();
$objRelationship->Person = $this;
$objRelationship->RelatedToPerson = $objWithPerson;
$objRelationship->RelationshipTypeId = $intRelationshipTypeId;
$objRelationship->Save();
// Create the other end of the relationship
$objOtherRelationship = new Relationship();
$objOtherRelationship->Person = $objWithPerson;
$objOtherRelationship->RelatedToPerson = $this;
$objOtherRelationship->RelationshipTypeId = $intOppositeRelationship;
$objOtherRelationship->Save();
// Return
return $objRelationship;
}