public function add($name) { $this->view = null; try { $user = User::find(Session::uid()); if (!$user->getId() || !$user->getIs_admin()) { throw new Exception('Action not allowed.'); } if (!preg_match('/^\\d*[-a-zA-Z][-a-zA-Z0-9]*$/', $name)) { throw new Exception('The name of the project can only contain alphanumeric characters plus dashes and must have 1 alpha character at least'); } try { $project = Project::find($name); } catch (Exception $e) { } if (is_object($project) && $project->getProjectId($name)) { throw new Exception('Project with the same name already exists!'); } $file = new File(); $logo = ''; if (!empty($_POST['logo'])) { $file->findFileById($_POST['logo']); $logo = basename($file->getUrl()); } $project = new Project(); $project->setName($name); $project->setDescription($_POST['description']); $project->setWebsite($_POST['website']); $project->setContactInfo($user->getUsername()); $project->setOwnerId($user->getId()); $project->setActive(true); $project->setInternal(true); $project->setRequireSandbox(true); $project->setLogo($logo); $project->setRepo_type('git'); $project->setRepository($_POST['github_repo_url']); $project->setGithubId($_POST['github_client_id']); $project->setGithubSecret($_POST['github_client_secret']); $project->save(); if ($file->getId()) { $file->setProjectId($project->getProjectId()); $file->save(); } $journal_message = '@' . $user->getNickname() . ' added project *' . $name . '*'; Utils::systemNotification($journal_message); echo json_encode(array('success' => true, 'message' => $journal_message)); } catch (Exception $e) { $error = $e->getMessage(); echo json_encode(array('success' => false, 'message' => $error)); } }
public function executeSaveNew() { $project = new Project(); $culture = $this->getUser()->getCulture(); // TODO: Implement multiple owners / project leads, if necessary $project->setCreatedBy($this->getUser()->getGuardUser()->getId()); $project->setOwnerId($this->getUser()->getGuardUser()->getId()); $project->setDepartmentId($this->getRequestParameter('department_id') ? $this->getRequestParameter('department_id') : null); $project->setTitle($this->getRequestParameter('title')); $project->setDescription($this->getRequestParameter('description')); $project->setNotes($this->getRequestParameter('notes')); $project->setKeywords($this->getRequestParameter('tags_as_text')); if ($this->getRequestParameter('begin')) { list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('begin'), $this->getUser()->getCulture()); $project->setBegin("{$y}-{$m}-{$d}"); } if ($this->getRequestParameter('finish')) { list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('finish'), $this->getUser()->getCulture()); $project->setFinish("{$y}-{$m}-{$d}"); } $this->logMessage('Dates Saved'); $project->setCampusId($this->getRequestParameter('campus')); $project->setPublished($this->getRequestParameter('published', 0)); $project->save(); $this->logMessage('Project Saved'); $project->createDefaultPermissions(); return $this->redirect('project/awaitApproval'); }
public function approve() { if (!$this->getIsApproved()) { $this->setIsApproved(true); $project = new Project(); $project->setCreatedBy($this->getCreatedBy()); $project->setOwnerId($this->getOwnerId()); $project->setDepartmentId($this->getDepartmentId()); $project->setCampusId($this->getCampusId()); $project->setTitle($this->getTitle()); $project->setDescription($this->getDescription()); $project->setNotes($this->getNotes()); $project->setBegin($this->getBegin()); $project->setFinish($this->getFinish()); $project->setMainForm('default'); $project->setPublished(true); $project->setIsApproved(true); $project->save(); } }