当前位置: 首页>>代码示例>>PHP>>正文


PHP Relationship::Save方法代码示例

本文整理汇总了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();
 }
开发者ID:alcf,项目名称:chms,代码行数:38,代码来源:Relationship.class.php

示例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;
 }
开发者ID:alcf,项目名称:chms,代码行数:65,代码来源:Person.class.php


注:本文中的Relationship::Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。