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)
  1. <?php
  2.  
  3. namespace Modules\Frontend\Controllers;
  4.  
  5. class SpecialityProfileController extends ControllerBase
  6. {
  7. public function indexAction($speciality)
  8. {
  9.  
  10. $lang_code = $this->language;
  11. $languagesModel = new \Languages();
  12. $lang = $languagesModel::findFirstByCode($lang_code)->id;
  13.  
  14. //second param is filters you want use
  15. $translates = $this->setViewTranslates($lang, ['menu', 'header', 'filters', 'footer', 'content', 'tabs']);
  16.  
  17. $this->assets->addCss('frontend/dist/css/speciality-profile.css' . $this->disableCache());
  18. $this->assets->addJs('frontend/js/speciality-profile.js' . $this->disableCache());
  19. $this->assets->addJs('frontend/js/rating.js' . $this->disableCache());
  20.  
  21. $specialityRecord = $this->modelsManager->createBuilder()
  22. ->addFrom('Specialities', 's')
  23. ->columns("
  24. s.id id,
  25. str.title title,
  26. s.cost_per_year cost_per_year,
  27. s.cost_per_sem cost_per_sem,
  28. s.country_id country_id,
  29. s.city_id city_id,
  30. cot.title as country,
  31. cit.title as city,
  32. ft.title as study_level,
  33. str.faculty_id faculty_id,
  34. str.science_id science_id,
  35. s.registration_fee registration_fee,
  36. s.registration_end registration_end,
  37. s.study_start study_start,
  38. s.is_apply_free is_apply_free,
  39. utr.title as university,
  40. ssd.duration_months as study_duration,
  41. str.url_suffix url_suffix,
  42. str.seo_title seo_title,
  43. str.seo_description seo_description,
  44. str.seo_keywords seo_keywords,
  45. str.url_cannonical url_cannonical,
  46. s.university_id university_id,
  47. str.study_level_id study_level_id,
  48. sd.job_description job_description,
  49. sd.study_description study_description
  50. ")
  51. ->leftjoin('UniversityTranslates', 'utr.university_id = s.university_id AND utr.language_id = :lang:', 'utr')
  52. ->leftjoin('SpecialityTranslates', 'str.speciality_id = s.id AND str.language_id = :lang:', 'str')
  53. ->leftjoin('SpecialityStudyDurations', 'ssd.speciality_id = s.id', 'ssd')
  54. ->leftjoin('FilterTranslates', 'ft.id = str.study_level_id AND ft.language_id = :lang:', 'ft')
  55. ->leftjoin('CountriesTranslates', 'cot.country_id = s.country_id AND cot.language_id = :lang:', 'cot')
  56. ->leftjoin('CitiesTranslates', 'cit.city_id = s.city_id AND cit.language_id = :lang:', 'cit')
  57. ->leftjoin('SpecialityDescription', 's.id = sd.speciality_id AND sd.language_id = :lang:', 'sd')
  58. ->where("str.url_suffix = :speciality:")
  59. ->andWhere("s.is_published = 1")
  60. ->getQuery()
  61. ->getSingleResult(['speciality' => $speciality, 'lang' => $lang]);
  62.  
  63. if ($specialityRecord) {
  64. $specialityRecord = $specialityRecord->toArray();
  65.  
  66. $speciality_langs = \SpecialityLanguages::findBySpecialityId($specialityRecord['id'])->toArray();
  67.  
  68. $langs_ids = $this->getField($speciality_langs, 'language_id');
  69.  
  70. if ($langs_ids) {
  71. if (count($langs_ids) > 1) {
  72. $where = "id IN ({langs_ids:array}) AND language_id = :lang:";
  73. } else {
  74. $where = "id = :langs_ids: AND language_id = :lang:";
  75. $langs_ids = $langs_ids[0];
  76. }
  77. $langs = \FilterTranslates::find([
  78. $where,
  79. "bind" => ["langs_ids" => $langs_ids, "lang" => $lang]])->toArray();
  80. }
  81. $faculty = \FilterTranslates::findFirst(["id = :faculty: AND language_id = :language_id:", "bind" => ["faculty" => $specialityRecord['faculty_id'], "language_id" => $lang]])->title;
  82.  
  83. $speciality_documents = \SpecialityRequiredDocuments::findBySpecialityId($specialityRecord['id'])->toArray();
  84.  
  85. $speciality_documents_ids = $this->getField($speciality_documents, 'document_id');
  86.  
  87. if ($speciality_documents_ids && count($speciality_documents_ids)) {
  88. $documents = \FilterTranslates::find([
  89. "id IN ({speciality_documents_ids:array}) AND language_id = :lang:",
  90. "bind" => ["speciality_documents_ids" => $speciality_documents_ids, "lang" => $lang]])->toArray();
  91. foreach ($speciality_documents as $key => $val) {
  92. foreach ($documents as $item => $value) {
  93. if ($value['id'] == $val['document_id'])
  94. $document[] = $value['title'];
  95. }
  96. }
  97. $documents = $document;
  98. }
  99.  
  100. $speciality_jobs = \SpecialityJobs::findBySpecialityId($specialityRecord['id'])->toArray();
  101.  
  102. $speciality_jobs_ids = $this->getField($speciality_jobs, 'job_id');
  103.  
  104. if ($speciality_jobs_ids && count($speciality_jobs_ids))
  105. $jobs = \FilterTranslates::find([
  106. "id IN ({speciality_jobs_ids:array}) AND language_id = :lang:",
  107. "bind" => ["speciality_jobs_ids" => $speciality_jobs_ids, "lang" => $lang]]);
  108.  
  109. $speciality_subjects = \SpecialitySubjects::findBySpecialityId($specialityRecord['id'])->toArray();
  110.  
  111. foreach ($speciality_subjects as $speciality_subject) {
  112. $subject_id = $speciality_subject['subject_id'];
  113. $subjects[] = (object)[
  114. 'title' => \FilterTranslates::findFirst([
  115. 'filter_id = :subject_id: AND language_id = :language_id:',
  116. 'bind' => ['subject_id' => $subject_id, 'language_id' => $lang]
  117. ])->title,
  118. 'duration_hr' => $speciality_subject['duration_hr'],
  119. 'checkboxes' => $speciality_subject['checkboxes'],
  120. ];
  121. }
  122.  
  123. $specialityRecord['study_start'] = date("d.m.Y", strtotime($specialityRecord['study_start']));
  124. $specialityRecord['registration_end'] = date("d.m.Y", strtotime($specialityRecord['registration_end']));
  125.  
  126. $univer_record = \Universities::findFirstById($specialityRecord['university_id']);
  127. if ($univer_record) {
  128. if ($univer_record->university_logo_id) {
  129. $univerLogo = \Medias::findFirst($univer_record->university_logo_id)->large_url;
  130. $logoAlt = \MediaSeo::findFirst(["media_id = :media_id: AND language_id = :language_id:", "bind" => ["media_id" => $univer_record->university_logo_id, "language_id" => $lang]])->alt;
  131. }
  132. if ($univer_record->banner_image_id)
  133. $univerBanner = \Medias::findFirst($univer_record->banner_image_id)->original_url;
  134.  
  135. $univerUrlSuffix = \UniversityTranslates::findFirst(["university_id = ?0 AND language_id = ?1", "bind" => [0 => $univer_record->id, 1 => $lang]])->url_suffix;
  136.  
  137. $country = \CountriesTranslates::findFirst(["country_id = :country_id: AND language_id = :language_id:", "bind" => ["country_id" => $univer_record->country_id, "language_id" => $lang]])->title;
  138. $city = \CitiesTranslates::findFirst(["city_id = :city_id: AND language_id = :language_id:", "bind" => ["city_id" => $univer_record->city_id, "language_id" => $lang]])->title;
  139.  
  140. }
  141.  
  142. $speciality_dependents = \SpecialityDependend::findBySpecialityId($specialityRecord['id'])->toArray();
  143.  
  144. $speciality_dependents_ids = $this->getField($speciality_dependents, 'speciality_depend_id');
  145.  
  146. if ($speciality_dependents_ids && count($speciality_dependents_ids)) {
  147. $dependents = \FilterTranslates::find([
  148. "id IN ({speciality_dependents_ids:array}) AND language_id = :lang:",
  149. "bind" => ["speciality_dependents_ids" => $speciality_dependents_ids, "lang" => $lang]]);
  150. }
  151.  
  152. $specialArticles = \SpecialtyArticles::findBySpecialtyId($specialityRecord['id'])->toArray();
  153. $special_articles_ids = $this->getField($specialArticles, 'article_id');
  154.  
  155. if ($special_articles_ids && count($special_articles_ids)) {
  156. $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]]);
  157. }
  158.  
  159. $specialityRecord['langs'] = implode(', ', $this->getField($langs, 'title'));
  160. $specialityRecord['faculty'] = $faculty;
  161. $specialityRecord['required_docs'] = $documents;
  162. $specialityRecord['jobs'] = $jobs;
  163. $specialityRecord['subjects'] = $subjects;
  164. $specialityRecord['univer_logo'] = $univerLogo ?? false;
  165. $specialityRecord['univer_banner'] = $univerBanner ?? false;
  166. $specialityRecord['univer_url'] = $univerUrlSuffix;
  167. $specialityRecord['description'] = \SpecialityDescription::findFirst(["speciality_id = :speciality_id: AND language_id = :language_id:", "bind" => ["speciality_id" => $specialityRecord['id'], "language_id" => $lang]]);
  168. $specialityRecord['dependents'] = $dependents;
  169. $specialityRecord['univer_logo_alt'] = $logoAlt;
  170. $specialityRecord['univer_country'] = $country;
  171. $specialityRecord['univer_city'] = $city;
  172. $specialityForCompare = $specialityRecord;
  173. $specialityForCompare['langs'] = $langs_ids;
  174. }
  175.  
  176. $applyFreeServiceId = \ServiceTranslates::findFirstByUrlSuffix('bezkoshtobna-podacha-polsha-vnz')->service_id;
  177. $applyFreeService = \ServiceTranslates::findFirst(["service_id = :service_id: AND language_id = :language_id:", "bind" => ["service_id" => $applyFreeServiceId, "language_id" => $lang]]);
  178.  
  179. $this->view->setVars([
  180. 'speciality' => $specialityRecord,
  181. 'meta' => [
  182. 'title' => $specialityRecord['seo_title'],
  183. 'description' => $specialityRecord['seo_description'],
  184. 'keywords' => $specialityRecord['seo_keywords'],
  185. 'cannonical' => $specialityRecord['url_cannonical'],
  186. ],
  187. 'popularUnivers' => $this->getPopularUniversities($lang),
  188. 'relatedUnivers' => $this->getRelatedUniversities($specialityRecord['country_id'], $specialityRecord['city_id'], $specialityRecord['university_id'], $lang),
  189. 'articles' => $special_articles,
  190. //'univerGallery' => $univerPhotos,
  191. 'currentCity' => $specialityRecord['city'],
  192.  
  193. 'relatedSpecials' => $this->getRelatedSpecialities($specialityForCompare, $lang),
  194. 'apply_free_service' => $applyFreeService->url_suffix,
  195. ]);
  196.  
  197.  
  198. //language titles
  199. $speciality_translate = \SpecialityTranslates::findBySpecialityId($specialityRecord['id']);
  200. $this->changeLangViewParams($speciality_translate);
  201.  
  202. $breadcrumbs = $this->getBaseBreadCrumbs($translates, $lang_code);
  203.  
  204. $breadcrumbs[] = [
  205. 'pos' => '2',
  206. 'title' => $translates['t_content']->specialty_catalog,
  207. 'url' => '/' . $lang_code . '/specialities'
  208. ];
  209.  
  210. $breadcrumbs[] = [
  211. 'pos' => '2',
  212. 'title' => $specialityRecord['title'],
  213. 'url' => '/' . $lang_code . '/specialities/' . $specialityRecord['url_suffix'],
  214. 'last' => true
  215. ];
  216.  
  217. $this->view->breadcrumbs = $breadcrumbs;
  218. }
  219.  
  220. public function getRelatedSpecialities($speciality, $lang, $limit = 5)
  221. {
  222. if (is_array($speciality['langs'])) {
  223. $where = "language_id IN ({langs_ids:array})";
  224. } else {
  225. $where = "language_id = :langs_ids:";
  226. }
  227. $speciality_langs = \SpecialityLanguages::find([$where, "bind" => ["langs_ids" => $speciality['langs']]])->toArray();
  228. $specs_ids = $this->getField($speciality_langs, 'speciality_id');
  229.  
  230. if ($specs_ids) {
  231. if (is_array($specs_ids) && count($specs_ids) > 1) {
  232. $specs_ids_where = "s.id IN ({specs_ids:array})";
  233. } else {
  234. $specs_ids_where = "s.id = :specs_ids:";
  235. $specs_ids = $specs_ids[0];
  236. }
  237. }
  238.  
  239. $bind = [
  240. 'first' => [
  241. "lang" => $lang,
  242. "exclude_id" => $speciality['id'],
  243. "title" => $speciality['title'],
  244. "study_level" => $speciality['study_level_id'],
  245. "specs_ids" => $specs_ids,
  246. ],
  247. 'second' => [
  248. "lang" => $lang,
  249. "exclude_id" => $speciality['id'],
  250. "title" => $speciality['title'],
  251. "study_level" => $speciality['study_level_id']
  252. ],
  253. 'third' => [
  254. "lang" => $lang,
  255. "exclude_id" => $speciality['id'],
  256. "science_id" => $speciality['science_id'],
  257. "study_level" => $speciality['study_level_id'],
  258. "specs_ids" => $specs_ids,
  259. ]
  260. ];
  261.  
  262. $andWhere = [
  263. 'first' => ["str.title = :title:", "str.study_level_id = :study_level:", $specs_ids_where],
  264. 'second' => ["str.title = :title:", "str.study_level_id = :study_level:"],
  265. 'third' => ["str.science_id = :science_id:", "str.study_level_id = :study_level:", $specs_ids_where]
  266. ];
  267.  
  268. /* get specialities with equal title, study_level and languages */
  269. $relatedSpecials['first'] = $this->getSpecialitiesByQuery($bind['first'], $andWhere['first'], $limit);
  270.  
  271. /* get specialities with equal title, study_level and different languages */
  272. if (!isset($relatedSpecials['first']) || count($relatedSpecials['first']) < $limit) {
  273. $secondLimit = isset($relatedSpecials['first']) ? ($limit - count($relatedSpecials['first'])) : $limit;
  274.  
  275. $excludeIds = isset($relatedSpecials['first']) ? $this->getField($relatedSpecials['first'], 'id') : false;
  276. if ($excludeIds) {
  277. $bind['second']['exclude_items'] = $excludeIds;
  278. $andWhere['second'][] = "s.id NOT IN ({exclude_items:array})";
  279. }
  280.  
  281. $relatedSpecials['second'] = $this->getSpecialitiesByQuery($bind['second'], $andWhere['second'], $secondLimit);
  282. }
  283.  
  284. /* get specialities with equal science, study_level and languages */
  285. if (!isset($relatedSpecials['second']) || count($relatedSpecials['second']) < $secondLimit) {
  286. $thirdLimit = (isset($relatedSpecials['second'])) ? ($secondLimit - count($relatedSpecials['second'])) : $secondLimit;
  287.  
  288. if ($excludeIds) {
  289. if (isset($relatedSpecials['second']) && count($relatedSpecials['second'])) {
  290. $excludeIds = array_merge($excludeIds, $this->getField($relatedSpecials['second'], 'id'));
  291. }
  292. $bind['third']['exclude_items'] = $excludeIds;
  293. $andWhere['third'][] = "s.id NOT IN ({exclude_items:array})";
  294. } else {
  295. if (isset($relatedSpecials['second']) && count($relatedSpecials['second'])) {
  296. $excludeIds = $this->getField($relatedSpecials['second'], 'id');
  297. if ($excludeIds) {
  298. $bind['third']['exclude_items'] = $excludeIds;
  299. $andWhere['third'][] = "s.id NOT IN ({exclude_items:array})";
  300. }
  301. }
  302. }
  303.  
  304. $relatedSpecials['third'] = $this->getSpecialitiesByQuery($bind['third'], $andWhere['third'], $thirdLimit);
  305. }
  306.  
  307. $relatedSpecials = array_merge($relatedSpecials['first'], $relatedSpecials['second'], $relatedSpecials['third']);
  308.  
  309. return $relatedSpecials;
  310. }
  311.  
  312. public function getSpecialitiesByQuery($bind, $andWhere, $limit)
  313. {
  314.  
  315. $relatedSpecials = $this->modelsManager->createBuilder()
  316. ->addFrom('Specialities', 's')
  317. ->columns("
  318. 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,
  319. cit.title as city, m.large_url as image, ms.alt as image_alt, ms.title as image_title, ft.title as study_level")
  320. ->leftjoin('SpecialityTranslates', 'str.speciality_id = s.id AND str.language_id = :lang:', 'str')
  321. ->leftjoin('UniversityTranslates', 'utr.university_id = s.university_id AND utr.language_id = :lang:', 'utr')
  322. ->leftjoin('CountriesTranslates', 'cot.country_id = s.country_id AND cot.language_id = :lang:', 'cot')
  323. ->leftjoin('CitiesTranslates', 'cit.city_id = s.city_id AND cit.language_id = :lang:', 'cit')
  324. ->leftjoin('Universities', 'u.id = s.university_id', 'u')
  325. ->leftjoin('Medias', 'm.id = u.banner_image_id', 'm')
  326. ->leftjoin('MediaSeo', 'ms.media_id = m.id AND ms.language_id = :lang:', 'ms')
  327. ->leftjoin('FilterTranslates', 'ft.id = str.study_level_id AND ft.language_id = :lang:', 'ft')
  328. ->where("s.id <> :exclude_id:")
  329. ->andWhere("s.is_published = 1");
  330.  
  331. foreach ($andWhere as $value) {
  332. if ($value) {
  333. if (strpos($value, ':array}') === false) {
  334. $relatedSpecials = $relatedSpecials->andWhere($value);
  335. } else {
  336. preg_match('/({(.*?):array})/', $value, $match);
  337. $key = trim(str_replace(":array}", "", $match[1]), "{");
  338. if ($key === 'specs_ids') {
  339. $relatedSpecials = $relatedSpecials->andWhere("s.id IN (" . implode(',', $bind[$key]) . ")");
  340. }
  341. if ($key === 'exclude_items') {
  342. $relatedSpecials = $relatedSpecials->andWhere("s.id NOT IN (" . implode(',', $bind[$key]) . ")");
  343. }
  344. //$relatedSpecials = $relatedSpecials->andWhere($value, [$key => $bind[$key]]);
  345. unset($bind[$key]);
  346. }
  347. }
  348. }
  349.  
  350. $limit = ($limit != null) ? $limit : 5;
  351. $relatedSpecials = $relatedSpecials->limit($limit)
  352. ->getQuery()
  353. ->execute($bind)
  354. ->toArray();
  355.  
  356. if ($relatedSpecials) {
  357. foreach ($relatedSpecials as $key => $item) {
  358. $speciality_langs = \SpecialityLanguages::findBySpecialityId($item['id'])->toArray();
  359. $langs_ids = $this->getField($speciality_langs, 'language_id');
  360. if ($langs_ids) {
  361. if (count($langs_ids) > 1) {
  362. $where = "id IN ({langs_ids:array}) AND language_id = :lang:";
  363. } else {
  364. $where = "id = :langs_ids: AND language_id = :lang:";
  365. }
  366. $langs = \FilterTranslates::find([
  367. $where,
  368. "bind" => ["langs_ids" => $langs_ids, "lang" => $bind['lang']]])->toArray();
  369. $relatedSpecials[$key]['study_langs'] = implode(', ', $this->getField($langs, 'title'));
  370. }
  371.  
  372. }
  373. }
  374.  
  375. return $relatedSpecials;
  376. }
  377. }
#1Modules\Frontend\Controllers\SpecialityProfileController->getRelatedSpecialities
/var/www/studyforyou.info/apps/modules/frontend/controllers/SpecialityProfileController.php (193)
  1. <?php
  2.  
  3. namespace Modules\Frontend\Controllers;
  4.  
  5. class SpecialityProfileController extends ControllerBase
  6. {
  7. public function indexAction($speciality)
  8. {
  9.  
  10. $lang_code = $this->language;
  11. $languagesModel = new \Languages();
  12. $lang = $languagesModel::findFirstByCode($lang_code)->id;
  13.  
  14. //second param is filters you want use
  15. $translates = $this->setViewTranslates($lang, ['menu', 'header', 'filters', 'footer', 'content', 'tabs']);
  16.  
  17. $this->assets->addCss('frontend/dist/css/speciality-profile.css' . $this->disableCache());
  18. $this->assets->addJs('frontend/js/speciality-profile.js' . $this->disableCache());
  19. $this->assets->addJs('frontend/js/rating.js' . $this->disableCache());
  20.  
  21. $specialityRecord = $this->modelsManager->createBuilder()
  22. ->addFrom('Specialities', 's')
  23. ->columns("
  24. s.id id,
  25. str.title title,
  26. s.cost_per_year cost_per_year,
  27. s.cost_per_sem cost_per_sem,
  28. s.country_id country_id,
  29. s.city_id city_id,
  30. cot.title as country,
  31. cit.title as city,
  32. ft.title as study_level,
  33. str.faculty_id faculty_id,
  34. str.science_id science_id,
  35. s.registration_fee registration_fee,
  36. s.registration_end registration_end,
  37. s.study_start study_start,
  38. s.is_apply_free is_apply_free,
  39. utr.title as university,
  40. ssd.duration_months as study_duration,
  41. str.url_suffix url_suffix,
  42. str.seo_title seo_title,
  43. str.seo_description seo_description,
  44. str.seo_keywords seo_keywords,
  45. str.url_cannonical url_cannonical,
  46. s.university_id university_id,
  47. str.study_level_id study_level_id,
  48. sd.job_description job_description,
  49. sd.study_description study_description
  50. ")
  51. ->leftjoin('UniversityTranslates', 'utr.university_id = s.university_id AND utr.language_id = :lang:', 'utr')
  52. ->leftjoin('SpecialityTranslates', 'str.speciality_id = s.id AND str.language_id = :lang:', 'str')
  53. ->leftjoin('SpecialityStudyDurations', 'ssd.speciality_id = s.id', 'ssd')
  54. ->leftjoin('FilterTranslates', 'ft.id = str.study_level_id AND ft.language_id = :lang:', 'ft')
  55. ->leftjoin('CountriesTranslates', 'cot.country_id = s.country_id AND cot.language_id = :lang:', 'cot')
  56. ->leftjoin('CitiesTranslates', 'cit.city_id = s.city_id AND cit.language_id = :lang:', 'cit')
  57. ->leftjoin('SpecialityDescription', 's.id = sd.speciality_id AND sd.language_id = :lang:', 'sd')
  58. ->where("str.url_suffix = :speciality:")
  59. ->andWhere("s.is_published = 1")
  60. ->getQuery()
  61. ->getSingleResult(['speciality' => $speciality, 'lang' => $lang]);
  62.  
  63. if ($specialityRecord) {
  64. $specialityRecord = $specialityRecord->toArray();
  65.  
  66. $speciality_langs = \SpecialityLanguages::findBySpecialityId($specialityRecord['id'])->toArray();
  67.  
  68. $langs_ids = $this->getField($speciality_langs, 'language_id');
  69.  
  70. if ($langs_ids) {
  71. if (count($langs_ids) > 1) {
  72. $where = "id IN ({langs_ids:array}) AND language_id = :lang:";
  73. } else {
  74. $where = "id = :langs_ids: AND language_id = :lang:";
  75. $langs_ids = $langs_ids[0];
  76. }
  77. $langs = \FilterTranslates::find([
  78. $where,
  79. "bind" => ["langs_ids" => $langs_ids, "lang" => $lang]])->toArray();
  80. }
  81. $faculty = \FilterTranslates::findFirst(["id = :faculty: AND language_id = :language_id:", "bind" => ["faculty" => $specialityRecord['faculty_id'], "language_id" => $lang]])->title;
  82.  
  83. $speciality_documents = \SpecialityRequiredDocuments::findBySpecialityId($specialityRecord['id'])->toArray();
  84.  
  85. $speciality_documents_ids = $this->getField($speciality_documents, 'document_id');
  86.  
  87. if ($speciality_documents_ids && count($speciality_documents_ids)) {
  88. $documents = \FilterTranslates::find([
  89. "id IN ({speciality_documents_ids:array}) AND language_id = :lang:",
  90. "bind" => ["speciality_documents_ids" => $speciality_documents_ids, "lang" => $lang]])->toArray();
  91. foreach ($speciality_documents as $key => $val) {
  92. foreach ($documents as $item => $value) {
  93. if ($value['id'] == $val['document_id'])
  94. $document[] = $value['title'];
  95. }
  96. }
  97. $documents = $document;
  98. }
  99.  
  100. $speciality_jobs = \SpecialityJobs::findBySpecialityId($specialityRecord['id'])->toArray();
  101.  
  102. $speciality_jobs_ids = $this->getField($speciality_jobs, 'job_id');
  103.  
  104. if ($speciality_jobs_ids && count($speciality_jobs_ids))
  105. $jobs = \FilterTranslates::find([
  106. "id IN ({speciality_jobs_ids:array}) AND language_id = :lang:",
  107. "bind" => ["speciality_jobs_ids" => $speciality_jobs_ids, "lang" => $lang]]);
  108.  
  109. $speciality_subjects = \SpecialitySubjects::findBySpecialityId($specialityRecord['id'])->toArray();
  110.  
  111. foreach ($speciality_subjects as $speciality_subject) {
  112. $subject_id = $speciality_subject['subject_id'];
  113. $subjects[] = (object)[
  114. 'title' => \FilterTranslates::findFirst([
  115. 'filter_id = :subject_id: AND language_id = :language_id:',
  116. 'bind' => ['subject_id' => $subject_id, 'language_id' => $lang]
  117. ])->title,
  118. 'duration_hr' => $speciality_subject['duration_hr'],
  119. 'checkboxes' => $speciality_subject['checkboxes'],
  120. ];
  121. }
  122.  
  123. $specialityRecord['study_start'] = date("d.m.Y", strtotime($specialityRecord['study_start']));
  124. $specialityRecord['registration_end'] = date("d.m.Y", strtotime($specialityRecord['registration_end']));
  125.  
  126. $univer_record = \Universities::findFirstById($specialityRecord['university_id']);
  127. if ($univer_record) {
  128. if ($univer_record->university_logo_id) {
  129. $univerLogo = \Medias::findFirst($univer_record->university_logo_id)->large_url;
  130. $logoAlt = \MediaSeo::findFirst(["media_id = :media_id: AND language_id = :language_id:", "bind" => ["media_id" => $univer_record->university_logo_id, "language_id" => $lang]])->alt;
  131. }
  132. if ($univer_record->banner_image_id)
  133. $univerBanner = \Medias::findFirst($univer_record->banner_image_id)->original_url;
  134.  
  135. $univerUrlSuffix = \UniversityTranslates::findFirst(["university_id = ?0 AND language_id = ?1", "bind" => [0 => $univer_record->id, 1 => $lang]])->url_suffix;
  136.  
  137. $country = \CountriesTranslates::findFirst(["country_id = :country_id: AND language_id = :language_id:", "bind" => ["country_id" => $univer_record->country_id, "language_id" => $lang]])->title;
  138. $city = \CitiesTranslates::findFirst(["city_id = :city_id: AND language_id = :language_id:", "bind" => ["city_id" => $univer_record->city_id, "language_id" => $lang]])->title;
  139.  
  140. }
  141.  
  142. $speciality_dependents = \SpecialityDependend::findBySpecialityId($specialityRecord['id'])->toArray();
  143.  
  144. $speciality_dependents_ids = $this->getField($speciality_dependents, 'speciality_depend_id');
  145.  
  146. if ($speciality_dependents_ids && count($speciality_dependents_ids)) {
  147. $dependents = \FilterTranslates::find([
  148. "id IN ({speciality_dependents_ids:array}) AND language_id = :lang:",
  149. "bind" => ["speciality_dependents_ids" => $speciality_dependents_ids, "lang" => $lang]]);
  150. }
  151.  
  152. $specialArticles = \SpecialtyArticles::findBySpecialtyId($specialityRecord['id'])->toArray();
  153. $special_articles_ids = $this->getField($specialArticles, 'article_id');
  154.  
  155. if ($special_articles_ids && count($special_articles_ids)) {
  156. $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]]);
  157. }
  158.  
  159. $specialityRecord['langs'] = implode(', ', $this->getField($langs, 'title'));
  160. $specialityRecord['faculty'] = $faculty;
  161. $specialityRecord['required_docs'] = $documents;
  162. $specialityRecord['jobs'] = $jobs;
  163. $specialityRecord['subjects'] = $subjects;
  164. $specialityRecord['univer_logo'] = $univerLogo ?? false;
  165. $specialityRecord['univer_banner'] = $univerBanner ?? false;
  166. $specialityRecord['univer_url'] = $univerUrlSuffix;
  167. $specialityRecord['description'] = \SpecialityDescription::findFirst(["speciality_id = :speciality_id: AND language_id = :language_id:", "bind" => ["speciality_id" => $specialityRecord['id'], "language_id" => $lang]]);
  168. $specialityRecord['dependents'] = $dependents;
  169. $specialityRecord['univer_logo_alt'] = $logoAlt;
  170. $specialityRecord['univer_country'] = $country;
  171. $specialityRecord['univer_city'] = $city;
  172. $specialityForCompare = $specialityRecord;
  173. $specialityForCompare['langs'] = $langs_ids;
  174. }
  175.  
  176. $applyFreeServiceId = \ServiceTranslates::findFirstByUrlSuffix('bezkoshtobna-podacha-polsha-vnz')->service_id;
  177. $applyFreeService = \ServiceTranslates::findFirst(["service_id = :service_id: AND language_id = :language_id:", "bind" => ["service_id" => $applyFreeServiceId, "language_id" => $lang]]);
  178.  
  179. $this->view->setVars([
  180. 'speciality' => $specialityRecord,
  181. 'meta' => [
  182. 'title' => $specialityRecord['seo_title'],
  183. 'description' => $specialityRecord['seo_description'],
  184. 'keywords' => $specialityRecord['seo_keywords'],
  185. 'cannonical' => $specialityRecord['url_cannonical'],
  186. ],
  187. 'popularUnivers' => $this->getPopularUniversities($lang),
  188. 'relatedUnivers' => $this->getRelatedUniversities($specialityRecord['country_id'], $specialityRecord['city_id'], $specialityRecord['university_id'], $lang),
  189. 'articles' => $special_articles,
  190. //'univerGallery' => $univerPhotos,
  191. 'currentCity' => $specialityRecord['city'],
  192.  
  193. 'relatedSpecials' => $this->getRelatedSpecialities($specialityForCompare, $lang),
  194. 'apply_free_service' => $applyFreeService->url_suffix,
  195. ]);
  196.  
  197.  
  198. //language titles
  199. $speciality_translate = \SpecialityTranslates::findBySpecialityId($specialityRecord['id']);
  200. $this->changeLangViewParams($speciality_translate);
  201.  
  202. $breadcrumbs = $this->getBaseBreadCrumbs($translates, $lang_code);
  203.  
  204. $breadcrumbs[] = [
  205. 'pos' => '2',
  206. 'title' => $translates['t_content']->specialty_catalog,
  207. 'url' => '/' . $lang_code . '/specialities'
  208. ];
  209.  
  210. $breadcrumbs[] = [
  211. 'pos' => '2',
  212. 'title' => $specialityRecord['title'],
  213. 'url' => '/' . $lang_code . '/specialities/' . $specialityRecord['url_suffix'],
  214. 'last' => true
  215. ];
  216.  
  217. $this->view->breadcrumbs = $breadcrumbs;
  218. }
  219.  
  220. public function getRelatedSpecialities($speciality, $lang, $limit = 5)
  221. {
  222. if (is_array($speciality['langs'])) {
  223. $where = "language_id IN ({langs_ids:array})";
  224. } else {
  225. $where = "language_id = :langs_ids:";
  226. }
  227. $speciality_langs = \SpecialityLanguages::find([$where, "bind" => ["langs_ids" => $speciality['langs']]])->toArray();
  228. $specs_ids = $this->getField($speciality_langs, 'speciality_id');
  229.  
  230. if ($specs_ids) {
  231. if (is_array($specs_ids) && count($specs_ids) > 1) {
  232. $specs_ids_where = "s.id IN ({specs_ids:array})";
  233. } else {
  234. $specs_ids_where = "s.id = :specs_ids:";
  235. $specs_ids = $specs_ids[0];
  236. }
  237. }
  238.  
  239. $bind = [
  240. 'first' => [
  241. "lang" => $lang,
  242. "exclude_id" => $speciality['id'],
  243. "title" => $speciality['title'],
  244. "study_level" => $speciality['study_level_id'],
  245. "specs_ids" => $specs_ids,
  246. ],
  247. 'second' => [
  248. "lang" => $lang,
  249. "exclude_id" => $speciality['id'],
  250. "title" => $speciality['title'],
  251. "study_level" => $speciality['study_level_id']
  252. ],
  253. 'third' => [
  254. "lang" => $lang,
  255. "exclude_id" => $speciality['id'],
  256. "science_id" => $speciality['science_id'],
  257. "study_level" => $speciality['study_level_id'],
  258. "specs_ids" => $specs_ids,
  259. ]
  260. ];
  261.  
  262. $andWhere = [
  263. 'first' => ["str.title = :title:", "str.study_level_id = :study_level:", $specs_ids_where],
  264. 'second' => ["str.title = :title:", "str.study_level_id = :study_level:"],
  265. 'third' => ["str.science_id = :science_id:", "str.study_level_id = :study_level:", $specs_ids_where]
  266. ];
  267.  
  268. /* get specialities with equal title, study_level and languages */
  269. $relatedSpecials['first'] = $this->getSpecialitiesByQuery($bind['first'], $andWhere['first'], $limit);
  270.  
  271. /* get specialities with equal title, study_level and different languages */
  272. if (!isset($relatedSpecials['first']) || count($relatedSpecials['first']) < $limit) {
  273. $secondLimit = isset($relatedSpecials['first']) ? ($limit - count($relatedSpecials['first'])) : $limit;
  274.  
  275. $excludeIds = isset($relatedSpecials['first']) ? $this->getField($relatedSpecials['first'], 'id') : false;
  276. if ($excludeIds) {
  277. $bind['second']['exclude_items'] = $excludeIds;
  278. $andWhere['second'][] = "s.id NOT IN ({exclude_items:array})";
  279. }
  280.  
  281. $relatedSpecials['second'] = $this->getSpecialitiesByQuery($bind['second'], $andWhere['second'], $secondLimit);
  282. }
  283.  
  284. /* get specialities with equal science, study_level and languages */
  285. if (!isset($relatedSpecials['second']) || count($relatedSpecials['second']) < $secondLimit) {
  286. $thirdLimit = (isset($relatedSpecials['second'])) ? ($secondLimit - count($relatedSpecials['second'])) : $secondLimit;
  287.  
  288. if ($excludeIds) {
  289. if (isset($relatedSpecials['second']) && count($relatedSpecials['second'])) {
  290. $excludeIds = array_merge($excludeIds, $this->getField($relatedSpecials['second'], 'id'));
  291. }
  292. $bind['third']['exclude_items'] = $excludeIds;
  293. $andWhere['third'][] = "s.id NOT IN ({exclude_items:array})";
  294. } else {
  295. if (isset($relatedSpecials['second']) && count($relatedSpecials['second'])) {
  296. $excludeIds = $this->getField($relatedSpecials['second'], 'id');
  297. if ($excludeIds) {
  298. $bind['third']['exclude_items'] = $excludeIds;
  299. $andWhere['third'][] = "s.id NOT IN ({exclude_items:array})";
  300. }
  301. }
  302. }
  303.  
  304. $relatedSpecials['third'] = $this->getSpecialitiesByQuery($bind['third'], $andWhere['third'], $thirdLimit);
  305. }
  306.  
  307. $relatedSpecials = array_merge($relatedSpecials['first'], $relatedSpecials['second'], $relatedSpecials['third']);
  308.  
  309. return $relatedSpecials;
  310. }
  311.  
  312. public function getSpecialitiesByQuery($bind, $andWhere, $limit)
  313. {
  314.  
  315. $relatedSpecials = $this->modelsManager->createBuilder()
  316. ->addFrom('Specialities', 's')
  317. ->columns("
  318. 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,
  319. cit.title as city, m.large_url as image, ms.alt as image_alt, ms.title as image_title, ft.title as study_level")
  320. ->leftjoin('SpecialityTranslates', 'str.speciality_id = s.id AND str.language_id = :lang:', 'str')
  321. ->leftjoin('UniversityTranslates', 'utr.university_id = s.university_id AND utr.language_id = :lang:', 'utr')
  322. ->leftjoin('CountriesTranslates', 'cot.country_id = s.country_id AND cot.language_id = :lang:', 'cot')
  323. ->leftjoin('CitiesTranslates', 'cit.city_id = s.city_id AND cit.language_id = :lang:', 'cit')
  324. ->leftjoin('Universities', 'u.id = s.university_id', 'u')
  325. ->leftjoin('Medias', 'm.id = u.banner_image_id', 'm')
  326. ->leftjoin('MediaSeo', 'ms.media_id = m.id AND ms.language_id = :lang:', 'ms')
  327. ->leftjoin('FilterTranslates', 'ft.id = str.study_level_id AND ft.language_id = :lang:', 'ft')
  328. ->where("s.id <> :exclude_id:")
  329. ->andWhere("s.is_published = 1");
  330.  
  331. foreach ($andWhere as $value) {
  332. if ($value) {
  333. if (strpos($value, ':array}') === false) {
  334. $relatedSpecials = $relatedSpecials->andWhere($value);
  335. } else {
  336. preg_match('/({(.*?):array})/', $value, $match);
  337. $key = trim(str_replace(":array}", "", $match[1]), "{");
  338. if ($key === 'specs_ids') {
  339. $relatedSpecials = $relatedSpecials->andWhere("s.id IN (" . implode(',', $bind[$key]) . ")");
  340. }
  341. if ($key === 'exclude_items') {
  342. $relatedSpecials = $relatedSpecials->andWhere("s.id NOT IN (" . implode(',', $bind[$key]) . ")");
  343. }
  344. //$relatedSpecials = $relatedSpecials->andWhere($value, [$key => $bind[$key]]);
  345. unset($bind[$key]);
  346. }
  347. }
  348. }
  349.  
  350. $limit = ($limit != null) ? $limit : 5;
  351. $relatedSpecials = $relatedSpecials->limit($limit)
  352. ->getQuery()
  353. ->execute($bind)
  354. ->toArray();
  355.  
  356. if ($relatedSpecials) {
  357. foreach ($relatedSpecials as $key => $item) {
  358. $speciality_langs = \SpecialityLanguages::findBySpecialityId($item['id'])->toArray();
  359. $langs_ids = $this->getField($speciality_langs, 'language_id');
  360. if ($langs_ids) {
  361. if (count($langs_ids) > 1) {
  362. $where = "id IN ({langs_ids:array}) AND language_id = :lang:";
  363. } else {
  364. $where = "id = :langs_ids: AND language_id = :lang:";
  365. }
  366. $langs = \FilterTranslates::find([
  367. $where,
  368. "bind" => ["langs_ids" => $langs_ids, "lang" => $bind['lang']]])->toArray();
  369. $relatedSpecials[$key]['study_langs'] = implode(', ', $this->getField($langs, 'title'));
  370. }
  371.  
  372. }
  373. }
  374.  
  375. return $relatedSpecials;
  376. }
  377. }
#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)
  1. <?php
  2. //
  3. use Phalcon\Mvc\Application;
  4. use Phalcon\DI\FactoryDefault;
  5.  
  6.  
  7. (new Phalcon\Support\Debug)->listen();
  8.  
  9.  
  10. require_once __DIR__ . '/../vendor/autoload.php';
  11.  
  12. /**
  13. * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
  14. */
  15. $di = new FactoryDefault();
  16.  
  17. $dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
  18. $dotenv->load();
  19.  
  20. if($_ENV['ENVIRONMENT'] == 'local'){
  21. ini_set('display_errors', 1);
  22. ini_set('display_startup_errors', 1);
  23. ini_set('error_reporting', E_ALL & ~E_NOTICE);
  24. error_reporting(E_ALL & ~E_NOTICE);
  25. } else {
  26. ini_set('display_errors', 0);
  27. }
  28.  
  29. try {
  30.  
  31.  
  32. /**
  33. * Include services
  34. */
  35. $config = require __DIR__ . "/../apps/config/config.php";
  36.  
  37.  
  38. require_once __DIR__ . '/../apps/config/services.php';
  39.  
  40. /**
  41. * Registering a router
  42. */
  43.  
  44. require_once __DIR__ . "/../apps/config/routers.php";
  45.  
  46.  
  47. /**
  48. * Handle the request
  49. */
  50. $application = new Application($di);
  51.  
  52.  
  53. /**
  54. * Include modules
  55. */
  56. require_once __DIR__ . '/../apps/config/modules.php';
  57.  
  58. $application->handle($_SERVER['REQUEST_URI'])->send();
  59.  
  60.  
  61. } catch (\Exception $e) {
  62. echo $e->getMessage();
  63. } catch (PDOException $e) {
  64. echo $e->getMessage();
  65. }
  66.