Guest User

Untitled

a guest
Dec 12th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. public function getArticles($firstPostDisplay, $nbPages)
  2. {
  3. $req = $this->dbb->prepare('
  4. SELECT
  5. article.id as article_id,
  6. article.title as article_title,
  7. article.author as article_author,
  8. article.abstract,
  9. article.content,
  10. article.date_added,
  11. article.date_modification,
  12. article.user_id,
  13. picture.id as picture_id;
  14. picture.name as picture_name,
  15. picture.image_size as picture_imageSize,
  16. picture.image_type as picture_imageType,
  17. picture.article_id as picture_articleId
  18. FROM article
  19. INNER JOIN picture ON (article.id = picture.article_id)
  20. WHERE picture.name LIKE :search
  21. ORDER BY article.id DESC LIMIT :firstPostDisplay, :nbPages
  22. ');
  23. $req->bindValue(':firstPostDisplay', $firstPostDisplay, \PDO::PARAM_INT);
  24. $req->bindValue(':nbPages', $nbPages, \PDO::PARAM_INT);
  25. $req->bindValue(':search', '%_mini%', \PDO::PARAM_STR);
  26. $req->execute();
  27. $req->setFetchMode(\PDO::FETCH_ASSOC);
  28. $data = $req->fetchAll();
  29. $articles = [];
  30. $pictures = [];
  31. foreach ($data as $value) {
  32. $article = new Article();
  33. $picture = new Picture();
  34.  
  35. $article->hydrate(
  36. array_filter($value, function($key) {
  37. return preg_match('/^article_/', $key);
  38. }, ARRAY_FILTER_USE_KEY);
  39. );
  40. $picture->hydrate(
  41. array_filter($value, function($key) {
  42. return preg_match('/^picture_/', $key);
  43. }, ARRAY_FILTER_USE_KEY);
  44. );
  45. $articles[] = $article;
  46. $pictures[] = $picture;
  47. }
  48. return array($articles, $pictures);
  49. }
Add Comment
Please, Sign In to add comment