Skip to content

Instantly share code, notes, and snippets.

@sleeping-owl
Last active August 29, 2015 14:13
Show Gist options
  • Save sleeping-owl/d8ad3b0ce5cfb098c3d9 to your computer and use it in GitHub Desktop.
Save sleeping-owl/d8ad3b0ce5cfb098c3d9 to your computer and use it in GitHub Desktop.
public function get_reviews($rest_id = 0)
{
if ( ! $rest_id)
{
return;
}
return $this->get('/site/all/main/' . $rest_id . '/opinions/', Apist::filter('.posts_c .post')->each([
'date' => Apist::filter('.post_date')->text()->call(function ($date)
{
return strtotime($date);
}),
'text' => Apist::filter('.post_text')->call(function ($node)
{
$node->filter('span span a')->each(function ($n)
{
$n->parent()->remove();
});
return $node;
})->text(),
'rating' => Apist::filter('.opinion_marks > span > span')->call(function ($node)
{
$votes = [];
$node->each(function ($n) use (&$votes)
{
$votes[] = trim($n->text());
});
$rating = array_sum( $votes ) / count( $votes );
return floor( $rating * 4 ) / 4;
}),
'attachment' => Apist::filter('.post_text img')->each(Apist::current()->attr('src')),
]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment