project_id < 1 ? -1 : $this->project_id; } public function getName(): string { return $this->project_name; } public function getCleanName(): string { return $this->project_name_clean ?? str_replace(' ', '-', trim(strtolower($this->getName()))); } public function getSummary(): string { return $this->project_summary ?? ''; } public function getDescription(): string { return $this->project_description ?? ''; } public function getDescriptionLines(): array { $linesRaw = array_reverse(explode("\n", $this->getDescription())); $lines = []; while(($line = array_pop($linesRaw)) !== false) { $line = trim($line); if(!empty($line)) $lines[] = $line; } return $lines; } public function getOrder(): int { return $this->project_order; } public function getType(): string { return $this->project_type; } public function isProject(): bool { return $this->getType() === self::TYPE_PROJECT; } public function isTool(): bool { return $this->getType() === self::TYPE_TOOL; } public function isFeatured(): bool { return boolval($this->project_featured); } // TODO: INHERIT LANGUAGE COLOUR public function hasColour(): bool { return $this->project_colour !== null; } public function getColour(): FmColour { return new FmColour($this->project_colour); } public function hasHomepage(): bool { return !empty($this->project_homepage); } public function getHomepage(): string { return $this->project_homepage ?? ''; } public function hasRepository(): bool { return !empty($this->project_repository); } public function getRepository(): string { return $this->project_repository ?? ''; } public function hasForum(): bool { return !empty($this->project_forum); } public function getForum(): string { return $this->project_forum ?? ''; } public function getCreatedTime(): DateTime { return new DateTime('@' . ($this->project_created ?? 0)); } public function isDeleted(): bool { return $this->project_deleted !== null; } public function getDeletedTime(): DateTime { return new DateTime('@' . ($this->project_deleted ?? 0)); } public function isArchived(): bool { return $this->project_archived !== null; } public function getArchivedTime(): DateTime { return new DateTime('@' . ($this->project_archived ?? 0)); } public function getLinks(): array { $links = []; if($this->hasHomepage()) $links[] = FmProjectLink::create('homepage', 'Homepage', $this->getHomepage()); if($this->hasRepository()) $links[] = FmProjectLink::create('repository', 'Source', $this->getRepository()); if($this->hasForum()) $links[] = FmProjectLink::create('forum', 'Discussion', $this->getForum()); return $links; } public function getLanguages(): array { return $this->languages ?? []; } private function transformLanguages(): void { if(empty($this->languages)) return; foreach($this->languages as &$lang) if($lang instanceof stdClass) $lang = FmLanguage::fromStdClass($lang); } public static function byFeatured(): array { return cache_output('projects-featured-noconvert', 300, function() { $projects = json_decode(file_get_contents('https://flash.moe/2020/projects.php?dump_that_shit&noconvert&rf')); foreach($projects as &$project) { $projRaw = (array)$project; $project = new static; foreach($projRaw as $prop => $val) $project->{$prop} = $val; $project->transformLanguages(); } return $projects; }); } public static function all(): array { return cache_output('projects-noconvert', 300, function() { $projects = json_decode(file_get_contents('https://flash.moe/2020/projects.php?dump_that_shit&noconvert')); foreach($projects as &$project) { $projRaw = (array)$project; $project = new static; foreach($projRaw as $prop => $val) $project->{$prop} = $val; $project->transformLanguages(); } return $projects; }); } }