/** * Creates part of a query for searches requiring the categoryID's. * * @param array $categories * * @return string */ public function categorySQL($categories) { $sql = ''; if (count($categories) > 0 && $categories[0] != -1) { $Category = new Category(['Settings' => $this->pdo]); $sql = ' AND ('; foreach ($categories as $category) { if ($category != -1) { if ($Category->isParent($category)) { $children = $Category->getChildren($category); $childList = '-99'; foreach ($children as $child) { $childList .= ', ' . $child['id']; } if ($childList != '-99') { $sql .= ' r.categoryid IN (' . $childList . ') OR '; } } else { $sql .= sprintf(' r.categoryid = %d OR ', $category); } } } $sql .= '1=2 )'; } return $sql; }