Phalcon Framework 5.6.1

TypeError: count(): Argument #1 ($value) must be of type Countable|array, int given

/var/www/ua.studyforyou.info/apps/modules/frontend/controllers/CoursesCatalogController.php (409)
#0count
/var/www/ua.studyforyou.info/apps/modules/frontend/controllers/CoursesCatalogController.php (409)
<?php
 
namespace Modules\Frontend\Controllers;
 
use Phalcon\Mvc\View;
 
class CoursesCatalogController extends ControllerBase
{
    public function indexAction()
    {
        $lang_code = $this->language;
        $languagesModel = new \Languages();
        $lang = $languagesModel::findFirstByCode($lang_code)->id;
 
        //second param is filters you want use
        $translates = $this->setViewTranslates($lang, ['menu', 'header', 'filters', 'footer', 'content']);
 
        $this->assets->addCss('frontend/dist/css/courses-catalog.css' . $this->disableCache());
        $this->assets->addJs('frontend/js/courses-catalog.js' . $this->disableCache());
 
        $activeFilters = [
            'search' => null,
            'category' => null,
            'type' => null,
            'country' => null,
            'city' => null,
            'lang' => null,
            'cost' => null,
            'duration' => null,
            'age' => null,
            'profile' => null,
 
        ];
        if ($this->request->get()) {
            if ($this->request->get('searchText')) {
                $search = $this->request->get('searchText');
                $activeFilters['search'] = $search;
            }
            if ($this->request->get('category')) {
                $categoryId = $this->request->get('category');
                $activeFilters['category'] = $categoryId;
                $activeFiltersValues['category'] = [
                    'value' => \FilterTranslates::findFirst($categoryId)->title,
                    'name' => ''//$translates['t_filters']->language_teaching
                ];
            }
            if ($this->request->get('type')) {
                $typeId = $this->request->get('type');
                $activeFilters['type'] = $typeId;
                $activeFiltersValues['type'] = [
                    'value' => \FilterTranslates::findFirst($typeId)->title,
                    'name' => $translates['t_filters']->course_type
                ];
            }
 
            if ($this->request->get('country')) {
                $countryId = $this->request->get('country');
                $activeFilters['country'] = $countryId;
                $activeFiltersValues['country'] = [
                    'value' => \CountriesTranslates::findFirst(["country_id = :country_id: AND language_id = :language_id:", "bind" => ["country_id" => $countryId, 'language_id' => $lang]])->title,
                    'name' => $translates['t_filters']->country
                ];
            }
            if ($this->request->get('city')) {
                $cityId = $this->request->get('city');
                $activeFilters['city'] = $cityId;
                $activeFiltersValues['city'] = [
                    'value' => \CitiesTranslates::findFirst(["city_id = :city_id: AND language_id = :language_id:", "bind" => ["city_id" => $cityId, 'language_id' => $lang]])->title,
                    'name' => $translates['t_filters']->city
                ];
            }
            if ($this->request->get('lang')) {
                $langId = $this->request->get('lang');
                $activeFilters['lang'] = $langId;
                $activeFiltersValues['lang'] = [
                    'value' => \FilterTranslates::findFirst($langId)->title,
                    'name' => $translates['t_filters']->language_teaching
                ];
            }
            if ($this->request->get('cost')) {
                $costTo = $this->request->get('cost');
                $activeFilters['cost'] = $costTo;
                $activeFiltersValues['cost'] = [
                    'value' => \FilterTranslates::findFirst($costTo)->title,
                    'name' => $translates['t_filters']->cost_to
                ];
            }
            if ($this->request->get('duration')) {
                $durationId = $this->request->get('duration');
                $activeFilters['duration'] = $durationId;
                $activeFiltersValues['duration'] = [
                    'value' => \FilterTranslates::findFirst($durationId)->title,
                    'name' => $translates['t_filters']->course_duration
                ];
            }
 
            if ($this->request->get('age')) {
                $ageId = $this->request->get('age');
                $activeFilters['age'] = $ageId;
                $activeFiltersValues['age'] = [
                    'value' => \FilterTranslates::findFirst($ageId)->title,
                    'name' => $translates['t_filters']->course_age
                ];
            }
            if ($this->request->get('profile')) {
                $profileId = $this->request->get('profile');
                $activeFilters['profile'] = $profileId;
                $activeFiltersValues['profile'] = [
                    'value' => \FilterTranslates::findFirst($profileId)->title,
                    'name' => $translates['t_filters']->course_profile
                ];
            }
        }
 
        $data = $this->getCourses($activeFilters, $lang);
 
        $this->setPageContents('courses', $lang);
 
        $this->view->setVars([
            'countries' => \CountriesTranslates::findByLanguageId($lang),
            'cities' => \CitiesTranslates::findByLanguageId($lang),
            'languages' => \FilterTranslates::findManyByGroup('study_lang', $lang),
            'categories' => \FilterTranslates::findManyByGroup('course_tabor_category', $lang),
            'types' => \FilterTranslates::findManyByGroup('course_tabor_type', $lang),
            'costs' => \FilterTranslates::findManyByGroup('course_cost', $lang),
            'durations' => \FilterTranslates::findManyByGroup('course_tabor_duration', $lang),
            'ages' => \FilterTranslates::findManyByGroup('ages', $lang),
            'profiles' => \FilterTranslates::findManyByGroup('course_tabor_profile', $lang),
            'lang' => $lang_code,
 
            'courses' => $data ? $data['courses'] : false,
            'current' => $data ? $data['current'] : false,
            'activeFilters' => $activeFilters,
            'activeFiltersValues' => $activeFiltersValues,
            'coursesCount' => $data['count'],
            //'meta' => \StringsTranslates::getMetaTranslates('courses', $lang)
        ]);
 
        $breadcrumbs = $this->getBaseBreadCrumbs($translates, $lang_code);
 
        $breadcrumbs[] = [
            'pos' => '2',
            'title' => $translates['t_content']->courses_catalog,
            'url' => '/' . $lang_code . '/courses',
            'last' => true
        ];
 
        $this->view->breadcrumbs = $breadcrumbs;
    }
 
    public function getCoursesAction()
    {
        $lang_code = $this->language;
        $languagesModel = new \Languages();
        $lang = $languagesModel::findFirstByCode($lang_code)->id;
        $activeFilters = [];
        $translates = $this->setViewTranslates($lang, ['filters', 'content']);
 
        if ($this->request->get()) {
            if ($this->request->get('sort') != null) {
                $sort = $this->request->get('sort');
                $activeFilters['sort'] = $sort;
            }
            if ($this->request->get('searchText') != null) {
                $search = $this->request->get('searchText');
                $activeFilters['search'] = $search;
            }
            if ($this->request->get('category') != null) {
                $categoryId = $this->request->get('category');
                $activeFilters['category'] = $categoryId;
            }
            if ($this->request->get('type') != null) {
                $typeId = $this->request->get('type');
                $activeFilters['type'] = $typeId;
            }
 
            if ($this->request->get('country') != null) {
                $countryId = $this->request->get('country');
                $activeFilters['country'] = $countryId;
            }
            if ($this->request->get('city') != null) {
                $cityId = $this->request->get('city');
                $activeFilters['city'] = $cityId;
            }
            if ($this->request->get('lang') != null) {
                $langId = $this->request->get('lang');
                $activeFilters['lang'] = $langId;
            }
            if ($this->request->get('cost') != null) {
                $costTo = $this->request->get('cost');
                $activeFilters['cost'] = $costTo;
            }
            if ($this->request->get('duration') != null) {
                $durationId = $this->request->get('duration');
                $activeFilters['duration'] = $durationId;
            }
 
            if ($this->request->get('age') != null) {
                $ageId = $this->request->get('age');
                $activeFilters['age'] = $ageId;
            }
            if ($this->request->get('profile') != null) {
                $profileId = $this->request->get('profile');
                $activeFilters['profile'] = $profileId;
            }
        }
 
        $data = $this->getCourses($activeFilters, $lang);
 
        $this->view->setRenderLevel(
            View::LEVEL_ACTION_VIEW
        );
 
        $this->view->partial(
            'courses-catalog/courses-list',
            [
                'courses' => $data && isset($data['courses']) ? $data['courses'] : false,
                'current' => $data && isset($data['current']) ? $data['current'] : false,
                'filters' => json_encode($activeFilters),
                'coursesCount' => $data ? $data['count'] : 0,
            ]
        );
    }
 
    public function load($start, $data)
    {
        $count = 15;
        $all_data = count($data);
        if ($start <= $all_data) {
            $end = (($start + $count) < $all_data) ? ($start + $count) : $all_data;
            for ($i = $start; $i < $end; $i++) {
                $result[$i] = $data[$i];
            }
        }
        return [
            'courses' => $result ? : false,
            'current' => ($end < $all_data) ? $end : false,
        ];
    }
 
    public function getSearchTipsAction()
    {
        $this->view->disable();
 
        $lang_code = $this->language;
        $languagesModel = new \Languages();
        $lang = $languagesModel::findFirstByCode($lang_code)->id;
 
        $search = $this->request->get('search');
        $bind['language_id'] = $lang;
        if ($search != null) {
            $where = "ctr.title LIKE '%$search%'";
 
            $courses = $this->modelsManager->createBuilder()
                ->addFrom('Courses', 'c')
                ->columns("
        c.id id, 
        ctr.title title
      ")
                ->leftjoin('CourseTranslates', 'ctr.course_id = c.id AND ctr.language_id = :language_id:', 'ctr')
                ->andwhere($where)
                ->andWhere("c.is_published = 1")
                ->getQuery()
                ->execute($bind)
                ->toArray();
 
            foreach ($courses as $key => $item) {
                $courses[$key]['title'] = preg_replace("/($search)/iu", '<b>' . $search . '</b>', $item['title']);
                $courses[$key]['search'][] = $item['title'];
            }
        }
 
        $this->response->setJsonContent(
            $courses,
            JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK
        );
        $this->response->send();
        exit;
 
    }
 
    public function getCourses($filtersData, $lang)
    {
        $current = $this->request->get('current') ? $this->request->get('current') : 0;
        $filters = [1];
        $bind["language_id"] = $lang;
        $search = '';
        $ids = [];
        $favorites = $this->getFavourites('course');
 
        $orderBy = "c.id DESC";
 
        if ($filtersData) {
            if (isset($filtersData['search'])) {
                $search = $filtersData['search'];
                $filters['searchText'] = "(ctr.title LIKE '%$search%')";
            }
            if (isset($filtersData['sort']) && $filtersData['sort'] != 'none') {
                $sort = explode('_', $filtersData['sort']);
                switch ($sort[0]) {
                    case 'cost':
                    {
                        $field = 'cost';
                        break;
                    }
                }
                $orderBy = "c.$field " . $sort[1];
            } else {
                $orderBy = "c.id DESC";
            }
            if (isset($filtersData['category'])) {
                $categoryId = $filtersData['category'];
                $filters['categoryId'] = "ctr.category_id = $categoryId";
            }
            if (isset($filtersData['type'])) {
                $typeId = $filtersData['type'];
                $filters['typeId'] = "ctr.type_id = $typeId";
            }
 
            if (isset($filtersData['country'])) {
                $countryId = $filtersData['country'];
                $filters['countryId'] = "c.country_id = $countryId";
            }
            if (isset($filtersData['city'])) {
                $cityId = $filtersData['city'];
                $filters['cityId'] = "c.city_id = $cityId";
            }
            if (isset($filtersData['lang'])) {
                $langId = $filtersData['lang'];
                $sLangsIds = $this->getField(\CourseLanguages::findByLanguageId($langId)->toArray(), 'course_id');
                if ((is_array($sLangsIds) && count($sLangsIds)) || $sLangsIds)
                    $ids[] = $sLangsIds;
            }
            if (isset($filtersData['cost'])) {
                $costTo = $filtersData['cost'];
                $filters['cost'] = "c.cost < $costTo";
            }
            if (isset($filtersData['duration'])) {
                $durationId = $filtersData['duration'];
                $filters['durationId'] = "ctr.duration = $durationId";
            }
 
            if (isset($filtersData['age'])) {
                $ageId = $filtersData['age'];
                $cAgesIds = $this->getField(\CourseAge::findByAgeId($ageId)->toArray(), 'course_id');
                if ((is_array($cAgesIds) && count($cAgesIds)) || $cAgesIds)
                    $ids[] = $cAgesIds;
            }
            if (isset($filtersData['profile'])) {
                $profileId = $filtersData['profile'];
                $cProfilesIds = $this->getField(\CourseProfile::findByProfileId($profileId)->toArray(), 'course_id');
                if ($cProfilesIds) {
                    if ((is_array($cProfilesIds) && count($cProfilesIds)) ||  $cProfilesIds)
                        $ids[] = $cProfilesIds;
                }
            }
        }
 
        if (count($ids)) {
            if (count($ids) > 1) {
                $intersection = call_user_func_array('array_intersect', $ids);
                $filters['ids'] = $intersection ? "c.id IN (" . implode(',', $intersection) . ")" : 0;
            } else {
                if (count($ids[0]) > 1) {
                    $filters['ids'] = "c.id IN (" . implode(',', $ids[0]) . ")";
                } else {
                    $filters['ids'] = $ids[0] ? "c.id = " . $ids[0][0] : 0;
                }
            }
        }
 
        $where = $filters ? implode(' AND ', $filters) : '1';
 
        $courses = $this->modelsManager->createBuilder()
            ->addFrom('Courses', 'c')
            ->columns("
        c.id id, 
        ctr.title title, 
        c.country_id country_id, 
        c.city_id city_id, 
        ctr.type_id type_id, 
        c.university_id university_id, 
        ctr.category_id category_id, 
        ctr.duration duration, 
        c.cost cost, 
        c.registration_fee registration_fee, 
        c.registration_end registration_end, 
        c.study_start study_start, 
        c.study_hours study_hours, 
        utr.title as university, 
        ctr.url_suffix url_suffix, 
        utr.url_suffix as university_url
      ")
            ->leftjoin('UniversityTranslates', 'utr.university_id = c.university_id AND utr.language_id = :language_id:', 'utr')
            ->leftjoin('CourseTranslates', 'ctr.course_id = c.id AND ctr.language_id = :language_id:', 'ctr')
            ->andwhere($where)
            ->andWhere("c.is_published = 1")
            ->orderBy($orderBy)
            ->getQuery()
            ->execute($bind)
            ->toArray();
 
        if (count($courses)) {
            foreach ($courses as $key => $course) {
                $course_langs = \CourseLanguages::findByCourseId($courses[$key]['id'])->toArray();
 
                $langs_ids = $this->getField($course_langs, 'language_id');
 
                if (count($langs_ids))
                    $langs = \FilterTranslates::find(["id IN ({langs_ids:array}) AND language_id = :language_id:", "bind" => ["langs_ids" => $langs_ids, "language_id" => $lang]])->toArray();
 
                $course_profiles = \CourseProfile::findByCourseId($courses[$key]['id'])->toArray();
                $profiles_ids = $this->getField($course_profiles, 'profile_id');
                if (count($profiles_ids))
                    $profiles = \FilterTranslates::find(["id IN ({profiles_ids:array}) AND language_id = :language_id:", "bind" => ["profiles_ids" => $profiles_ids, "language_id" => $lang]])->toArray();
 
                $country = \CountriesTranslates::findFirst([
                    "country_id = :country_id: AND language_id = :language_id:",
                    "bind" => ["country_id" => $courses[$key]['country_id'], "language_id" => $lang]
                ]);
                $city = \CitiesTranslates::findFirst([
                    "city_id = :city_id: AND language_id = :language_id:",
                    "bind" => ["city_id" => $courses[$key]['city_id'], "language_id" => $lang]
                ]);
 
                $type = \FilterTranslates::findFirst(["id = :type_id: AND language_id = :language_id:", "bind" => ["type_id" => $courses[$key]['type_id'], "language_id" => $lang]]);
                $duration = \FilterTranslates::findFirst(["id = :duration_id: AND language_id = :language_id:", "bind" => ["duration_id" => $courses[$key]['duration'], "language_id" => $lang]]);
 
                $univer_id = \Universities::findFirstById($courses[$key]['university_id']);
                if ($univer_id) {
                    if ($univer_id->university_logo_id) {
                        $univerLogo = \Medias::findFirst($univer_id->university_logo_id)->small_url ?? '';
                        $logoAlt = \MediaSeo::findFirst(["media_id = :media_id: AND language_id = :language_id:", "bind" => ["media_id" => $univer_id->university_logo_id, "language_id" => $lang]]);
                    }
                    if ($univer_id->banner_image_id) {
                        $univerBanner = \Medias::findFirst($univer_id->banner_image_id)->large_url;
                        $bannerAlt = \MediaSeo::findFirst(["media_id = :media_id: AND language_id = :language_id:", "bind" => ["media_id" => $univer_id->banner_image_id, "language_id" => $lang]]);
                    }
                }
 
                $courses[$key]['langs'] = $langs ? implode(', ', $this->getField($langs, 'title')) : null;
                $courses[$key]['profiles'] = $profiles ? implode(', ', $this->getField($profiles, 'title')) : null;
                $courses[$key]['country'] = $country ? $country->title : null;
                $courses[$key]['country_code'] = $country ? \Countries::findFirstById($country->country_id)->code : null;
                $courses[$key]['city'] = $city ? $city->title : null;
                $courses[$key]['type'] = $type ? $type->title : null;
                $courses[$key]['duration'] = $duration ? $duration->title : null;
                $courses[$key]['univerLogo'] = $univerLogo;
                $courses[$key]['univerBanner'] = $univerBanner;
                $courses[$key]['logoAlt'] = $logoAlt ? $logoAlt->alt : null;
                $courses[$key]['bannerAlt'] = $bannerAlt ? $bannerAlt->alt : null;
 
                $courses[$key]['favorite'] = $favorites ? (in_array($courses[$key]['id'], $favorites) ? true : false) : false;
            }
 
            $data = $this->load($current, $courses);
        } else {
            $data = false;
        }
 
        if($data) {
            $data['count'] = $courses ? count($courses) : 0;
        }
 
        return $data;
    }
}
#1Modules\Frontend\Controllers\CoursesCatalogController->getCourses
/var/www/ua.studyforyou.info/apps/modules/frontend/controllers/CoursesCatalogController.php (115)
<?php
 
namespace Modules\Frontend\Controllers;
 
use Phalcon\Mvc\View;
 
class CoursesCatalogController extends ControllerBase
{
    public function indexAction()
    {
        $lang_code = $this->language;
        $languagesModel = new \Languages();
        $lang = $languagesModel::findFirstByCode($lang_code)->id;
 
        //second param is filters you want use
        $translates = $this->setViewTranslates($lang, ['menu', 'header', 'filters', 'footer', 'content']);
 
        $this->assets->addCss('frontend/dist/css/courses-catalog.css' . $this->disableCache());
        $this->assets->addJs('frontend/js/courses-catalog.js' . $this->disableCache());
 
        $activeFilters = [
            'search' => null,
            'category' => null,
            'type' => null,
            'country' => null,
            'city' => null,
            'lang' => null,
            'cost' => null,
            'duration' => null,
            'age' => null,
            'profile' => null,
 
        ];
        if ($this->request->get()) {
            if ($this->request->get('searchText')) {
                $search = $this->request->get('searchText');
                $activeFilters['search'] = $search;
            }
            if ($this->request->get('category')) {
                $categoryId = $this->request->get('category');
                $activeFilters['category'] = $categoryId;
                $activeFiltersValues['category'] = [
                    'value' => \FilterTranslates::findFirst($categoryId)->title,
                    'name' => ''//$translates['t_filters']->language_teaching
                ];
            }
            if ($this->request->get('type')) {
                $typeId = $this->request->get('type');
                $activeFilters['type'] = $typeId;
                $activeFiltersValues['type'] = [
                    'value' => \FilterTranslates::findFirst($typeId)->title,
                    'name' => $translates['t_filters']->course_type
                ];
            }
 
            if ($this->request->get('country')) {
                $countryId = $this->request->get('country');
                $activeFilters['country'] = $countryId;
                $activeFiltersValues['country'] = [
                    'value' => \CountriesTranslates::findFirst(["country_id = :country_id: AND language_id = :language_id:", "bind" => ["country_id" => $countryId, 'language_id' => $lang]])->title,
                    'name' => $translates['t_filters']->country
                ];
            }
            if ($this->request->get('city')) {
                $cityId = $this->request->get('city');
                $activeFilters['city'] = $cityId;
                $activeFiltersValues['city'] = [
                    'value' => \CitiesTranslates::findFirst(["city_id = :city_id: AND language_id = :language_id:", "bind" => ["city_id" => $cityId, 'language_id' => $lang]])->title,
                    'name' => $translates['t_filters']->city
                ];
            }
            if ($this->request->get('lang')) {
                $langId = $this->request->get('lang');
                $activeFilters['lang'] = $langId;
                $activeFiltersValues['lang'] = [
                    'value' => \FilterTranslates::findFirst($langId)->title,
                    'name' => $translates['t_filters']->language_teaching
                ];
            }
            if ($this->request->get('cost')) {
                $costTo = $this->request->get('cost');
                $activeFilters['cost'] = $costTo;
                $activeFiltersValues['cost'] = [
                    'value' => \FilterTranslates::findFirst($costTo)->title,
                    'name' => $translates['t_filters']->cost_to
                ];
            }
            if ($this->request->get('duration')) {
                $durationId = $this->request->get('duration');
                $activeFilters['duration'] = $durationId;
                $activeFiltersValues['duration'] = [
                    'value' => \FilterTranslates::findFirst($durationId)->title,
                    'name' => $translates['t_filters']->course_duration
                ];
            }
 
            if ($this->request->get('age')) {
                $ageId = $this->request->get('age');
                $activeFilters['age'] = $ageId;
                $activeFiltersValues['age'] = [
                    'value' => \FilterTranslates::findFirst($ageId)->title,
                    'name' => $translates['t_filters']->course_age
                ];
            }
            if ($this->request->get('profile')) {
                $profileId = $this->request->get('profile');
                $activeFilters['profile'] = $profileId;
                $activeFiltersValues['profile'] = [
                    'value' => \FilterTranslates::findFirst($profileId)->title,
                    'name' => $translates['t_filters']->course_profile
                ];
            }
        }
 
        $data = $this->getCourses($activeFilters, $lang);
 
        $this->setPageContents('courses', $lang);
 
        $this->view->setVars([
            'countries' => \CountriesTranslates::findByLanguageId($lang),
            'cities' => \CitiesTranslates::findByLanguageId($lang),
            'languages' => \FilterTranslates::findManyByGroup('study_lang', $lang),
            'categories' => \FilterTranslates::findManyByGroup('course_tabor_category', $lang),
            'types' => \FilterTranslates::findManyByGroup('course_tabor_type', $lang),
            'costs' => \FilterTranslates::findManyByGroup('course_cost', $lang),
            'durations' => \FilterTranslates::findManyByGroup('course_tabor_duration', $lang),
            'ages' => \FilterTranslates::findManyByGroup('ages', $lang),
            'profiles' => \FilterTranslates::findManyByGroup('course_tabor_profile', $lang),
            'lang' => $lang_code,
 
            'courses' => $data ? $data['courses'] : false,
            'current' => $data ? $data['current'] : false,
            'activeFilters' => $activeFilters,
            'activeFiltersValues' => $activeFiltersValues,
            'coursesCount' => $data['count'],
            //'meta' => \StringsTranslates::getMetaTranslates('courses', $lang)
        ]);
 
        $breadcrumbs = $this->getBaseBreadCrumbs($translates, $lang_code);
 
        $breadcrumbs[] = [
            'pos' => '2',
            'title' => $translates['t_content']->courses_catalog,
            'url' => '/' . $lang_code . '/courses',
            'last' => true
        ];
 
        $this->view->breadcrumbs = $breadcrumbs;
    }
 
    public function getCoursesAction()
    {
        $lang_code = $this->language;
        $languagesModel = new \Languages();
        $lang = $languagesModel::findFirstByCode($lang_code)->id;
        $activeFilters = [];
        $translates = $this->setViewTranslates($lang, ['filters', 'content']);
 
        if ($this->request->get()) {
            if ($this->request->get('sort') != null) {
                $sort = $this->request->get('sort');
                $activeFilters['sort'] = $sort;
            }
            if ($this->request->get('searchText') != null) {
                $search = $this->request->get('searchText');
                $activeFilters['search'] = $search;
            }
            if ($this->request->get('category') != null) {
                $categoryId = $this->request->get('category');
                $activeFilters['category'] = $categoryId;
            }
            if ($this->request->get('type') != null) {
                $typeId = $this->request->get('type');
                $activeFilters['type'] = $typeId;
            }
 
            if ($this->request->get('country') != null) {
                $countryId = $this->request->get('country');
                $activeFilters['country'] = $countryId;
            }
            if ($this->request->get('city') != null) {
                $cityId = $this->request->get('city');
                $activeFilters['city'] = $cityId;
            }
            if ($this->request->get('lang') != null) {
                $langId = $this->request->get('lang');
                $activeFilters['lang'] = $langId;
            }
            if ($this->request->get('cost') != null) {
                $costTo = $this->request->get('cost');
                $activeFilters['cost'] = $costTo;
            }
            if ($this->request->get('duration') != null) {
                $durationId = $this->request->get('duration');
                $activeFilters['duration'] = $durationId;
            }
 
            if ($this->request->get('age') != null) {
                $ageId = $this->request->get('age');
                $activeFilters['age'] = $ageId;
            }
            if ($this->request->get('profile') != null) {
                $profileId = $this->request->get('profile');
                $activeFilters['profile'] = $profileId;
            }
        }
 
        $data = $this->getCourses($activeFilters, $lang);
 
        $this->view->setRenderLevel(
            View::LEVEL_ACTION_VIEW
        );
 
        $this->view->partial(
            'courses-catalog/courses-list',
            [
                'courses' => $data && isset($data['courses']) ? $data['courses'] : false,
                'current' => $data && isset($data['current']) ? $data['current'] : false,
                'filters' => json_encode($activeFilters),
                'coursesCount' => $data ? $data['count'] : 0,
            ]
        );
    }
 
    public function load($start, $data)
    {
        $count = 15;
        $all_data = count($data);
        if ($start <= $all_data) {
            $end = (($start + $count) < $all_data) ? ($start + $count) : $all_data;
            for ($i = $start; $i < $end; $i++) {
                $result[$i] = $data[$i];
            }
        }
        return [
            'courses' => $result ? : false,
            'current' => ($end < $all_data) ? $end : false,
        ];
    }
 
    public function getSearchTipsAction()
    {
        $this->view->disable();
 
        $lang_code = $this->language;
        $languagesModel = new \Languages();
        $lang = $languagesModel::findFirstByCode($lang_code)->id;
 
        $search = $this->request->get('search');
        $bind['language_id'] = $lang;
        if ($search != null) {
            $where = "ctr.title LIKE '%$search%'";
 
            $courses = $this->modelsManager->createBuilder()
                ->addFrom('Courses', 'c')
                ->columns("
        c.id id, 
        ctr.title title
      ")
                ->leftjoin('CourseTranslates', 'ctr.course_id = c.id AND ctr.language_id = :language_id:', 'ctr')
                ->andwhere($where)
                ->andWhere("c.is_published = 1")
                ->getQuery()
                ->execute($bind)
                ->toArray();
 
            foreach ($courses as $key => $item) {
                $courses[$key]['title'] = preg_replace("/($search)/iu", '<b>' . $search . '</b>', $item['title']);
                $courses[$key]['search'][] = $item['title'];
            }
        }
 
        $this->response->setJsonContent(
            $courses,
            JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK
        );
        $this->response->send();
        exit;
 
    }
 
    public function getCourses($filtersData, $lang)
    {
        $current = $this->request->get('current') ? $this->request->get('current') : 0;
        $filters = [1];
        $bind["language_id"] = $lang;
        $search = '';
        $ids = [];
        $favorites = $this->getFavourites('course');
 
        $orderBy = "c.id DESC";
 
        if ($filtersData) {
            if (isset($filtersData['search'])) {
                $search = $filtersData['search'];
                $filters['searchText'] = "(ctr.title LIKE '%$search%')";
            }
            if (isset($filtersData['sort']) && $filtersData['sort'] != 'none') {
                $sort = explode('_', $filtersData['sort']);
                switch ($sort[0]) {
                    case 'cost':
                    {
                        $field = 'cost';
                        break;
                    }
                }
                $orderBy = "c.$field " . $sort[1];
            } else {
                $orderBy = "c.id DESC";
            }
            if (isset($filtersData['category'])) {
                $categoryId = $filtersData['category'];
                $filters['categoryId'] = "ctr.category_id = $categoryId";
            }
            if (isset($filtersData['type'])) {
                $typeId = $filtersData['type'];
                $filters['typeId'] = "ctr.type_id = $typeId";
            }
 
            if (isset($filtersData['country'])) {
                $countryId = $filtersData['country'];
                $filters['countryId'] = "c.country_id = $countryId";
            }
            if (isset($filtersData['city'])) {
                $cityId = $filtersData['city'];
                $filters['cityId'] = "c.city_id = $cityId";
            }
            if (isset($filtersData['lang'])) {
                $langId = $filtersData['lang'];
                $sLangsIds = $this->getField(\CourseLanguages::findByLanguageId($langId)->toArray(), 'course_id');
                if ((is_array($sLangsIds) && count($sLangsIds)) || $sLangsIds)
                    $ids[] = $sLangsIds;
            }
            if (isset($filtersData['cost'])) {
                $costTo = $filtersData['cost'];
                $filters['cost'] = "c.cost < $costTo";
            }
            if (isset($filtersData['duration'])) {
                $durationId = $filtersData['duration'];
                $filters['durationId'] = "ctr.duration = $durationId";
            }
 
            if (isset($filtersData['age'])) {
                $ageId = $filtersData['age'];
                $cAgesIds = $this->getField(\CourseAge::findByAgeId($ageId)->toArray(), 'course_id');
                if ((is_array($cAgesIds) && count($cAgesIds)) || $cAgesIds)
                    $ids[] = $cAgesIds;
            }
            if (isset($filtersData['profile'])) {
                $profileId = $filtersData['profile'];
                $cProfilesIds = $this->getField(\CourseProfile::findByProfileId($profileId)->toArray(), 'course_id');
                if ($cProfilesIds) {
                    if ((is_array($cProfilesIds) && count($cProfilesIds)) ||  $cProfilesIds)
                        $ids[] = $cProfilesIds;
                }
            }
        }
 
        if (count($ids)) {
            if (count($ids) > 1) {
                $intersection = call_user_func_array('array_intersect', $ids);
                $filters['ids'] = $intersection ? "c.id IN (" . implode(',', $intersection) . ")" : 0;
            } else {
                if (count($ids[0]) > 1) {
                    $filters['ids'] = "c.id IN (" . implode(',', $ids[0]) . ")";
                } else {
                    $filters['ids'] = $ids[0] ? "c.id = " . $ids[0][0] : 0;
                }
            }
        }
 
        $where = $filters ? implode(' AND ', $filters) : '1';
 
        $courses = $this->modelsManager->createBuilder()
            ->addFrom('Courses', 'c')
            ->columns("
        c.id id, 
        ctr.title title, 
        c.country_id country_id, 
        c.city_id city_id, 
        ctr.type_id type_id, 
        c.university_id university_id, 
        ctr.category_id category_id, 
        ctr.duration duration, 
        c.cost cost, 
        c.registration_fee registration_fee, 
        c.registration_end registration_end, 
        c.study_start study_start, 
        c.study_hours study_hours, 
        utr.title as university, 
        ctr.url_suffix url_suffix, 
        utr.url_suffix as university_url
      ")
            ->leftjoin('UniversityTranslates', 'utr.university_id = c.university_id AND utr.language_id = :language_id:', 'utr')
            ->leftjoin('CourseTranslates', 'ctr.course_id = c.id AND ctr.language_id = :language_id:', 'ctr')
            ->andwhere($where)
            ->andWhere("c.is_published = 1")
            ->orderBy($orderBy)
            ->getQuery()
            ->execute($bind)
            ->toArray();
 
        if (count($courses)) {
            foreach ($courses as $key => $course) {
                $course_langs = \CourseLanguages::findByCourseId($courses[$key]['id'])->toArray();
 
                $langs_ids = $this->getField($course_langs, 'language_id');
 
                if (count($langs_ids))
                    $langs = \FilterTranslates::find(["id IN ({langs_ids:array}) AND language_id = :language_id:", "bind" => ["langs_ids" => $langs_ids, "language_id" => $lang]])->toArray();
 
                $course_profiles = \CourseProfile::findByCourseId($courses[$key]['id'])->toArray();
                $profiles_ids = $this->getField($course_profiles, 'profile_id');
                if (count($profiles_ids))
                    $profiles = \FilterTranslates::find(["id IN ({profiles_ids:array}) AND language_id = :language_id:", "bind" => ["profiles_ids" => $profiles_ids, "language_id" => $lang]])->toArray();
 
                $country = \CountriesTranslates::findFirst([
                    "country_id = :country_id: AND language_id = :language_id:",
                    "bind" => ["country_id" => $courses[$key]['country_id'], "language_id" => $lang]
                ]);
                $city = \CitiesTranslates::findFirst([
                    "city_id = :city_id: AND language_id = :language_id:",
                    "bind" => ["city_id" => $courses[$key]['city_id'], "language_id" => $lang]
                ]);
 
                $type = \FilterTranslates::findFirst(["id = :type_id: AND language_id = :language_id:", "bind" => ["type_id" => $courses[$key]['type_id'], "language_id" => $lang]]);
                $duration = \FilterTranslates::findFirst(["id = :duration_id: AND language_id = :language_id:", "bind" => ["duration_id" => $courses[$key]['duration'], "language_id" => $lang]]);
 
                $univer_id = \Universities::findFirstById($courses[$key]['university_id']);
                if ($univer_id) {
                    if ($univer_id->university_logo_id) {
                        $univerLogo = \Medias::findFirst($univer_id->university_logo_id)->small_url ?? '';
                        $logoAlt = \MediaSeo::findFirst(["media_id = :media_id: AND language_id = :language_id:", "bind" => ["media_id" => $univer_id->university_logo_id, "language_id" => $lang]]);
                    }
                    if ($univer_id->banner_image_id) {
                        $univerBanner = \Medias::findFirst($univer_id->banner_image_id)->large_url;
                        $bannerAlt = \MediaSeo::findFirst(["media_id = :media_id: AND language_id = :language_id:", "bind" => ["media_id" => $univer_id->banner_image_id, "language_id" => $lang]]);
                    }
                }
 
                $courses[$key]['langs'] = $langs ? implode(', ', $this->getField($langs, 'title')) : null;
                $courses[$key]['profiles'] = $profiles ? implode(', ', $this->getField($profiles, 'title')) : null;
                $courses[$key]['country'] = $country ? $country->title : null;
                $courses[$key]['country_code'] = $country ? \Countries::findFirstById($country->country_id)->code : null;
                $courses[$key]['city'] = $city ? $city->title : null;
                $courses[$key]['type'] = $type ? $type->title : null;
                $courses[$key]['duration'] = $duration ? $duration->title : null;
                $courses[$key]['univerLogo'] = $univerLogo;
                $courses[$key]['univerBanner'] = $univerBanner;
                $courses[$key]['logoAlt'] = $logoAlt ? $logoAlt->alt : null;
                $courses[$key]['bannerAlt'] = $bannerAlt ? $bannerAlt->alt : null;
 
                $courses[$key]['favorite'] = $favorites ? (in_array($courses[$key]['id'], $favorites) ? true : false) : false;
            }
 
            $data = $this->load($current, $courses);
        } else {
            $data = false;
        }
 
        if($data) {
            $data['count'] = $courses ? count($courses) : 0;
        }
 
        return $data;
    }
}
#2Modules\Frontend\Controllers\CoursesCatalogController->indexAction
#3Phalcon\Dispatcher\AbstractDispatcher->callActionMethod
#4Phalcon\Dispatcher\AbstractDispatcher->dispatch
#5Phalcon\Mvc\Application->handle
/var/www/ua.studyforyou.info/public/index.php (58)
<?php
//
use Phalcon\Mvc\Application;
use Phalcon\DI\FactoryDefault;
 
 
(new Phalcon\Support\Debug)->listen();
 
 
require_once __DIR__ . '/../vendor/autoload.php';
 
/**
 * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
 */
$di = new FactoryDefault();
 
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
 
if($_ENV['ENVIRONMENT'] == 'local'){
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    error_reporting(E_ALL & ~E_NOTICE);
} else {
    ini_set('display_errors', 0);
}
 
try {
 
 
    /**
     * Include services
     */
    $config = require __DIR__ . "/../apps/config/config.php";
 
 
    require_once __DIR__ . '/../apps/config/services.php';
 
    /**
     * Registering a router
     */
 
    require_once __DIR__ . "/../apps/config/routers.php";
 
 
    /**
     * Handle the request
     */
    $application = new Application($di);
 
 
    /**
     * Include modules
     */
    require_once __DIR__ . '/../apps/config/modules.php';
 
    $application->handle($_SERVER['REQUEST_URI'])->send();
 
 
} catch (\Exception $e) {
    echo $e->getMessage();
} catch (PDOException $e) {
    echo $e->getMessage();
}
 
KeyValue
_url/uk/courses
KeyValue
USERwww-data
HOME/var/www
HTTP_HOSTdev.studyforyou.info
HTTP_ACCEPT_ENCODINGgzip, br, zstd, deflate
HTTP_USER_AGENTMozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
HTTP_ACCEPT*/*
SCRIPT_FILENAME/var/www/ua.studyforyou.info/public/index.php
PATH_INFO
REDIRECT_STATUS200
SERVER_NAMEdev.studyforyou.info
SERVER_PORT443
SERVER_ADDR54.37.235.116
REMOTE_PORT34081
REMOTE_ADDR18.119.112.17
SERVER_SOFTWAREnginx/1.18.0
GATEWAY_INTERFACECGI/1.1
HTTPSon
REQUEST_SCHEMEhttps
SERVER_PROTOCOLHTTP/1.1
DOCUMENT_ROOT/var/www/ua.studyforyou.info/public
DOCUMENT_URI/index.php
REQUEST_URI/uk/courses
SCRIPT_NAME/index.php
CONTENT_LENGTH
CONTENT_TYPE
REQUEST_METHODGET
QUERY_STRING_url=/uk/courses&
FCGI_ROLERESPONDER
PHP_SELF/index.php
REQUEST_TIME_FLOAT1747235211.0249
REQUEST_TIME1747235211
SITE_URLhttps://dev.studyforyou.info
DATABASE_HOSTlocalhost
USERNAMEsfy_database
PASSWORDe234rwdf33123
DBNAMEsfy_ua
LOG_IN_DBtrue
IMAGEPATH/var/www/data/images/
#Path
0/var/www/ua.studyforyou.info/public/index.php
1/var/www/ua.studyforyou.info/vendor/autoload.php
2/var/www/ua.studyforyou.info/vendor/composer/autoload_real.php
3/var/www/ua.studyforyou.info/vendor/composer/platform_check.php
4/var/www/ua.studyforyou.info/vendor/composer/ClassLoader.php
5/var/www/ua.studyforyou.info/vendor/composer/autoload_static.php
6/var/www/ua.studyforyou.info/vendor/symfony/deprecation-contracts/function.php
7/var/www/ua.studyforyou.info/vendor/symfony/polyfill-ctype/bootstrap.php
8/var/www/ua.studyforyou.info/vendor/symfony/polyfill-ctype/bootstrap80.php
9/var/www/ua.studyforyou.info/vendor/symfony/polyfill-mbstring/bootstrap.php
10/var/www/ua.studyforyou.info/vendor/symfony/polyfill-mbstring/bootstrap80.php
11/var/www/ua.studyforyou.info/vendor/cakephp/core/functions.php
12/var/www/ua.studyforyou.info/vendor/cakephp/core/functions_global.php
13/var/www/ua.studyforyou.info/vendor/symfony/polyfill-intl-grapheme/bootstrap.php
14/var/www/ua.studyforyou.info/vendor/symfony/polyfill-intl-grapheme/bootstrap80.php
15/var/www/ua.studyforyou.info/vendor/symfony/polyfill-intl-normalizer/bootstrap.php
16/var/www/ua.studyforyou.info/vendor/symfony/polyfill-intl-normalizer/bootstrap80.php
17/var/www/ua.studyforyou.info/vendor/symfony/string/Resources/functions.php
18/var/www/ua.studyforyou.info/vendor/cakephp/utility/bootstrap.php
19/var/www/ua.studyforyou.info/vendor/cakephp/utility/Inflector.php
20/var/www/ua.studyforyou.info/vendor/symfony/polyfill-php80/bootstrap.php
21/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Dotenv.php
22/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/RepositoryBuilder.php
23/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/ServerConstAdapter.php
24/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/AdapterInterface.php
25/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/ReaderInterface.php
26/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/WriterInterface.php
27/var/www/ua.studyforyou.info/vendor/phpoption/phpoption/src/PhpOption/Some.php
28/var/www/ua.studyforyou.info/vendor/phpoption/phpoption/src/PhpOption/Option.php
29/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/EnvConstAdapter.php
30/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiReader.php
31/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiWriter.php
32/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/ImmutableWriter.php
33/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/AdapterRepository.php
34/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/RepositoryInterface.php
35/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php
36/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Store/FileStore.php
37/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Store/StoreInterface.php
38/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Store/File/Paths.php
39/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/Parser.php
40/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/ParserInterface.php
41/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Loader/Loader.php
42/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Loader/LoaderInterface.php
43/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Store/File/Reader.php
44/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Util/Str.php
45/var/www/ua.studyforyou.info/vendor/symfony/polyfill-mbstring/Mbstring.php
46/var/www/ua.studyforyou.info/vendor/graham-campbell/result-type/src/Success.php
47/var/www/ua.studyforyou.info/vendor/graham-campbell/result-type/src/Result.php
48/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Util/Regex.php
49/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/Lines.php
50/var/www/ua.studyforyou.info/vendor/phpoption/phpoption/src/PhpOption/None.php
51/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/EntryParser.php
52/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/Lexer.php
53/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/Value.php
54/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/Entry.php
55/var/www/ua.studyforyou.info/vendor/vlucas/phpdotenv/src/Loader/Resolver.php
56/var/www/ua.studyforyou.info/apps/config/config.php
57/var/www/ua.studyforyou.info/vendor/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php
58/var/www/ua.studyforyou.info/apps/config/services.php
59/var/www/ua.studyforyou.info/apps/config/routers.php
60/var/www/ua.studyforyou.info/apps/config/modules.php
61/var/www/ua.studyforyou.info/apps/config/routesAdmin.php
62/var/www/ua.studyforyou.info/apps/config/routesFrontend.php
63/var/www/ua.studyforyou.info/apps/modules/frontend/Module.php
64/var/www/ua.studyforyou.info/apps/modules/frontend/controllers/CoursesCatalogController.php
65/var/www/ua.studyforyou.info/apps/modules/frontend/controllers/ControllerBase.php
66/var/www/ua.studyforyou.info/apps/modules/frontend/controllers/AuthController.php
67/var/www/ua.studyforyou.info/apps/models/Languages.php
68/var/www/ua.studyforyou.info/apps/models/FilterTranslates.php
69/var/www/ua.studyforyou.info/apps/models/ArticleTranslates.php
70/var/www/ua.studyforyou.info/apps/models/Strings.php
71/var/www/ua.studyforyou.info/apps/models/StringsTranslates.php
72/var/www/ua.studyforyou.info/apps/models/CountriesTranslates.php
73/var/www/ua.studyforyou.info/apps/models/Filters.php
74/var/www/ua.studyforyou.info/apps/models/CitiesTranslates.php
75/var/www/ua.studyforyou.info/apps/models/Courses.php
76/var/www/ua.studyforyou.info/apps/models/UniversityTranslates.php
77/var/www/ua.studyforyou.info/apps/models/CourseTranslates.php
78/var/www/ua.studyforyou.info/apps/models/CourseLanguages.php
Memory
Usage2097152