public function save(Default_Model_DatasetLocation $value) { global $application; $data = array(); if (!isnull($value->getId())) { $data['id'] = $value->getId(); } if (!isnull($value->getAddedByID())) { $data['addedby'] = $value->getAddedByID(); } if (!isnull($value->getAddedon())) { $data['addedon'] = $value->getAddedon(); } if (!isnull($value->getUri())) { $data['uri'] = $value->getUri(); } if (!isnull($value->getIsMaster())) { $data['is_master'] = $this->pgBool($value->getIsMaster()); } if (!isnull($value->getExchangeFormatID())) { $data['exchange_fmt'] = $value->getExchangeFormatID(); } if (!isnull($value->getConnectionTypeID())) { $data['connection_type'] = $value->getConnectionTypeID(); } if (!isnull($value->getIsPublic())) { $data['is_public'] = $this->pgBool($value->getIsPublic()); } if (!isnull($value->getOrganizationID())) { $data['organizationid'] = $value->getOrganizationID(); } if (!isnull($value->getSiteID())) { $data['siteid'] = $value->getSiteID(); } if (!isnull($value->getNotes())) { $data['notes'] = $value->getNotes(); } if (!isnull($value->getDatasetVersionId())) { $data['dataset_version_id'] = $value->getDatasetVersionId(); } $q1 = 'id = ?'; $q2 = $value->id; if (null === ($id = $value->id)) { unset($data['id']); $value->id = $this->getDbTable()->insert($data); } else { $s = $this->getDbTable()->getAdapter()->quoteInto($q1, $q2); $this->getDbTable()->update($data, $s); } }
/** * implementation of abstract parse() operation from RestXMLParser. * @xml SimpleXMLElement the root element of the dataset XML representation * * @return Default_Model_Dataset * @access public */ public function parse($xml) { global $application; if (!is_null($this->_user)) { $ds = new Default_Model_DatasetLocation(); try { $xml = new SimpleXMLElement($xml); } catch (Exception $e) { error_log($xml); $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION; return $ds; } $this->_xml = $xml; // basic properties $xmli = $xml->xpath('//dataset:location'); if (count($xmli) === 0) { $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION; return $ds; } $xml = $xmli[0]; if ($this->_parent->getMethod() === RestMethodEnum::RM_PUT && (is_null($this->el($xml, "dataset:uri")) || strval($xml->attributes()->datasetversionid) == "" && $this->_parent->getParam("vid") == "" || count($xml->xpath("//dataset:exchange_format")) == 0 || count($xml->xpath("//dataset:interface")) == 0)) { $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION; $this->_extError = "One ore more required entities or attributes are missing or contain no data."; return $ds; } if ($this->_parent->getMethod() === RestMethodEnum::RM_PUT) { if ($this->_parent->getParam("vid") == "") { $ds->datasetVersionID = strval($xml->attributes()->datasetversionid); } else { $ds->datasetVersionID = $this->_parent->getParam("vid"); } $ds->addedByID = $this->_parent->getUser()->id; } elseif ($this->_parent->getMethod() === RestMethodEnum::RM_POST) { if ($xml->attributes()->id) { $ds->id = strval($xml->attributes()->id); } else { $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION; return $ds; } } if (!is_null($this->el($xml, "dataset:uri"))) { $ds->uri = strval($this->el($xml, "dataset:uri")); } if (!is_null($this->el($xml, "dataset:notes"))) { $ds->notes = strval($this->el($xml, "dataset:notes")); } if (!is_null($this->el($xml, "dataset:interface"))) { $ds->connectionTypeID = strval($this->el($xml, "dataset:interface")->attributes()->id); if ($ds->connectionTypeID == "") { $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION; return $ds; } } if (!is_null($this->el($xml, "dataset:exchange_format"))) { $ds->exchangeFormatID = strval($this->el($xml, "dataset:exchange_format")->attributes()->id); if ($ds->exchangeFormatID == "") { $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION; return $ds; } } $ds->save(); if (count($xml->xpath('//dataset:organization[@xsi:nil="true"]')) > 0) { //$ds->organizationID = "0"; // N.B.: mapper overriden to nullify "0" values if ($ds->id != "") { db()->exec("DELETE FROM dataset_location_organizations WHERE dataset_location_id = " . $ds->id); } } else { if (!is_null($this->el($xml, "dataset:organization"))) { if ($ds->id != "") { db()->exec("DELETE FROM dataset_location_organizations WHERE dataset_location_id = " . $ds->id); } //$xorg = $this->el($xml,"dataset:organization"); foreach ($xml->xpath("//dataset:organization") as $xorg) { $orgitem = null; $orgid = strval($xorg->attributes()->id); if (is_string($orgid) && trim($orgid) !== '') { $orgitem = HarvestOrganizations::getImportedOrganization($orgid); } if ($orgitem === null) { $orgitem = HarvestOrganizations::import($orgid); } if ($orgitem) { $orgid = $orgitem->id; } else { $orgid = ""; } $dss = new Default_Model_DatasetLocationOrganization(); $dss->organizationID = $orgid; //strval($xorg->attributes()->id); if ($dss->organizationID == "") { $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION; return $ds; } $dss->datasetLocationID = $ds->id; $dss->save(); } } } if (count($xml->xpath('//appdb:site[@xsi:nil="true"]')) > 0) { //$ds->siteID = "0"; // N.B.: mapper overriden to nullify "0" values if ($ds->id != "") { db()->exec("DELETE FROM dataset_location_sites WHERE dataset_location_id = " . $ds->id); } } elseif (!is_null($this->el($xml, "appdb:site"))) { //$xsite = $this->el($xml,"appdb:site"); if ($ds->id != "") { db()->exec("DELETE FROM dataset_location_sites WHERE dataset_location_id = " . $ds->id); } foreach ($xml->xpath("//appdb:site") as $xsite) { $dss = new Default_Model_DatasetLocationSite(); $dss->siteID = strval($xsite->attributes()->id); if ($dss->siteID == "") { $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION; return $ds; } $dss->datasetLocationID = $ds->id; $dss->save(); } } if (isset($xml->attributes()->master)) { $ds->isMaster = filter_var($xml->attributes()->master, FILTER_VALIDATE_BOOLEAN); } if (isset($xml->attributes()->public)) { $ds->isPublic = filter_var($xml->attributes()->public, FILTER_VALIDATE_BOOLEAN); } $ds->save(); } return $ds; }