瀏覽代碼

Backend Application getters

First simple version with dummy data.
Ecconia 7 年之前
父節點
當前提交
e4a77bd9d0
共有 5 個文件被更改,包括 248 次插入0 次删除
  1. 70 0
      src/Application/AppPattern.php
  2. 51 0
      src/Application/Application.php
  3. 103 0
      src/DummyData.php
  4. 13 0
      src/Handler/MyHandler.php
  5. 11 0
      src/User.php

+ 70 - 0
src/Application/AppPattern.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace RS\Application;
+
+class AppPattern {
+	public $instruction;
+	public $fields;
+
+	function __construct() {
+		$this->instruction = 'First impressions are important. Please tell us about yourself. A well-written application is likely to speed up your approval on the server, while a poorly written one might not get approved at all. 2-3 well-written sentences per question is recommended.';
+		
+		$this->fields = json_decode('[
+				{
+					"text": "Country?",
+					"hint": "Where are you from? Just the continent is fine. Please leave blank if you don\"t want to tell us!",
+					"type": "line",
+					"optional": true
+				},
+				{
+					"text": "Age?",
+					"hint": "How old are you? Please leave blank if you don\'t want to tell us!",
+					"type": "age",
+					"optional": true
+				},
+				{
+					"text": "About how often do you play Minecraft?",
+					"optional": true,
+					"type": "hours-per"
+				},
+				{
+					"text": "Why are you interested in joining this server?",
+					"hint": "Why would you like to join this server? What can you offer to others on the server? What can this server offer you that other servers can not? Please describe in detail.",
+					"optional": false,
+					"type": "text-box-limited"
+				},
+				{
+					"text": "Current Redstone knowledge",
+					"hint": "What are your current limits in redstone? Tell us anything you know concerning redstone.",
+					"optional": false,
+					"type": "text-box-limited"
+				},
+				{
+					"text": "Past Redstone Experience",
+					"hint": "Describe your best Redstone creation(s) to date. Tell us how they work and what kind of Redstone logic was used.",
+					"optional": false,
+					"type": "text-box-limited"
+				},
+				{
+					"text": "What kind of creations would you like to build on this server?",
+					"hint": "Describe what sort of creations you will try to be building on this server.",
+					"optional": false,
+					"type": "text-box"
+				},
+				{
+					"text": "Links to your work:",
+					"hint": "Include screenshots/videos of your previous work. These links will not be released to anyone but the application appraisers.",
+					"optional": true,
+					"hidden": true,
+					"type": "links"
+				},
+				{
+					"text": "Anything else you\'d like to mention",
+					"hint": "Have any opinions? Any extra information?",
+					"optional": true,
+					"type": "text-box"
+				}
+			]'
+		, true);
+	}
+}

+ 51 - 0
src/Application/Application.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace RS\Application;
+
+use RS\Application\AppPattern;
+use RS\User;
+
+class Application {
+	public $user;
+	public $pattern;
+	public $answers;
+	public $state;
+	public $time;
+
+	function __construct(User $user, AppPattern $pattern, int $time, Array $answers, $state) {
+		$this->user = $user;
+		$this->pattern = $pattern;
+		$this->answers = $answers;
+		$this->time = $time;
+		$this->state = $state;
+	}
+
+	public function fullCompile() {
+		$application['username'] = $this->user->username;
+
+		for($i = 0; $i < sizeof($this->answers); $i++) {
+			$fields[$this->pattern->fields[$i]['text']] = $this->answers[$i];
+		}
+		$application['fields'] = $fields;
+
+		$application['time'] = $this->time;
+
+		if($this->state >= 0) {
+			$application['state'] = $this->state > 0 ? true : false;
+		}
+
+		return $application;
+	}
+
+	public function viewCompile() {
+		$application['username'] = $this->user->username;
+
+		$application['time'] = $this->time;
+
+		if(isset($this->state)) {
+			$application['state'] = $this->state > 0 ? true : false;
+		}
+
+		return $application;
+	}
+}

+ 103 - 0
src/DummyData.php

@@ -0,0 +1,103 @@
+<?php
+
+namespace RS;
+
+use RS\Application\AppPattern;
+use RS\Application\Application;
+use RS\User;
+
+class DummyData {
+	public static function dummyBase() {
+		$devPattern = new AppPattern();
+
+		$applications[] = new Application(new User('Joke'), $devPattern, 1439202084, [
+			'LalaLand', # Country
+			'69', # Age
+			'Play always', # Addiction
+			'Cause banned on all de other crap servers', # Why joining this server?
+			'I am betta den all you, i swear!', # Your current rs knowledge?
+			'm3m3g3n3r4t0r gud redstoned', # Stuff you built in the past?
+			'Betta shiet', # What you gonna build?
+			'admin@p', # Links?
+			'U all smoke ganja!', # Wanna mention something?
+		], false);
+
+		$applications[] = new Application(new User('Josh (KingTempest07)'), $devPattern, 1528202084, [
+			'', # Country
+			'11', # Age
+			'1-5 hours per day', # Addiction
+			'I love redstone, and I am not the best, at all, but I am trying to learn, so I thought maybe a server with some good redstone engineers could help! Also, I have no online friends, really, just real life, so I have been looking for servers on many different games, like: Terraria, Minecraft, etc.', # Why joining this server?
+			'Let\'s just say, I\'m terrible. I watch tons of Mumbo Jumbo, which is both entertaining and helpful, but I am still better at building than redstone. I know how to do things like: minecart systems, pulse extenders, double piston extenders, monostable circuits, some piston doors, do slab/redstone torch elevators, etc., but I can\'t really find was to compact or combine them easily!', # Your current rs knowledge?
+			'I have made 2x2 piston doors with pressure plates on both sides, and only used around a 8x3 block area with redstone torch elevators, and I can also make some simple things, like item transport systems with water and ice, hoppers, and I\'m not that good with storage systems, but I\'m getting there!', # Stuff you built in the past?
+			'Maybe some mob farms, storage systems, and minigames, but not so soon for minigames, but I might get there!', # What you gonna build?
+			'', # Links?
+			'', # Wanna mention something else?
+		], true);
+
+		$applications[] = new Application(new User('Jack'), $devPattern, 1529202084, [
+			'', # Country
+			'', # Age
+			'', # Addiction
+			'', # Why joining this server?
+			'', # Your current rs knowledge?
+			'', # Stuff you built in the past?
+			'', # What you gonna build?
+			'', # Links?
+			'', # Wanna mention something?
+		], false);
+
+		$applications[] = new Application(new User('John'), $devPattern, 1539102084, [
+			'', # Country
+			'', # Age
+			'', # Addiction
+			'', # Why joining this server?
+			'', # Your current rs knowledge?
+			'', # Stuff you built in the past?
+			'', # What you gonna build?
+			'', # Links?
+			'', # Wanna mention something?
+		], false);
+
+		$applications[] = new Application(new User('Jeff'), $devPattern, 1539202084, [
+			'', # Country
+			'', # Age
+			'', # Addiction
+			'', # Why joining this server?
+			'', # Your current rs knowledge?
+			'', # Stuff you built in the past?
+			'', # What you gonna build?
+			'', # Links?
+			'', # Wanna mention something?
+		], null);
+
+		return $applications;
+	}
+
+	public static function getDummyData() {
+		$applications = self::dummyBase();
+
+		//Add dummy ID's
+		for($i = 0; $i < sizeof($applications); $i++) {
+			$app = $applications[$i]->fullCompile();
+			$app['id'] = $i;
+
+			$compiledApps[] = $app;
+		}
+
+		return $compiledApps;
+	}
+
+	public static function getViewDummies() {
+		$applications = self::dummyBase();
+
+		//Add dummy ID's
+		for($i = 0; $i < sizeof($applications); $i++) {
+			$app = $applications[$i]->viewCompile();
+			$app['id'] = $i;
+
+			$compiledApps[] = $app;
+		}
+
+		return $compiledApps;
+	}
+}

+ 13 - 0
src/Handler/MyHandler.php

@@ -11,6 +11,8 @@
 		ResponseInterface
 	};
 
+	use RS\DummyData;
+
 	class MyHandler extends Handler {
 		public function soos(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
 			$lel[] = 'A';
@@ -100,11 +102,22 @@
 			return $response->withJson($entries);
 		}
 
+		public function applications(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+			$applications = [];
+			return $response->withJson(DummyData::getViewDummies());
+		}
+
+		public function dummies(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+			return $response->withJson(DummyData::getDummyData());
+		}
+
 		public static function getRoutes(): array {
 			return [
 				new Route('GET', '/soos', 'soos'),
 				new Route('GET', '/error', 'error'),
 				new Route('GET', '/devblog', 'devblog'),
+				new Route('GET', '/applications', 'applications'),
+				new Route('GET', '/dummies', 'dummies'),
 			];
 		}
 	}

+ 11 - 0
src/User.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace RS;
+
+class User {
+	public $username;
+
+	function __construct(string $username) {
+		$this->username = $username;
+	}
+}