示例#1
0
 private function handleEntityRelations()
 {
     $subjectguid = $this->swappliance->guid;
     $reltype = EntityRelations::getRelationType("swappliance", "usage", "vappliance");
     if ($reltype === null) {
         throw new Exception("No relation type for sofwtare appliance and virtual appliance");
     }
     $vappguids = $this->getRelatedSWApplianceGuids();
     $result = EntityRelations::unrelateAll($subjectguid, array(), false, array($reltype->id));
     if ($result !== true) {
         throw new Exception($result);
     }
     if (count($vappguids) > 0) {
         $userid = null;
         if ($this->user && is_numeric($this->user->id) && $this->user->id > 0) {
             $userid = $this->user->id;
         }
         foreach ($vappguids as $vg) {
             $result = EntityRelations::relate($reltype->id, $subjectguid, $vg, $userid);
             if (is_string($result)) {
                 throw new Exception($result);
             }
         }
     }
     return true;
 }
示例#2
0
 private static function saveRecord($data, $imports = array())
 {
     $userid = null;
     if (isset($data["userid"]) && is_numeric($data["userid"])) {
         $userid = $data["userid"];
     }
     try {
         $proj = new Default_Model_Project();
         $proj->identifier = $data["appdb_identifier"];
         $proj->extIdentifier = $data["external_identifier"];
         $proj->code = $data["code"];
         $proj->acronym = $data["acronym"];
         $proj->title = $data["title"];
         $proj->startdate = $data["startdate"];
         $proj->enddate = $data["enddate"];
         $proj->callidentifier = $data["callidentifier"];
         $proj->keywords = $data["keywords"];
         $proj->duration = $data["duration"];
         $proj->websiteurl = $data["websiteurl"];
         $proj->addedbyID = $userid;
         $proj->sourceid = 2;
         //OpenAire source
         $proj->save();
     } catch (Exception $ex) {
         return $ex->getMessage();
     }
     try {
         $proj = self::isRecordImported($proj->identifier);
         if ($proj === null) {
             return null;
         }
         if ($data["contracttype"] !== null) {
             $ct = self::importContractType($data["contracttype"]);
             $proj->contracttypeid = $ct->id;
             $proj->save();
         }
         if ($data["funding"] !== null && count($data["funding"]) > 0) {
             $funds = $data["funding"];
             $pid = null;
             for ($i = 0; $i < count($funds); $i += 1) {
                 $f = self::importFunding($funds[$i], $pid);
                 $pid = $f->id;
             }
             if ($pid !== null) {
                 $proj->fundingid = $pid;
             }
         }
         if (in_array("organization", $imports) === true && $data["organizations"] !== null && count($data["organizations"]) > 0) {
             $orgs = $data["organizations"];
             for ($i = 0; $i < count($orgs); $i += 1) {
                 $org = $orgs[$i];
                 $reltype = EntityRelations::getRelationType("organization", $org["type"], "project");
                 if ($reltype !== null) {
                     $org["reltypeid"] = $reltype->id;
                 } else {
                     $org["reltypeid"] = null;
                 }
                 $orgs[$i] = $org;
             }
             for ($i = 0; $i < count($orgs); $i += 1) {
                 $org = $orgs[$i];
                 if (isset($org["reltypeid"]) && $org["reltypeid"] !== null) {
                     $o = self::importOrganization($org);
                     if ($o !== null && is_string($o) === false) {
                         EntityRelations::relate($org["reltypeid"], $o->guid, $proj->guid, $userid);
                     }
                 }
             }
         }
     } catch (Exception $ex) {
         return $ex->getMessage();
     }
     return $proj;
 }