public function getCollection() { if ($this->_keyword) { if ($this->_filter == 'mangatitle') { $searchQuery = "AND {$this->_table}.mangatitle LIKE '{$this->_keyword}' OR `othertitle` LIKE '{$this->_keyword}'"; } else { $searchQuery = "AND {$this->_table}.{$this->_filter} LIKE '{$this->_keyword}'"; } } if ($this->_limit) { $totalManga = $this->getTotal(); $totalPage = ceil($totalManga / $this->_limit); if ($this->_page > $totalPage) { $this->_page = $totalPage; } $limitQuery = "LIMIT " . $this->_limit * ($this->_page - 1) . ",{$this->_limit}"; } $chapterObject = new Chapter(); $chapterTable = $chapterObject->getTable(); $query = "SELECT {$this->_table}.*, IFNULL(chapter.count_chapter, 0) AS `finishedchapter` FROM `{$this->_table}` LEFT JOIN\n (\n SELECT COUNT(*) AS count_chapter, mangaid\n FROM {$chapterTable}\n WHERE `active` = '1'\n AND `type` = '1'\n GROUP BY mangaid\n ) chapter\n ON {$this->_table}.mangaid = chapter.mangaid\n WHERE {$this->_table}.`active` = '1'\n {$searchQuery}\n {$limitQuery}"; $mangaDatas = $this->_db->fetchAll($query); if (!empty($mangaDatas)) { $mangaCollection = array(); foreach ($mangaDatas as $mangaData) { $this->setData($mangaData); $mangaCollection[] = clone $this; } return $mangaCollection; } else { return NULL; } }