From 927b08ed00b72b41c5e6bef7aad66ea897206c57 Mon Sep 17 00:00:00 2001 From: sal0max Date: Thu, 14 Oct 2021 22:52:42 +0200 Subject: [PATCH] [LegoIdeasBridge] Add bridge (#2284) * [LegoIdeasBridge] Add bridge --- bridges/LegoIdeasBridge.php | 102 ++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 bridges/LegoIdeasBridge.php diff --git a/bridges/LegoIdeasBridge.php b/bridges/LegoIdeasBridge.php new file mode 100644 index 00000000..442aba64 --- /dev/null +++ b/bridges/LegoIdeasBridge.php @@ -0,0 +1,102 @@ + array( + 'name' => 'Minimum Supporters', + 'title' => 'The number of people that need to have supported a project at minimum. +Once a project reaches 10,000 supporters, it gets reviewed by the lego experts.', + 'type' => 'number', + 'defaultValue' => 1000 + ), + 'idea_phase' => array( + 'name' => 'Idea Phase', + 'type' => 'list', + 'values' => array( + 'Gathering Support' => 'idea_gathering_support', + 'Achieved Support' => 'idea_achieved_support', + 'In Review' => 'idea_in_review', + 'Approved Ideas' => 'idea_idea_approved', + 'Not Approved Ideas' => 'idea_idea_not_approved', + 'On Shelves' => 'idea_on_shelves', + 'Expired Ideas' => 'idea_expired_ideas', + ), + 'defaultValue' => 'idea_gathering_support' + ) + ) + ); + + public function getURI() { + // link to the corresponding page on the website, not the api endpoint + return self::URI . 'search/global_search/ideas' + . "?support_value={$this->getInput('support_value_min')}" + . '&support_value=10000' + . "&idea_phase={$this->getInput('idea_phase')}" + . '&sort=most_recent'; + } + + public function collectData() { + $header = array( + 'Content-Type: application/json', + 'Accept: application/json' + ); + $opts = array( + CURLOPT_POST => 1, + CURLOPT_POSTFIELDS => $this->getHttpPostData() + ); + $responseData = getContents($this->getHttpPostURI(), $header, $opts) or + returnServerError('Unable to query Lego Ideas API.'); + + foreach (json_decode($responseData)->results as $project) { + preg_match('/datetime=\"(\S+)\"/', $project->entity->published_at, $date_matches); + $datetime = $date_matches[1]; + $link = self::URI . $project->entity->view_url; + $title = $project->entity->title; + $desc = $project->entity->content; + $imageUrl = $project->entity->image_url; + $creator = $project->entity->creator->alias; + $uuid = $project->entity->uuid; + + $item = array( + 'uri' => $link, + 'title' => $title, + 'timestamp' => strtotime($datetime), + 'author' => $creator, + 'content' => <<{$title}

+

{$desc}

+EOD + ); + $this->items[] = $item; + } + } + + /** + * Returns the API endpoint + */ + private function getHttpPostURI() { + return self::URI . '/search/global_search/ideas'; + } + + /** + * Returns the API query + */ + private function getHttpPostData() { + + $phase = $this->getInput('idea_phase'); + $minSupporters = $this->getInput('support_value_min'); + + return <<