Phalcon Framework 5.6.1

TypeError: array_merge(): Argument #2 must be of type array, null given

/var/www/studyforyou.info/apps/modules/frontend/controllers/SpecialityProfileController.php (307)
#0array_merge
/var/www/studyforyou.info/apps/modules/frontend/controllers/SpecialityProfileController.php (307)
<?php
 
namespace Modules\Frontend\Controllers;
 
class SpecialityProfileController extends ControllerBase
{
    public function indexAction($speciality)
    {
 
        $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', 'tabs']);
 
        $this->assets->addCss('frontend/dist/css/speciality-profile.css' . $this->disableCache());
        $this->assets->addJs('frontend/js/speciality-profile.js' . $this->disableCache());
        $this->assets->addJs('frontend/js/rating.js' . $this->disableCache());
 
        $specialityRecord = $this->modelsManager->createBuilder()
            ->addFrom('Specialities', 's')
            ->columns("
                s.id id, 
                str.title title, 
                s.cost_per_year cost_per_year, 
                s.cost_per_sem cost_per_sem, 
                s.country_id country_id, 
                s.city_id city_id, 
                cot.title as country, 
                cit.title as city, 
                ft.title as study_level, 
                str.faculty_id faculty_id, 
                str.science_id science_id, 
                s.registration_fee registration_fee, 
                s.registration_end registration_end, 
                s.study_start study_start, 
                s.is_apply_free is_apply_free, 
                utr.title as university, 
                ssd.duration_months as study_duration, 
                str.url_suffix url_suffix, 
                str.seo_title seo_title, 
                str.seo_description seo_description, 
                str.seo_keywords seo_keywords, 
                str.url_cannonical url_cannonical, 
                s.university_id university_id, 
                str.study_level_id study_level_id, 
                sd.job_description job_description, 
                sd.study_description study_description
            ")
            ->leftjoin('UniversityTranslates', 'utr.university_id = s.university_id AND utr.language_id = :lang:', 'utr')
            ->leftjoin('SpecialityTranslates', 'str.speciality_id = s.id AND str.language_id = :lang:', 'str')
            ->leftjoin('SpecialityStudyDurations', 'ssd.speciality_id = s.id', 'ssd')
            ->leftjoin('FilterTranslates', 'ft.id = str.study_level_id AND ft.language_id = :lang:', 'ft')
            ->leftjoin('CountriesTranslates', 'cot.country_id = s.country_id AND cot.language_id = :lang:', 'cot')
            ->leftjoin('CitiesTranslates', 'cit.city_id = s.city_id AND cit.language_id = :lang:', 'cit')
            ->leftjoin('SpecialityDescription', 's.id = sd.speciality_id AND sd.language_id = :lang:', 'sd')
            ->where("str.url_suffix = :speciality:")
            ->andWhere("s.is_published = 1")
            ->getQuery()
            ->getSingleResult(['speciality' => $speciality, 'lang' => $lang]);
 
        if ($specialityRecord) {
            $specialityRecord = $specialityRecord->toArray();
 
            $speciality_langs = \SpecialityLanguages::findBySpecialityId($specialityRecord['id'])->toArray();
 
            $langs_ids = $this->getField($speciality_langs, 'language_id');
 
            if ($langs_ids) {
                if (count($langs_ids) > 1) {
                    $where = "id IN ({langs_ids:array}) AND language_id = :lang:";
                } else {
                    $where = "id = :langs_ids: AND language_id = :lang:";
                    $langs_ids = $langs_ids[0];
                }
                $langs = \FilterTranslates::find([
                    $where,
                    "bind" => ["langs_ids" => $langs_ids, "lang" => $lang]])->toArray();
            }
            $faculty = \FilterTranslates::findFirst(["id = :faculty: AND language_id = :language_id:", "bind" => ["faculty" => $specialityRecord['faculty_id'], "language_id" => $lang]])->title;
 
            $speciality_documents = \SpecialityRequiredDocuments::findBySpecialityId($specialityRecord['id'])->toArray();
 
            $speciality_documents_ids = $this->getField($speciality_documents, 'document_id');
 
            if ($speciality_documents_ids && count($speciality_documents_ids)) {
                $documents = \FilterTranslates::find([
                    "id IN ({speciality_documents_ids:array}) AND language_id = :lang:",
                    "bind" => ["speciality_documents_ids" => $speciality_documents_ids, "lang" => $lang]])->toArray();
                foreach ($speciality_documents as $key => $val) {
                    foreach ($documents as $item => $value) {
                        if ($value['id'] == $val['document_id'])
                            $document[] = $value['title'];
                    }
                }
                $documents = $document;
            }
 
            $speciality_jobs = \SpecialityJobs::findBySpecialityId($specialityRecord['id'])->toArray();
 
            $speciality_jobs_ids = $this->getField($speciality_jobs, 'job_id');
 
            if ($speciality_jobs_ids && count($speciality_jobs_ids))
                $jobs = \FilterTranslates::find([
                    "id IN ({speciality_jobs_ids:array}) AND language_id = :lang:",
                    "bind" => ["speciality_jobs_ids" => $speciality_jobs_ids, "lang" => $lang]]);
 
            $speciality_subjects = \SpecialitySubjects::findBySpecialityId($specialityRecord['id'])->toArray();
 
            foreach ($speciality_subjects as $speciality_subject) {
                $subject_id = $speciality_subject['subject_id'];
                $subjects[] = (object)[
                    'title' => \FilterTranslates::findFirst([
                        'filter_id = :subject_id: AND language_id = :language_id:',
                        'bind' => ['subject_id' => $subject_id, 'language_id' => $lang]
                    ])->title,
                    'duration_hr' => $speciality_subject['duration_hr'],
                    'checkboxes' => $speciality_subject['checkboxes'],
                ];
            }
 
            $specialityRecord['study_start'] = date("d.m.Y", strtotime($specialityRecord['study_start']));
            $specialityRecord['registration_end'] = date("d.m.Y", strtotime($specialityRecord['registration_end']));
 
            $univer_record = \Universities::findFirstById($specialityRecord['university_id']);
            if ($univer_record) {
                if ($univer_record->university_logo_id) {
                    $univerLogo = \Medias::findFirst($univer_record->university_logo_id)->large_url;
                    $logoAlt = \MediaSeo::findFirst(["media_id = :media_id: AND language_id = :language_id:", "bind" => ["media_id" => $univer_record->university_logo_id, "language_id" => $lang]])->alt;
                }
                if ($univer_record->banner_image_id)
                    $univerBanner = \Medias::findFirst($univer_record->banner_image_id)->original_url;
 
                $univerUrlSuffix = \UniversityTranslates::findFirst(["university_id = ?0 AND language_id = ?1", "bind" => [0 => $univer_record->id, 1 => $lang]])->url_suffix;
 
                $country = \CountriesTranslates::findFirst(["country_id = :country_id: AND language_id = :language_id:", "bind" => ["country_id" => $univer_record->country_id, "language_id" => $lang]])->title;
                $city = \CitiesTranslates::findFirst(["city_id = :city_id: AND language_id = :language_id:", "bind" => ["city_id" => $univer_record->city_id, "language_id" => $lang]])->title;
 
            }
 
            $speciality_dependents = \SpecialityDependend::findBySpecialityId($specialityRecord['id'])->toArray();
 
            $speciality_dependents_ids = $this->getField($speciality_dependents, 'speciality_depend_id');
 
            if ($speciality_dependents_ids && count($speciality_dependents_ids)) {
                $dependents = \FilterTranslates::find([
                    "id IN ({speciality_dependents_ids:array}) AND language_id = :lang:",
                    "bind" => ["speciality_dependents_ids" => $speciality_dependents_ids, "lang" => $lang]]);
            }
 
            $specialArticles = \SpecialtyArticles::findBySpecialtyId($specialityRecord['id'])->toArray();
            $special_articles_ids = $this->getField($specialArticles, 'article_id');
 
            if ($special_articles_ids && count($special_articles_ids)) {
                $special_articles = \ArticleTranslates::find(["article_id IN ({special_articles_ids:array}) AND language_id = :language_id:", "bind" => ["special_articles_ids" => $special_articles_ids, "language_id" => $lang]]);
            }
 
            $specialityRecord['langs'] = implode(', ', $this->getField($langs, 'title'));
            $specialityRecord['faculty'] = $faculty;
            $specialityRecord['required_docs'] = $documents;
            $specialityRecord['jobs'] = $jobs;
            $specialityRecord['subjects'] = $subjects;
            $specialityRecord['univer_logo'] = $univerLogo ?? false;
            $specialityRecord['univer_banner'] = $univerBanner ?? false;
            $specialityRecord['univer_url'] = $univerUrlSuffix;
            $specialityRecord['description'] = \SpecialityDescription::findFirst(["speciality_id = :speciality_id: AND language_id = :language_id:", "bind" => ["speciality_id" => $specialityRecord['id'], "language_id" => $lang]]);
            $specialityRecord['dependents'] = $dependents;
            $specialityRecord['univer_logo_alt'] = $logoAlt;
            $specialityRecord['univer_country'] = $country;
            $specialityRecord['univer_city'] = $city;
            $specialityForCompare = $specialityRecord;
            $specialityForCompare['langs'] = $langs_ids;
        }
 
        $applyFreeServiceId = \ServiceTranslates::findFirstByUrlSuffix('bezkoshtobna-podacha-polsha-vnz')->service_id;
        $applyFreeService = \ServiceTranslates::findFirst(["service_id = :service_id: AND language_id = :language_id:", "bind" => ["service_id" => $applyFreeServiceId, "language_id" => $lang]]);
 
        $this->view->setVars([
            'speciality' => $specialityRecord,
            'meta' => [
                'title' => $specialityRecord['seo_title'],
                'description' => $specialityRecord['seo_description'],
                'keywords' => $specialityRecord['seo_keywords'],
                'cannonical' => $specialityRecord['url_cannonical'],
            ],
            'popularUnivers' => $this->getPopularUniversities($lang),
            'relatedUnivers' => $this->getRelatedUniversities($specialityRecord['country_id'], $specialityRecord['city_id'], $specialityRecord['university_id'], $lang),
            'articles' => $special_articles,
            //'univerGallery' => $univerPhotos,
            'currentCity' => $specialityRecord['city'],
 
            'relatedSpecials' => $this->getRelatedSpecialities($specialityForCompare, $lang),
            'apply_free_service' => $applyFreeService->url_suffix,
        ]);
 
 
        //language titles
        $speciality_translate = \SpecialityTranslates::findBySpecialityId($specialityRecord['id']);
        $this->changeLangViewParams($speciality_translate);
 
        $breadcrumbs = $this->getBaseBreadCrumbs($translates, $lang_code);
 
        $breadcrumbs[] = [
            'pos' => '2',
            'title' => $translates['t_content']->specialty_catalog,
            'url' => '/' . $lang_code . '/specialities'
        ];
 
        $breadcrumbs[] = [
            'pos' => '2',
            'title' => $specialityRecord['title'],
            'url' => '/' . $lang_code . '/specialities/' . $specialityRecord['url_suffix'],
            'last' => true
        ];
 
        $this->view->breadcrumbs = $breadcrumbs;
    }
 
    public function getRelatedSpecialities($speciality, $lang, $limit = 5)
    {
        if (is_array($speciality['langs'])) {
            $where = "language_id IN ({langs_ids:array})";
        } else {
            $where = "language_id = :langs_ids:";
        }
        $speciality_langs = \SpecialityLanguages::find([$where, "bind" => ["langs_ids" => $speciality['langs']]])->toArray();
        $specs_ids = $this->getField($speciality_langs, 'speciality_id');
 
        if ($specs_ids) {
            if (is_array($specs_ids) && count($specs_ids) > 1) {
                $specs_ids_where = "s.id IN ({specs_ids:array})";
            } else {
                $specs_ids_where = "s.id = :specs_ids:";
                $specs_ids = $specs_ids[0];
            }
        }
 
        $bind = [
            'first' => [
                "lang" => $lang,
                "exclude_id" => $speciality['id'],
                "title" => $speciality['title'],
                "study_level" => $speciality['study_level_id'],
                "specs_ids" => $specs_ids,
            ],
            'second' => [
                "lang" => $lang,
                "exclude_id" => $speciality['id'],
                "title" => $speciality['title'],
                "study_level" => $speciality['study_level_id']
            ],
            'third' => [
                "lang" => $lang,
                "exclude_id" => $speciality['id'],
                "science_id" => $speciality['science_id'],
                "study_level" => $speciality['study_level_id'],
                "specs_ids" => $specs_ids,
            ]
        ];
 
        $andWhere = [
            'first' => ["str.title = :title:", "str.study_level_id = :study_level:", $specs_ids_where],
            'second' => ["str.title = :title:", "str.study_level_id = :study_level:"],
            'third' => ["str.science_id = :science_id:", "str.study_level_id = :study_level:", $specs_ids_where]
        ];
 
        /* get specialities with equal title, study_level and languages */
        $relatedSpecials['first'] = $this->getSpecialitiesByQuery($bind['first'], $andWhere['first'], $limit);
 
        /* get specialities with equal title, study_level and different languages */
        if (!isset($relatedSpecials['first']) || count($relatedSpecials['first']) < $limit) {
            $secondLimit = isset($relatedSpecials['first']) ? ($limit - count($relatedSpecials['first'])) : $limit;
 
            $excludeIds = isset($relatedSpecials['first']) ? $this->getField($relatedSpecials['first'], 'id') : false;
            if ($excludeIds) {
                $bind['second']['exclude_items'] = $excludeIds;
                $andWhere['second'][] = "s.id NOT IN ({exclude_items:array})";
            }
 
            $relatedSpecials['second'] = $this->getSpecialitiesByQuery($bind['second'], $andWhere['second'], $secondLimit);
        }
 
        /* get specialities with equal science, study_level and languages */
        if (!isset($relatedSpecials['second']) || count($relatedSpecials['second']) < $secondLimit) {
            $thirdLimit = (isset($relatedSpecials['second'])) ? ($secondLimit - count($relatedSpecials['second'])) : $secondLimit;
 
            if ($excludeIds) {
                if (isset($relatedSpecials['second']) && count($relatedSpecials['second'])) {
                    $excludeIds = array_merge($excludeIds, $this->getField($relatedSpecials['second'], 'id'));
                }
                $bind['third']['exclude_items'] = $excludeIds;
                $andWhere['third'][] = "s.id NOT IN ({exclude_items:array})";
            } else {
                if (isset($relatedSpecials['second']) && count($relatedSpecials['second'])) {
                    $excludeIds = $this->getField($relatedSpecials['second'], 'id');
                    if ($excludeIds) {
                        $bind['third']['exclude_items'] = $excludeIds;
                        $andWhere['third'][] = "s.id NOT IN ({exclude_items:array})";
                    }
                }
            }
 
            $relatedSpecials['third'] = $this->getSpecialitiesByQuery($bind['third'], $andWhere['third'], $thirdLimit);
        }
 
        $relatedSpecials = array_merge($relatedSpecials['first'], $relatedSpecials['second'], $relatedSpecials['third']);
 
        return $relatedSpecials;
    }
 
    public function getSpecialitiesByQuery($bind, $andWhere, $limit)
    {
 
        $relatedSpecials = $this->modelsManager->createBuilder()
            ->addFrom('Specialities', 's')
            ->columns("
                s.id id, s.cost_per_year cost_per_year, str.title title, str.url_suffix as url, utr.title as university, utr.url_suffix as univer_url, cot.title as country, 
                cit.title as city, m.large_url as image, ms.alt as image_alt, ms.title as image_title, ft.title as study_level")
            ->leftjoin('SpecialityTranslates', 'str.speciality_id = s.id AND str.language_id = :lang:', 'str')
            ->leftjoin('UniversityTranslates', 'utr.university_id = s.university_id AND utr.language_id = :lang:', 'utr')
            ->leftjoin('CountriesTranslates', 'cot.country_id = s.country_id AND cot.language_id = :lang:', 'cot')
            ->leftjoin('CitiesTranslates', 'cit.city_id = s.city_id AND cit.language_id = :lang:', 'cit')
            ->leftjoin('Universities', 'u.id = s.university_id', 'u')
            ->leftjoin('Medias', 'm.id = u.banner_image_id', 'm')
            ->leftjoin('MediaSeo', 'ms.media_id = m.id AND ms.language_id = :lang:', 'ms')
            ->leftjoin('FilterTranslates', 'ft.id = str.study_level_id AND ft.language_id = :lang:', 'ft')
            ->where("s.id <> :exclude_id:")
            ->andWhere("s.is_published = 1");
 
        foreach ($andWhere as $value) {
            if ($value) {
                if (strpos($value, ':array}') === false) {
                    $relatedSpecials = $relatedSpecials->andWhere($value);
                } else {
                    preg_match('/({(.*?):array})/', $value, $match);
                    $key = trim(str_replace(":array}", "", $match[1]), "{");
                    if ($key === 'specs_ids') {
                        $relatedSpecials = $relatedSpecials->andWhere("s.id IN (" . implode(',', $bind[$key]) . ")");
                    }
                    if ($key === 'exclude_items') {
                        $relatedSpecials = $relatedSpecials->andWhere("s.id NOT IN (" . implode(',', $bind[$key]) . ")");
                    }
                    //$relatedSpecials = $relatedSpecials->andWhere($value, [$key => $bind[$key]]);
                    unset($bind[$key]);
                }
            }
        }
 
        $limit = ($limit != null) ? $limit : 5;
        $relatedSpecials = $relatedSpecials->limit($limit)
            ->getQuery()
            ->execute($bind)
            ->toArray();
 
        if ($relatedSpecials) {
            foreach ($relatedSpecials as $key => $item) {
                $speciality_langs = \SpecialityLanguages::findBySpecialityId($item['id'])->toArray();
                $langs_ids = $this->getField($speciality_langs, 'language_id');
                if ($langs_ids) {
                    if (count($langs_ids) > 1) {
                        $where = "id IN ({langs_ids:array}) AND language_id = :lang:";
                    } else {
                        $where = "id = :langs_ids: AND language_id = :lang:";
                    }
                    $langs = \FilterTranslates::find([
                        $where,
                        "bind" => ["langs_ids" => $langs_ids, "lang" => $bind['lang']]])->toArray();
                    $relatedSpecials[$key]['study_langs'] = implode(', ', $this->getField($langs, 'title'));
                }
 
            }
        }
 
        return $relatedSpecials;
    }
}
#1Modules\Frontend\Controllers\SpecialityProfileController->getRelatedSpecialities
/var/www/studyforyou.info/apps/modules/frontend/controllers/SpecialityProfileController.php (193)
<?php
 
namespace Modules\Frontend\Controllers;
 
class SpecialityProfileController extends ControllerBase
{
    public function indexAction($speciality)
    {
 
        $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', 'tabs']);
 
        $this->assets->addCss('frontend/dist/css/speciality-profile.css' . $this->disableCache());
        $this->assets->addJs('frontend/js/speciality-profile.js' . $this->disableCache());
        $this->assets->addJs('frontend/js/rating.js' . $this->disableCache());
 
        $specialityRecord = $this->modelsManager->createBuilder()
            ->addFrom('Specialities', 's')
            ->columns("
                s.id id, 
                str.title title, 
                s.cost_per_year cost_per_year, 
                s.cost_per_sem cost_per_sem, 
                s.country_id country_id, 
                s.city_id city_id, 
                cot.title as country, 
                cit.title as city, 
                ft.title as study_level, 
                str.faculty_id faculty_id, 
                str.science_id science_id, 
                s.registration_fee registration_fee, 
                s.registration_end registration_end, 
                s.study_start study_start, 
                s.is_apply_free is_apply_free, 
                utr.title as university, 
                ssd.duration_months as study_duration, 
                str.url_suffix url_suffix, 
                str.seo_title seo_title, 
                str.seo_description seo_description, 
                str.seo_keywords seo_keywords, 
                str.url_cannonical url_cannonical, 
                s.university_id university_id, 
                str.study_level_id study_level_id, 
                sd.job_description job_description, 
                sd.study_description study_description
            ")
            ->leftjoin('UniversityTranslates', 'utr.university_id = s.university_id AND utr.language_id = :lang:', 'utr')
            ->leftjoin('SpecialityTranslates', 'str.speciality_id = s.id AND str.language_id = :lang:', 'str')
            ->leftjoin('SpecialityStudyDurations', 'ssd.speciality_id = s.id', 'ssd')
            ->leftjoin('FilterTranslates', 'ft.id = str.study_level_id AND ft.language_id = :lang:', 'ft')
            ->leftjoin('CountriesTranslates', 'cot.country_id = s.country_id AND cot.language_id = :lang:', 'cot')
            ->leftjoin('CitiesTranslates', 'cit.city_id = s.city_id AND cit.language_id = :lang:', 'cit')
            ->leftjoin('SpecialityDescription', 's.id = sd.speciality_id AND sd.language_id = :lang:', 'sd')
            ->where("str.url_suffix = :speciality:")
            ->andWhere("s.is_published = 1")
            ->getQuery()
            ->getSingleResult(['speciality' => $speciality, 'lang' => $lang]);
 
        if ($specialityRecord) {
            $specialityRecord = $specialityRecord->toArray();
 
            $speciality_langs = \SpecialityLanguages::findBySpecialityId($specialityRecord['id'])->toArray();
 
            $langs_ids = $this->getField($speciality_langs, 'language_id');
 
            if ($langs_ids) {
                if (count($langs_ids) > 1) {
                    $where = "id IN ({langs_ids:array}) AND language_id = :lang:";
                } else {
                    $where = "id = :langs_ids: AND language_id = :lang:";
                    $langs_ids = $langs_ids[0];
                }
                $langs = \FilterTranslates::find([
                    $where,
                    "bind" => ["langs_ids" => $langs_ids, "lang" => $lang]])->toArray();
            }
            $faculty = \FilterTranslates::findFirst(["id = :faculty: AND language_id = :language_id:", "bind" => ["faculty" => $specialityRecord['faculty_id'], "language_id" => $lang]])->title;
 
            $speciality_documents = \SpecialityRequiredDocuments::findBySpecialityId($specialityRecord['id'])->toArray();
 
            $speciality_documents_ids = $this->getField($speciality_documents, 'document_id');
 
            if ($speciality_documents_ids && count($speciality_documents_ids)) {
                $documents = \FilterTranslates::find([
                    "id IN ({speciality_documents_ids:array}) AND language_id = :lang:",
                    "bind" => ["speciality_documents_ids" => $speciality_documents_ids, "lang" => $lang]])->toArray();
                foreach ($speciality_documents as $key => $val) {
                    foreach ($documents as $item => $value) {
                        if ($value['id'] == $val['document_id'])
                            $document[] = $value['title'];
                    }
                }
                $documents = $document;
            }
 
            $speciality_jobs = \SpecialityJobs::findBySpecialityId($specialityRecord['id'])->toArray();
 
            $speciality_jobs_ids = $this->getField($speciality_jobs, 'job_id');
 
            if ($speciality_jobs_ids && count($speciality_jobs_ids))
                $jobs = \FilterTranslates::find([
                    "id IN ({speciality_jobs_ids:array}) AND language_id = :lang:",
                    "bind" => ["speciality_jobs_ids" => $speciality_jobs_ids, "lang" => $lang]]);
 
            $speciality_subjects = \SpecialitySubjects::findBySpecialityId($specialityRecord['id'])->toArray();
 
            foreach ($speciality_subjects as $speciality_subject) {
                $subject_id = $speciality_subject['subject_id'];
                $subjects[] = (object)[
                    'title' => \FilterTranslates::findFirst([
                        'filter_id = :subject_id: AND language_id = :language_id:',
                        'bind' => ['subject_id' => $subject_id, 'language_id' => $lang]
                    ])->title,
                    'duration_hr' => $speciality_subject['duration_hr'],
                    'checkboxes' => $speciality_subject['checkboxes'],
                ];
            }
 
            $specialityRecord['study_start'] = date("d.m.Y", strtotime($specialityRecord['study_start']));
            $specialityRecord['registration_end'] = date("d.m.Y", strtotime($specialityRecord['registration_end']));
 
            $univer_record = \Universities::findFirstById($specialityRecord['university_id']);
            if ($univer_record) {
                if ($univer_record->university_logo_id) {
                    $univerLogo = \Medias::findFirst($univer_record->university_logo_id)->large_url;
                    $logoAlt = \MediaSeo::findFirst(["media_id = :media_id: AND language_id = :language_id:", "bind" => ["media_id" => $univer_record->university_logo_id, "language_id" => $lang]])->alt;
                }
                if ($univer_record->banner_image_id)
                    $univerBanner = \Medias::findFirst($univer_record->banner_image_id)->original_url;
 
                $univerUrlSuffix = \UniversityTranslates::findFirst(["university_id = ?0 AND language_id = ?1", "bind" => [0 => $univer_record->id, 1 => $lang]])->url_suffix;
 
                $country = \CountriesTranslates::findFirst(["country_id = :country_id: AND language_id = :language_id:", "bind" => ["country_id" => $univer_record->country_id, "language_id" => $lang]])->title;
                $city = \CitiesTranslates::findFirst(["city_id = :city_id: AND language_id = :language_id:", "bind" => ["city_id" => $univer_record->city_id, "language_id" => $lang]])->title;
 
            }
 
            $speciality_dependents = \SpecialityDependend::findBySpecialityId($specialityRecord['id'])->toArray();
 
            $speciality_dependents_ids = $this->getField($speciality_dependents, 'speciality_depend_id');
 
            if ($speciality_dependents_ids && count($speciality_dependents_ids)) {
                $dependents = \FilterTranslates::find([
                    "id IN ({speciality_dependents_ids:array}) AND language_id = :lang:",
                    "bind" => ["speciality_dependents_ids" => $speciality_dependents_ids, "lang" => $lang]]);
            }
 
            $specialArticles = \SpecialtyArticles::findBySpecialtyId($specialityRecord['id'])->toArray();
            $special_articles_ids = $this->getField($specialArticles, 'article_id');
 
            if ($special_articles_ids && count($special_articles_ids)) {
                $special_articles = \ArticleTranslates::find(["article_id IN ({special_articles_ids:array}) AND language_id = :language_id:", "bind" => ["special_articles_ids" => $special_articles_ids, "language_id" => $lang]]);
            }
 
            $specialityRecord['langs'] = implode(', ', $this->getField($langs, 'title'));
            $specialityRecord['faculty'] = $faculty;
            $specialityRecord['required_docs'] = $documents;
            $specialityRecord['jobs'] = $jobs;
            $specialityRecord['subjects'] = $subjects;
            $specialityRecord['univer_logo'] = $univerLogo ?? false;
            $specialityRecord['univer_banner'] = $univerBanner ?? false;
            $specialityRecord['univer_url'] = $univerUrlSuffix;
            $specialityRecord['description'] = \SpecialityDescription::findFirst(["speciality_id = :speciality_id: AND language_id = :language_id:", "bind" => ["speciality_id" => $specialityRecord['id'], "language_id" => $lang]]);
            $specialityRecord['dependents'] = $dependents;
            $specialityRecord['univer_logo_alt'] = $logoAlt;
            $specialityRecord['univer_country'] = $country;
            $specialityRecord['univer_city'] = $city;
            $specialityForCompare = $specialityRecord;
            $specialityForCompare['langs'] = $langs_ids;
        }
 
        $applyFreeServiceId = \ServiceTranslates::findFirstByUrlSuffix('bezkoshtobna-podacha-polsha-vnz')->service_id;
        $applyFreeService = \ServiceTranslates::findFirst(["service_id = :service_id: AND language_id = :language_id:", "bind" => ["service_id" => $applyFreeServiceId, "language_id" => $lang]]);
 
        $this->view->setVars([
            'speciality' => $specialityRecord,
            'meta' => [
                'title' => $specialityRecord['seo_title'],
                'description' => $specialityRecord['seo_description'],
                'keywords' => $specialityRecord['seo_keywords'],
                'cannonical' => $specialityRecord['url_cannonical'],
            ],
            'popularUnivers' => $this->getPopularUniversities($lang),
            'relatedUnivers' => $this->getRelatedUniversities($specialityRecord['country_id'], $specialityRecord['city_id'], $specialityRecord['university_id'], $lang),
            'articles' => $special_articles,
            //'univerGallery' => $univerPhotos,
            'currentCity' => $specialityRecord['city'],
 
            'relatedSpecials' => $this->getRelatedSpecialities($specialityForCompare, $lang),
            'apply_free_service' => $applyFreeService->url_suffix,
        ]);
 
 
        //language titles
        $speciality_translate = \SpecialityTranslates::findBySpecialityId($specialityRecord['id']);
        $this->changeLangViewParams($speciality_translate);
 
        $breadcrumbs = $this->getBaseBreadCrumbs($translates, $lang_code);
 
        $breadcrumbs[] = [
            'pos' => '2',
            'title' => $translates['t_content']->specialty_catalog,
            'url' => '/' . $lang_code . '/specialities'
        ];
 
        $breadcrumbs[] = [
            'pos' => '2',
            'title' => $specialityRecord['title'],
            'url' => '/' . $lang_code . '/specialities/' . $specialityRecord['url_suffix'],
            'last' => true
        ];
 
        $this->view->breadcrumbs = $breadcrumbs;
    }
 
    public function getRelatedSpecialities($speciality, $lang, $limit = 5)
    {
        if (is_array($speciality['langs'])) {
            $where = "language_id IN ({langs_ids:array})";
        } else {
            $where = "language_id = :langs_ids:";
        }
        $speciality_langs = \SpecialityLanguages::find([$where, "bind" => ["langs_ids" => $speciality['langs']]])->toArray();
        $specs_ids = $this->getField($speciality_langs, 'speciality_id');
 
        if ($specs_ids) {
            if (is_array($specs_ids) && count($specs_ids) > 1) {
                $specs_ids_where = "s.id IN ({specs_ids:array})";
            } else {
                $specs_ids_where = "s.id = :specs_ids:";
                $specs_ids = $specs_ids[0];
            }
        }
 
        $bind = [
            'first' => [
                "lang" => $lang,
                "exclude_id" => $speciality['id'],
                "title" => $speciality['title'],
                "study_level" => $speciality['study_level_id'],
                "specs_ids" => $specs_ids,
            ],
            'second' => [
                "lang" => $lang,
                "exclude_id" => $speciality['id'],
                "title" => $speciality['title'],
                "study_level" => $speciality['study_level_id']
            ],
            'third' => [
                "lang" => $lang,
                "exclude_id" => $speciality['id'],
                "science_id" => $speciality['science_id'],
                "study_level" => $speciality['study_level_id'],
                "specs_ids" => $specs_ids,
            ]
        ];
 
        $andWhere = [
            'first' => ["str.title = :title:", "str.study_level_id = :study_level:", $specs_ids_where],
            'second' => ["str.title = :title:", "str.study_level_id = :study_level:"],
            'third' => ["str.science_id = :science_id:", "str.study_level_id = :study_level:", $specs_ids_where]
        ];
 
        /* get specialities with equal title, study_level and languages */
        $relatedSpecials['first'] = $this->getSpecialitiesByQuery($bind['first'], $andWhere['first'], $limit);
 
        /* get specialities with equal title, study_level and different languages */
        if (!isset($relatedSpecials['first']) || count($relatedSpecials['first']) < $limit) {
            $secondLimit = isset($relatedSpecials['first']) ? ($limit - count($relatedSpecials['first'])) : $limit;
 
            $excludeIds = isset($relatedSpecials['first']) ? $this->getField($relatedSpecials['first'], 'id') : false;
            if ($excludeIds) {
                $bind['second']['exclude_items'] = $excludeIds;
                $andWhere['second'][] = "s.id NOT IN ({exclude_items:array})";
            }
 
            $relatedSpecials['second'] = $this->getSpecialitiesByQuery($bind['second'], $andWhere['second'], $secondLimit);
        }
 
        /* get specialities with equal science, study_level and languages */
        if (!isset($relatedSpecials['second']) || count($relatedSpecials['second']) < $secondLimit) {
            $thirdLimit = (isset($relatedSpecials['second'])) ? ($secondLimit - count($relatedSpecials['second'])) : $secondLimit;
 
            if ($excludeIds) {
                if (isset($relatedSpecials['second']) && count($relatedSpecials['second'])) {
                    $excludeIds = array_merge($excludeIds, $this->getField($relatedSpecials['second'], 'id'));
                }
                $bind['third']['exclude_items'] = $excludeIds;
                $andWhere['third'][] = "s.id NOT IN ({exclude_items:array})";
            } else {
                if (isset($relatedSpecials['second']) && count($relatedSpecials['second'])) {
                    $excludeIds = $this->getField($relatedSpecials['second'], 'id');
                    if ($excludeIds) {
                        $bind['third']['exclude_items'] = $excludeIds;
                        $andWhere['third'][] = "s.id NOT IN ({exclude_items:array})";
                    }
                }
            }
 
            $relatedSpecials['third'] = $this->getSpecialitiesByQuery($bind['third'], $andWhere['third'], $thirdLimit);
        }
 
        $relatedSpecials = array_merge($relatedSpecials['first'], $relatedSpecials['second'], $relatedSpecials['third']);
 
        return $relatedSpecials;
    }
 
    public function getSpecialitiesByQuery($bind, $andWhere, $limit)
    {
 
        $relatedSpecials = $this->modelsManager->createBuilder()
            ->addFrom('Specialities', 's')
            ->columns("
                s.id id, s.cost_per_year cost_per_year, str.title title, str.url_suffix as url, utr.title as university, utr.url_suffix as univer_url, cot.title as country, 
                cit.title as city, m.large_url as image, ms.alt as image_alt, ms.title as image_title, ft.title as study_level")
            ->leftjoin('SpecialityTranslates', 'str.speciality_id = s.id AND str.language_id = :lang:', 'str')
            ->leftjoin('UniversityTranslates', 'utr.university_id = s.university_id AND utr.language_id = :lang:', 'utr')
            ->leftjoin('CountriesTranslates', 'cot.country_id = s.country_id AND cot.language_id = :lang:', 'cot')
            ->leftjoin('CitiesTranslates', 'cit.city_id = s.city_id AND cit.language_id = :lang:', 'cit')
            ->leftjoin('Universities', 'u.id = s.university_id', 'u')
            ->leftjoin('Medias', 'm.id = u.banner_image_id', 'm')
            ->leftjoin('MediaSeo', 'ms.media_id = m.id AND ms.language_id = :lang:', 'ms')
            ->leftjoin('FilterTranslates', 'ft.id = str.study_level_id AND ft.language_id = :lang:', 'ft')
            ->where("s.id <> :exclude_id:")
            ->andWhere("s.is_published = 1");
 
        foreach ($andWhere as $value) {
            if ($value) {
                if (strpos($value, ':array}') === false) {
                    $relatedSpecials = $relatedSpecials->andWhere($value);
                } else {
                    preg_match('/({(.*?):array})/', $value, $match);
                    $key = trim(str_replace(":array}", "", $match[1]), "{");
                    if ($key === 'specs_ids') {
                        $relatedSpecials = $relatedSpecials->andWhere("s.id IN (" . implode(',', $bind[$key]) . ")");
                    }
                    if ($key === 'exclude_items') {
                        $relatedSpecials = $relatedSpecials->andWhere("s.id NOT IN (" . implode(',', $bind[$key]) . ")");
                    }
                    //$relatedSpecials = $relatedSpecials->andWhere($value, [$key => $bind[$key]]);
                    unset($bind[$key]);
                }
            }
        }
 
        $limit = ($limit != null) ? $limit : 5;
        $relatedSpecials = $relatedSpecials->limit($limit)
            ->getQuery()
            ->execute($bind)
            ->toArray();
 
        if ($relatedSpecials) {
            foreach ($relatedSpecials as $key => $item) {
                $speciality_langs = \SpecialityLanguages::findBySpecialityId($item['id'])->toArray();
                $langs_ids = $this->getField($speciality_langs, 'language_id');
                if ($langs_ids) {
                    if (count($langs_ids) > 1) {
                        $where = "id IN ({langs_ids:array}) AND language_id = :lang:";
                    } else {
                        $where = "id = :langs_ids: AND language_id = :lang:";
                    }
                    $langs = \FilterTranslates::find([
                        $where,
                        "bind" => ["langs_ids" => $langs_ids, "lang" => $bind['lang']]])->toArray();
                    $relatedSpecials[$key]['study_langs'] = implode(', ', $this->getField($langs, 'title'));
                }
 
            }
        }
 
        return $relatedSpecials;
    }
}
#2Modules\Frontend\Controllers\SpecialityProfileController->indexAction
#3Phalcon\Dispatcher\AbstractDispatcher->callActionMethod
#4Phalcon\Dispatcher\AbstractDispatcher->dispatch
#5Phalcon\Mvc\Application->handle
/var/www/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/en/specialities/politology-bs-mcsu-lublin
KeyValue
USERwww-data
HOME/var/www
HTTP_HOSTstudyforyou.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/studyforyou.info/public/index.php
PATH_INFO
REDIRECT_STATUS200
SERVER_NAMEstudyforyou.info
SERVER_PORT443
SERVER_ADDR54.37.235.116
REMOTE_PORT14368
REMOTE_ADDR13.59.58.68
SERVER_SOFTWAREnginx/1.18.0
GATEWAY_INTERFACECGI/1.1
HTTPSon
REQUEST_SCHEMEhttps
SERVER_PROTOCOLHTTP/1.1
DOCUMENT_ROOT/var/www/studyforyou.info/public
DOCUMENT_URI/index.php
REQUEST_URI/en/specialities/politology-bs-mcsu-lublin
SCRIPT_NAME/index.php
CONTENT_LENGTH
CONTENT_TYPE
REQUEST_METHODGET
QUERY_STRING_url=/en/specialities/politology-bs-mcsu-lublin&
FCGI_ROLERESPONDER
PHP_SELF/index.php
REQUEST_TIME_FLOAT1735580666.0574
REQUEST_TIME1735580666
SITE_URLhttps://studyforyou.info
DATABASE_HOSTlocalhost
USERNAMEsfy_database
PASSWORDe234rwdf33123
DBNAMEsfy
LOG_IN_DBfalse
IMAGEPATH/var/www/data/images/
#Path
0/var/www/studyforyou.info/public/index.php
1/var/www/studyforyou.info/vendor/autoload.php
2/var/www/studyforyou.info/vendor/composer/autoload_real.php
3/var/www/studyforyou.info/vendor/composer/platform_check.php
4/var/www/studyforyou.info/vendor/composer/ClassLoader.php
5/var/www/studyforyou.info/vendor/composer/autoload_static.php
6/var/www/studyforyou.info/vendor/symfony/polyfill-ctype/bootstrap.php
7/var/www/studyforyou.info/vendor/symfony/polyfill-ctype/bootstrap80.php
8/var/www/studyforyou.info/vendor/symfony/polyfill-mbstring/bootstrap.php
9/var/www/studyforyou.info/vendor/symfony/polyfill-mbstring/bootstrap80.php
10/var/www/studyforyou.info/vendor/cakephp/core/functions.php
11/var/www/studyforyou.info/vendor/cakephp/core/functions_global.php
12/var/www/studyforyou.info/vendor/symfony/deprecation-contracts/function.php
13/var/www/studyforyou.info/vendor/symfony/polyfill-intl-grapheme/bootstrap.php
14/var/www/studyforyou.info/vendor/symfony/polyfill-intl-grapheme/bootstrap80.php
15/var/www/studyforyou.info/vendor/symfony/polyfill-intl-normalizer/bootstrap.php
16/var/www/studyforyou.info/vendor/symfony/polyfill-intl-normalizer/bootstrap80.php
17/var/www/studyforyou.info/vendor/symfony/string/Resources/functions.php
18/var/www/studyforyou.info/vendor/cakephp/utility/bootstrap.php
19/var/www/studyforyou.info/vendor/cakephp/utility/Inflector.php
20/var/www/studyforyou.info/vendor/symfony/polyfill-php80/bootstrap.php
21/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Dotenv.php
22/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/RepositoryBuilder.php
23/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/ServerConstAdapter.php
24/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/AdapterInterface.php
25/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/ReaderInterface.php
26/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/WriterInterface.php
27/var/www/studyforyou.info/vendor/phpoption/phpoption/src/PhpOption/Some.php
28/var/www/studyforyou.info/vendor/phpoption/phpoption/src/PhpOption/Option.php
29/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/EnvConstAdapter.php
30/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiReader.php
31/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiWriter.php
32/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/Adapter/ImmutableWriter.php
33/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/AdapterRepository.php
34/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Repository/RepositoryInterface.php
35/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php
36/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Store/FileStore.php
37/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Store/StoreInterface.php
38/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Store/File/Paths.php
39/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/Parser.php
40/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/ParserInterface.php
41/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Loader/Loader.php
42/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Loader/LoaderInterface.php
43/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Store/File/Reader.php
44/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Util/Str.php
45/var/www/studyforyou.info/vendor/symfony/polyfill-mbstring/Mbstring.php
46/var/www/studyforyou.info/vendor/graham-campbell/result-type/src/Success.php
47/var/www/studyforyou.info/vendor/graham-campbell/result-type/src/Result.php
48/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Util/Regex.php
49/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/Lines.php
50/var/www/studyforyou.info/vendor/phpoption/phpoption/src/PhpOption/None.php
51/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/EntryParser.php
52/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/Lexer.php
53/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/Value.php
54/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Parser/Entry.php
55/var/www/studyforyou.info/vendor/vlucas/phpdotenv/src/Loader/Resolver.php
56/var/www/studyforyou.info/apps/config/config.php
57/var/www/studyforyou.info/vendor/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php
58/var/www/studyforyou.info/apps/config/services.php
59/var/www/studyforyou.info/apps/config/routers.php
60/var/www/studyforyou.info/apps/config/modules.php
61/var/www/studyforyou.info/apps/config/routesAdmin.php
62/var/www/studyforyou.info/apps/config/routesFrontend.php
63/var/www/studyforyou.info/apps/modules/frontend/Module.php
64/var/www/studyforyou.info/apps/modules/frontend/controllers/SpecialityProfileController.php
65/var/www/studyforyou.info/apps/modules/frontend/controllers/ControllerBase.php
66/var/www/studyforyou.info/apps/modules/frontend/controllers/AuthController.php
67/var/www/studyforyou.info/apps/models/Languages.php
68/var/www/studyforyou.info/apps/models/FilterTranslates.php
69/var/www/studyforyou.info/apps/models/ArticleTranslates.php
70/var/www/studyforyou.info/apps/models/Strings.php
71/var/www/studyforyou.info/apps/models/StringsTranslates.php
72/var/www/studyforyou.info/apps/models/CountriesTranslates.php
73/var/www/studyforyou.info/apps/models/Filters.php
74/var/www/studyforyou.info/apps/models/CitiesTranslates.php
75/var/www/studyforyou.info/apps/models/Specialities.php
76/var/www/studyforyou.info/apps/models/UniversityTranslates.php
77/var/www/studyforyou.info/apps/models/SpecialityTranslates.php
78/var/www/studyforyou.info/apps/models/SpecialityStudyDurations.php
79/var/www/studyforyou.info/apps/models/SpecialityDescription.php
80/var/www/studyforyou.info/apps/models/SpecialityLanguages.php
81/var/www/studyforyou.info/apps/models/SpecialityRequiredDocuments.php
82/var/www/studyforyou.info/apps/models/SpecialityJobs.php
83/var/www/studyforyou.info/apps/models/SpecialitySubjects.php
84/var/www/studyforyou.info/apps/models/Universities.php
85/var/www/studyforyou.info/apps/models/Medias.php
86/var/www/studyforyou.info/apps/models/MediaSeo.php
87/var/www/studyforyou.info/apps/models/SpecialityDependend.php
88/var/www/studyforyou.info/apps/models/SpecialtyArticles.php
89/var/www/studyforyou.info/apps/models/ServiceTranslates.php
90/var/www/studyforyou.info/apps/models/Countries.php
Memory
Usage12582912