| @@ 346-377 (lines=32) @@ | ||
| 343 | * |
|
| 344 | * @return array |
|
| 345 | */ |
|
| 346 | public function getAllCategories() |
|
| 347 | { |
|
| 348 | $categories = []; |
|
| 349 | $query = sprintf(' |
|
| 350 | SELECT |
|
| 351 | id, lang, parent_id, name, description, user_id, group_id, active, show_home, image |
|
| 352 | FROM |
|
| 353 | %sfaqcategories', |
|
| 354 | Db::getTablePrefix() |
|
| 355 | ); |
|
| 356 | if (isset($this->language) && preg_match("/^[a-z\-]{2,}$/", $this->language)) { |
|
| 357 | $query .= " WHERE lang = '".$this->language."'"; |
|
| 358 | } |
|
| 359 | $result = $this->config->getDb()->query($query); |
|
| 360 | while ($row = $this->config->getDb()->fetchArray($result)) { |
|
| 361 | $categories[(int)$row['id']] = [ |
|
| 362 | 'id' => (int)$row['id'], |
|
| 363 | 'lang' => $row['lang'], |
|
| 364 | 'parent_id' => (int)$row['parent_id'], |
|
| 365 | 'name' => $row['name'], |
|
| 366 | 'description' => $row['description'], |
|
| 367 | 'user_id' => (int)$row['user_id'], |
|
| 368 | 'group_id' => (int)$row['group_id'], |
|
| 369 | 'active' => (int)$row['active'], |
|
| 370 | 'show_home' => (int)$row['show_home'], |
|
| 371 | 'image' => $row['image'], |
|
| 372 | 'level' => (int)$this->levelOf($row['id']) |
|
| 373 | ]; |
|
| 374 | } |
|
| 375 | ||
| 376 | return $categories; |
|
| 377 | } |
|
| 378 | ||
| 379 | /** |
|
| 380 | * Get top level categories and returns them in an array. |
|
| @@ 384-418 (lines=35) @@ | ||
| 381 | * |
|
| 382 | * @return array |
|
| 383 | */ |
|
| 384 | public function getTopLevelCategories() |
|
| 385 | { |
|
| 386 | $categories = []; |
|
| 387 | $query = sprintf(' |
|
| 388 | SELECT |
|
| 389 | id, lang, parent_id, name, description, user_id, group_id, active, show_home, image |
|
| 390 | FROM |
|
| 391 | %sfaqcategories |
|
| 392 | WHERE |
|
| 393 | parent_id = 0', |
|
| 394 | Db::getTablePrefix() |
|
| 395 | ); |
|
| 396 | if (isset($this->language) && preg_match("/^[a-z\-]{2,}$/", $this->language)) { |
|
| 397 | $query .= " AND lang = '".$this->language."'"; |
|
| 398 | } |
|
| 399 | $result = $this->config->getDb()->query($query); |
|
| 400 | ||
| 401 | while ($row = $this->config->getDb()->fetchArray($result)) { |
|
| 402 | $categories[(int)$row['id']] = [ |
|
| 403 | 'id' => (int)$row['id'], |
|
| 404 | 'lang' => $row['lang'], |
|
| 405 | 'parent_id' => (int)$row['parent_id'], |
|
| 406 | 'name' => $row['name'], |
|
| 407 | 'description' => $row['description'], |
|
| 408 | 'user_id' => (int)$row['user_id'], |
|
| 409 | 'group_id' => (int)$row['group_id'], |
|
| 410 | 'active' => (int)$row['active'], |
|
| 411 | 'show_home' => (int)$row['show_home'], |
|
| 412 | 'image' => $row['image'], |
|
| 413 | 'level' => (int)$this->levelOf($row['id']) |
|
| 414 | ]; |
|
| 415 | } |
|
| 416 | ||
| 417 | return $categories; |
|
| 418 | } |
|
| 419 | ||
| 420 | /** |
|
| 421 | * Gets all categories and write them in an array. |
|