public function insert(Default_Model_Project $project) { $data = array('name' => $project->getName(), 'private' => $project->isPrivate() ? 1 : 0); $db = $this->getWriteAdapter(); $db->insert($this->getTableName(), $data); return $db->lastInsertId(); }
public function createFromForm(Default_Form_Project_Create $form) { $acl = Zend_Registry::get('Default_DiContainer')->getAclService(); if (!$acl->isAllowed('project', 'create')) { return false; } $permissions = $form->getValue('permissions'); $project = new Default_Model_Project(); $project->setName($form->getValue('project_name'))->setPrivate($permissions['private'] ? true : false); $return = $this->_mapper->insert($project); if ($permissions['private']) { Zend_Registry::get('Default_DiContainer')->getAclService()->addResourceRecord($permissions['roles'], 'project', $return); } return $return; }
public function save(Default_Model_Project $value) { global $application; $data = array(); if (!isnull($value->getId())) { $data['id'] = $value->getId(); } if (!isnull($value->getCode())) { $data['code'] = $value->getCode(); } if (!isnull($value->getAcronym())) { $data['acronym'] = $value->getAcronym(); } if (!isnull($value->getTitle())) { $data['title'] = $value->getTitle(); } if (!isnull($value->getStartDate())) { $data['startdate'] = $value->getStartDate(); } if (!isnull($value->getEndDate())) { $data['enddate'] = $value->getEndDate(); } if (!isnull($value->getCallIdentifier())) { $data['callidentifier'] = $value->getCallIdentifier(); } if (!isnull($value->getWebsiteURL())) { $data['websiteurl'] = $value->getWebsiteURL(); } if (!isnull($value->getKeywords())) { $data['keywords'] = $value->getKeywords(); } if (!isnull($value->getDuration())) { $data['duration'] = $value->getDuration(); } if (!isnull($value->getContractTypeID())) { $data['contracttypeid'] = $value->getContractTypeID(); } if (!isnull($value->getFundingID())) { $data['fundingid'] = $value->getFundingID(); } if (!isnull($value->getAddedOn())) { $data['addedon'] = $value->getAddedOn(); } if (!isnull($value->getAddedByID())) { $data['addedby'] = $value->getAddedByID(); } if (!isnull($value->getGuid())) { $data['guid'] = $value->getGuid(); } if (!isnull($value->getIdentifier())) { $data['identifier'] = $value->getIdentifier(); } if (!isnull($value->getSourceID())) { $data['sourceid'] = $value->getSourceID(); } if (!isnull($value->getDeletedon())) { $data['deletedon'] = $value->getDeletedon(); } if (!isnull($value->getDeletedby())) { $data['deletedby'] = $value->getDeletedby(); } if (!isnull($value->getExtIdentifier())) { $data['ext_identifier'] = $value->getExtIdentifier(); } if (!isnull($value->getModerated())) { $data['moderated'] = $this->pgBool($value->getModerated()); } if (!isnull($value->getDeleted())) { $data['deleted'] = $this->pgBool($value->getDeleted()); } $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); } }
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; }