Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Student Model for Education Sample App (#6)
- Loading branch information
1 parent
5464c5a
commit 0fa2d4f
Showing
5 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
# Buildfest 2022 PHP Project | ||
|
||
|
||
|
||
## How to run the app locally | ||
|
||
1. Build the container: `docker build -t school_app .` | ||
2. Run the app: `docker run -v $(pwd)/src:/school_app/src -p8080:80 -e MONGODB_URI='mongodb+srv://your_atlas_cluster/' -e DATABASE='school_app' school_app` | ||
2. Run the app: `docker run -v $(pwd)/src:/school_app/src -p 8080:80 -e MONGODB_URI='mongodb+srv://your_atlas_cluster/' -e DATABASE='school_app' school_app` | ||
3. Open [http://localhost:8080](http://localhost:8080). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
<?php namespace SchoolApp\Controller; | ||
|
||
use \SchoolApp\Model\Student as Student; | ||
use \MongoDB\BSON\ObjectId as ObjectId; | ||
|
||
class Students { | ||
static function index() { | ||
$students = \SchoolApp\Repository\Students::getAll(); | ||
\SchoolApp\View\Students::index($students); | ||
} | ||
static function create(Student $student) { | ||
\SchoolApp\Repository\Students::insertOne($student); | ||
return "successful insert!"; | ||
} | ||
static function show(string $student) { | ||
$objectId = new ObjectId($student); | ||
$found_student = \SchoolApp\Repository\Students::findOne($objectId); | ||
\SchoolApp\View\Students::index([$found_student]); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php namespace SchoolApp\Model; | ||
|
||
class Student { | ||
|
||
public function __construct(string $name, array $courses ){ | ||
$this->name = $name; | ||
$this->courses = $courses; | ||
} | ||
|
||
public static function makeWithPost(array $post) { | ||
return new self($post['name'], $post['courses']); | ||
} | ||
|
||
function get(): array { | ||
return [ | ||
'name' => $this->name, | ||
'courses' => $this->courses, | ||
]; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
<?php namespace SchoolApp\Repository; | ||
|
||
use \SchoolApp\Model\Student as Student; | ||
use \MongoDB\BSON\ObjectId as ObjectId; | ||
|
||
|
||
class Students { | ||
static function getAll() { | ||
return \SchoolApp\Repository\Database::getInstance()->students->find(); | ||
} | ||
|
||
static function insertOne(Student $student) { | ||
return \SchoolApp\Repository\Database::getInstance()->students->insertOne($student->get()); | ||
} | ||
|
||
static function findOne(ObjectId $id) { | ||
return \SchoolApp\Repository\Database::getInstance()->students->findOne(['_id' => $id]); | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters