public static function getPostsForEvent($event_id) { $app = \Slim\Slim::getInstance(); //return all post $allGetVars = $app->request->get(); //default startAt = 0, limit = 15 $startAt = @$allGetVars['startAt'] ? intval($allGetVars['startAt']) : 0; $limit = @$allGetVars['limit'] ? $allGetVars['limit'] : 15; $orderBy = @$allGetVars['orderBy'] ? $allGetVars['orderBy'] : "datetime"; if (!filter_var($event_id, FILTER_VALIDATE_INT) || !filter_var($limit, FILTER_VALIDATE_INT)) { $app->render(400, ['Status' => 'Invalid event id.']); return; } if ($orderBy != "post_id") { $orderBy = "datetime"; } $event = \relive\models\Event::find($event_id); if ($event) { $event->rankPoints = $event->rankPoints + 1; $event->save(); $crawljob = \relive\models\CrawlJob::where('event_id', '=', $event_id)->first(); if ($crawljob) { $crawljob->delay = 10; $crawljob->save(); } $posts = \relive\models\Post::whereIn('post_id', function ($query) use($event_id) { $query->select('post_id')->from('posteventrelationships')->where('event_id', '=', $event_id)->where('isFiltered', False); })->orderBy('datetime', 'desc')->offset($startAt)->limit($limit)->get(); echo json_encode($posts, JSON_UNESCAPED_SLASHES); } else { $app->render(404, ['Status', 'Event not found.']); } }
<?php require_once '/var/www/vendor/autoload.php'; use relive\models\Event; use relive\models\Post; use relive\models\PostEventRelationship; foreach (Event::all() as $event) { $event_id = $event->event_id; $count = PostEventRelationship::where('event_id', '=', $event_id)->count(); if ($count > 500) { $post = Post::whereIn('post_id', function ($query) use($event_id) { $query->select('post_id')->from('posteventrelationships')->where('event_id', '=', $event_id); })->orderBy('rankPoints', 'asc')->offset($count * 0.35)->limit(1)->first(); $rankPoints = $post->rankPoints; PostEventRelationship::whereIn('post_id', function ($query) use($rankPoints) { $query->select('post_id')->from('posts')->where('rankPoints', '<', $rankPoints); })->where('event_id', '=', $event_id)->update(['isFiltered' => 1]); PostEventRelationship::whereIn('post_id', function ($query) use($rankPoints) { $query->select('post_id')->from('posts')->where('rankPoints', '>=', $rankPoints); })->where('event_id', '=', $event_id)->update(['isFiltered' => 0]); } }
require_once '/var/www/vendor/autoload.php'; if (isset($_GET['event_id'])) { $event = \relive\models\SearchIndex::find($_GET['event_id']); } if ($event) { $hashtags = \relive\models\Hashtag::whereIn('hashtag_id', function ($query) use($event) { $query->select('hashtag_id')->from('eventhashtagrelationships')->where('event_id', '=', $event->event_id); })->select('hashtag')->get(); $tags = []; foreach ($hashtags as $hashtag) { array_push($tags, $hashtag->hashtag); } $keyword = join(',', $tags); $posts = \relive\models\Post::whereIn('post_id', function ($query) use($event) { $query->select('post_id')->from('posteventrelationships')->where('event_id', '=', $event->event_id)->where('isFiltered', False); })->orderBy('datetime', 'desc')->offset(0)->limit(15)->get(); } else { header("Location: http://relive.space/"); } ?> <!DOCTYPE html> <html lang="en"> <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb##"> <meta charset="UTF-8"> <title>relive</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <link rel="apple-touch-icon" sizes="57x57" href="//relive.space/apple-touch-icon-57x57.png"> <link rel="apple-touch-icon" sizes="60x60" href="//relive.space/apple-touch-icon-60x60.png">