Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getArticles($firstPostDisplay, $nbPages)
- {
- $req = $this->dbb->prepare('
- SELECT
- article.id as article_id,
- article.title as article_title,
- article.author as article_author,
- article.abstract,
- article.content,
- article.date_added,
- article.date_modification,
- article.user_id,
- picture.id as picture_id;
- picture.name as picture_name,
- picture.image_size as picture_imageSize,
- picture.image_type as picture_imageType,
- picture.article_id as picture_articleId
- FROM article
- INNER JOIN picture ON (article.id = picture.article_id)
- WHERE picture.name LIKE :search
- ORDER BY article.id DESC LIMIT :firstPostDisplay, :nbPages
- ');
- $req->bindValue(':firstPostDisplay', $firstPostDisplay, \PDO::PARAM_INT);
- $req->bindValue(':nbPages', $nbPages, \PDO::PARAM_INT);
- $req->bindValue(':search', '%_mini%', \PDO::PARAM_STR);
- $req->execute();
- $req->setFetchMode(\PDO::FETCH_ASSOC);
- $data = $req->fetchAll();
- $articles = [];
- $pictures = [];
- foreach ($data as $value) {
- $article = new Article();
- $picture = new Picture();
- $article->hydrate(
- array_filter($value, function($key) {
- return preg_match('/^article_/', $key);
- }, ARRAY_FILTER_USE_KEY);
- );
- $picture->hydrate(
- array_filter($value, function($key) {
- return preg_match('/^picture_/', $key);
- }, ARRAY_FILTER_USE_KEY);
- );
- $articles[] = $article;
- $pictures[] = $picture;
- }
- return array($articles, $pictures);
- }
Add Comment
Please, Sign In to add comment