コード例 #1
0
ファイル: ResourceVersion.php プロジェクト: sgrove/cothinker
 /**
  * Populates version properties and creates necessary entries in the resource_attribute_version table.
  * 
  * @param      BaseObject    $resource
  * @param      Array         $withObjects      Optional list of object classes to create and attach to the current resource
  */
 public function populateFromObject(BaseObject $resource, $withObjects = array(), $withVersion = true)
 {
     $this->setResourceId($resource->getPrimaryKey());
     $this->setResourceName(get_class($resource));
     if ($withVersion) {
         $this->setNumber($resource->getVersion());
     }
     foreach ($resource->getPeer()->getFieldNames() as $attribute_name) {
         $getter = sprintf('get%s', $attribute_name);
         $attribute_version = new ResourceAttributeVersion();
         $attribute_version->setAttributeName($attribute_name);
         $attribute_version->setAttributeValue($resource->{$getter}());
         $this->addResourceAttributeVersion($attribute_version);
     }
     foreach ($withObjects as $resourceName) {
         $getter = sprintf('get%s', $resourceName);
         $relatedResources = $resource->{$getter}();
         if (!is_array($relatedResources)) {
             $relatedResources = array($relatedResources);
         }
         foreach ($relatedResources as $relatedResource) {
             $resourceVersion = new ResourceVersion();
             $resourceVersion->populateFromObject($relatedResource, array(), false);
             $this->addResourceVersionRelatedByResourceVersionId($resourceVersion);
         }
     }
 }
コード例 #2
0
 public function addResourceVersionRelatedByResourceVersionId(ResourceVersion $l)
 {
     $this->collResourceVersionsRelatedByResourceVersionId[] = $l;
     $l->setResourceVersionRelatedByResourceVersionId($this);
 }
コード例 #3
0
 /**
  * Creates a new ResourceVersion record based on the object
  *
  * @param      BaseObject    $resource
  * @param      string   Optional name of the revision author
  * @param      string   Optional comment about the revision
  */
 public static function createResourceVersion(BaseObject $resource, $createdBy = '', $comment = '')
 {
     $resourceVersion = new ResourceVersion();
     $resourceVersion->setNumber($resource->getVersion());
     if ($titleGetter = self::forgeMethodName($resource, 'get', 'title')) {
         $resourceVersion->setTitle($resource->{$titleGetter}());
     }
     $resourceVersion->setCreatedBy($createdBy);
     $resourceVersion->setComment($comment);
     return $resourceVersion;
 }