diff --git a/src/pvv/side/project.php b/src/pvv/side/project.php index 552939e..eab8b6e 100644 --- a/src/pvv/side/project.php +++ b/src/pvv/side/project.php @@ -68,10 +68,16 @@ class Project { return $this->title; } + /** + * @return string[] + */ public function getDescriptionEn(): array { return $this->description_en; } + /** + * @return string[] + */ public function getDescriptionNo(): array { return $this->description_no; } @@ -88,14 +94,23 @@ class Project { return $this->wiki_link; } + /** + * @return string[] + */ public function getProgrammingLanguages(): array { return $this->programming_languages; } + /** + * @return string[] + */ public function getTechnologies(): array { return $this->technologies; } + /** + * @return string[] + */ public function getKeywords(): array { return $this->keywords; } diff --git a/src/pvv/side/projectmanager.php b/src/pvv/side/projectmanager.php index 8e514ab..2b44b1e 100644 --- a/src/pvv/side/projectmanager.php +++ b/src/pvv/side/projectmanager.php @@ -142,4 +142,33 @@ class ProjectManager { return $maintainers; } + + /** + * @return array{name:string,uname:string,link:string,mail:string}|null + */ + public function getProjectOwner(int $id): ?array { + $query = ' + SELECT name, uname, link, mail FROM project + JOIN project__project_maintainer ON project.id = project__project_maintainer.project_id + JOIN project_maintainer ON project__project_maintainer.uname = project_maintainer.uname + WHERE project.id = :id AND project__project_maintainer.owner = TRUE + LIMIT 1 + '; + + $statement = $this->pdo->prepare($query); + $statement->bindParam(':id', $id, \PDO::PARAM_STR); + $statement->execute(); + + $owner = $statement->fetch(); + if (!$owner) { + return null; + } + + return [ + 'name' => $owner['name'], + 'uname' => $owner['uname'], + 'link' => $owner['link'], + 'mail' => $owner['mail'], + ]; + } } diff --git a/www/prosjekt/edit.php b/www/prosjekt/edit.php index 2c114a0..666ac40 100644 --- a/www/prosjekt/edit.php +++ b/www/prosjekt/edit.php @@ -14,38 +14,45 @@ $pdo = new PDO($DB_DSN, $DB_USER, $DB_PASS); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $projectManager = new pvv\side\ProjectManager($pdo); -$new = 0; +$project_is_new = false; if (isset($_GET['new'])) { - $new = $_GET['new']; + $project_is_new = $_GET['new']; } $projectID = 0; if (isset($_GET['id'])) { $projectID = $_GET['id']; -} elseif ($new == 0) { +} elseif (!$project_is_new) { echo "\nID not set"; exit; } $project = new pvv\side\Project( - 0, - 'Nytt Prosjekt', - '', - $attrs['cn'][0], - $attrs['uid'][0], - $attrs['mail'][0], - 1 + id: 0, + title: 'Nytt Prosjekt', + description_en: null, + description_no: null, + gitea_link: null, + issue_board_link: null, + wiki_link: null, + programming_languages: null, + technologies: null, + keywords: null, + license: null, + logo_url: null ); -// if ($new == 0) { -// $project = $projectManager->getByID($projectID); -// $maintainers = $projectManager->getProjectMaintainers($projectID); -// if ($owner['uname'] != $attrs['uid'][0]) { -// header('HTTP/1.0 403 Forbidden'); -// echo 'wrong user'; -// exit; -// } -// } +if (!$project_is_new) { + $project = $projectManager->getByID($projectID); + $maintainers = $projectManager->getProjectMaintainers($projectID); + + if ($owner['uname'] != $attrs['uid'][0]) { + header('HTTP/1.0 403 Forbidden'); + echo 'wrong user'; + exit; + } +} + ?> @@ -87,11 +94,11 @@ $project = new pvv\side\Project(
Gitea-link
Link til prosjektet på Gitea
-Issue board-link
Link til issue board på Gitea
-Wiki-link
Link til wiki-side
@@ -99,15 +106,15 @@ $project = new pvv\side\Project(Programmeringsspråk
Hvilke programmeringsspråk brukes i prosjektet?
-Teknologier
Hvilke teknologier brukes i prosjektet?
-Nøkkelord
Nøkkelord som beskriver prosjektet
-Lisens
Hvilken lisens bruker prosjektet?
@@ -122,8 +129,8 @@ $project = new pvv\side\Project(Organisert av
-+ text(implode("\n", array_slice($project->getDescriptionNo(), 0, 2))); + ?> +
+ getGiteaLink() ?> + getIssueBoardLink() ?> + getLogoURL() ?> + getProgrammingLanguages() ?> + getTechnologies() ?> + getKeywords() ?> + getLicense() ?> + getWikiLink() ?> +Organisert av
+