Phalcon Framework 5.6.1

TypeError: implode(): Argument #2 ($array) must be of type ?array, int given

/var/www/studyforyou.info/apps/modules/frontend/controllers/CourseProfileController.php (116)
#0implode
/var/www/studyforyou.info/apps/modules/frontend/controllers/CourseProfileController.php (116)
  1. <?php
  2.  
  3. namespace Modules\Frontend\Controllers;
  4.  
  5. class CourseProfileController extends ControllerBase
  6. {
  7.  
  8. /**
  9. * @param $course
  10. */
  11. public function indexAction($course)
  12. {
  13. $lang_code = $this->language;
  14. $languagesModel = new \Languages();
  15. $lang = $languagesModel::findFirst("code='$lang_code'")->id;
  16.  
  17. //second param is filters you want use
  18. $translates = $this->setViewTranslates($lang, ['menu', 'header', 'filters', 'footer', 'content', 'tabs']);
  19.  
  20. $this->assets->addCss('frontend/dist/css/course-profile.css' . $this->disableCache());
  21. $this->assets->addJs('frontend/js/course-profile.js' . $this->disableCache());
  22. $this->assets->addJs('frontend/js/rating.js' . $this->disableCache());
  23.  
  24. $courseRecord = $this->modelsManager->createBuilder()
  25. ->addFrom('Courses', 'c')
  26. ->columns("
  27. c.id id,
  28. ctr.title title,
  29. c.country_id country_id,
  30. c.city_id city_id,
  31. cot.title as country,
  32. cit.title as city,
  33. ctr.type_id type_id,
  34. c.university_id university_id,
  35. ctr.category_id category_id,
  36. ctr.duration duration,
  37. c.cost cost,
  38. c.registration_fee registration_fee,
  39. c.registration_end registration_end,
  40. c.study_start study_start,
  41. c.study_hours study_hours,
  42. utr.title as university,
  43. ctr.url_suffix url_suffix,
  44. ctr.description description,
  45. ctr.seo_title seo_title,
  46. ctr.seo_description seo_description,
  47. ctr.seo_keywords seo_keywords,
  48. ctr.url_cannonical url_cannonical
  49. ")
  50. ->leftjoin('UniversityTranslates', 'utr.university_id = c.university_id AND utr.language_id = :language_id:', 'utr')
  51. ->leftjoin('CourseTranslates', 'ctr.course_id = c.id AND ctr.language_id = :language_id:', 'ctr')
  52. ->leftjoin('CountriesTranslates', 'cot.country_id = c.country_id AND cot.language_id = :language_id:', 'cot')
  53. ->leftjoin('CitiesTranslates', 'cit.city_id = c.city_id AND cit.language_id = :language_id:', 'cit')
  54. ->andWhere("ctr.url_suffix = :course:")
  55. ->getQuery()
  56. ->getSingleResult(['course' => $course, 'language_id' => $lang]);
  57.  
  58. if ($courseRecord) {
  59. $courseRecord = $courseRecord->toArray();
  60.  
  61. $courseRecord['registration_end'] = date("d.m.Y", strtotime($courseRecord['registration_end']));
  62. $courseRecord['study_start'] = date('d.m.Y', strtotime($courseRecord['study_start']));
  63.  
  64. $course_langs = \CourseLanguages::find(["course_id = :course_id:", "bind" => ["course_id" => $courseRecord['id']]])->toArray();
  65. $langs_ids = $this->getField($course_langs, 'language_id');
  66. if (count($langs_ids))
  67. $langs = \FilterTranslates::find(["id IN ({langs_ids:array}) AND language_id = :language_id:", "bind" => ["langs_ids" => $langs_ids, "language_id" => $lang]])->toArray();
  68.  
  69. $course_profiles = \CourseProfile::find(["course_id = :course_id:", "bind" => ["course_id" => $courseRecord['id']]])->toArray();
  70. $profiles_ids = $this->getField($course_profiles, 'profile_id');
  71. if (count($profiles_ids))
  72. $profiles = \FilterTranslates::find(["id IN ({profiles_ids:array}) AND language_id = :language_id:", "bind" => ["profiles_ids" => $profiles_ids, "language_id" => $lang]])->toArray();
  73.  
  74. $type = \FilterTranslates::findFirst(["id = :type_id: AND language_id = :language_id:", "bind" => ["type_id" => $courseRecord['type_id'], "language_id" => $lang]])->title;
  75. $duration = \FilterTranslates::findFirst(["id = :duration_id: AND language_id = :language_id:", "bind" => ["duration_id" => $courseRecord['duration'], "language_id" => $lang]])->title;
  76.  
  77. $univer_record = \Universities::findFirstById($courseRecord['university_id']);
  78. if ($univer_record) {
  79. if ($univer_record->university_logo_id) {
  80. $univerLogo = \Medias::findFirst($univer_record->university_logo_id)->large_url;
  81. $logoAlt = \MediaSeo::findFirst(["media_id = :media_id: AND language_id = :language_id:", "bind" => ["media_id" => $univer_record->university_logo_id, "language_id" => $lang]])->alt;
  82. }
  83. if ($univer_record->banner_image_id)
  84. $univerBanner = \Medias::findFirst($univer_record->banner_image_id)->original_url;
  85.  
  86. $univerUrlSuffix = \UniversityTranslates::findFirst(["university_id = ?0 AND language_id = ?1", "bind" => [0 => $univer_record->id, 1 => $lang]])->url_suffix;
  87.  
  88. $country = \CountriesTranslates::findFirst(["country_id = :country_id: AND language_id = :language_id:", "bind" => ["country_id" => $univer_record->country_id, "language_id" => $lang]])->title;
  89. $city = \CitiesTranslates::findFirst(["city_id = :city_id: AND language_id = :language_id:", "bind" => ["city_id" => $univer_record->city_id, "language_id" => $lang]])->title;
  90.  
  91. }
  92.  
  93. $courseMedia = $this->modelsManager->createBuilder()
  94. ->addFrom('CourseMedias', 'cm')
  95. ->columns("m.id id, m.large_url as url, ms.alt alt, ms.title title")
  96. ->leftjoin('Medias', 'm.id = cm.media_id', 'm')
  97. ->leftjoin('MediaSeo', 'ms.media_id = cm.media_id AND ms.language_id = :lang_id:', 'ms')
  98. ->where('cm.course_id = :course_id:')
  99. ->getQuery()
  100. ->execute(['course_id' => $courseRecord['id'], 'lang_id' => $lang])->toArray();
  101.  
  102. $courseArticles = \CourseArticles::findByCourseId($courseRecord['id'])->toArray();
  103. $course_articles_ids = $this->getField($courseArticles, 'article_id');
  104.  
  105. if ($course_articles_ids && count($course_articles_ids)) {
  106. $course_articles = \ArticleTranslates::find(["article_id IN ({course_articles_ids:array}) AND language_id = :language_id:", "bind" => ["course_articles_ids" => $course_articles_ids, "language_id" => $lang]]);
  107. }
  108.  
  109. $courseForCompare = $courseRecord;
  110. $courseForCompare['langs'] = $langs_ids;
  111.  
  112. $courseRecord['univer_country'] = $country;
  113. $courseRecord['univer_city'] = $city;
  114. $courseRecord['univer_url'] = $univerUrlSuffix;
  115.  
  116. $courseRecord['langs'] = implode(', ', $this->getField($langs, 'title'));
  117. $courseRecord['type'] = $type;
  118. $courseRecord['duration'] = $duration;
  119. $courseRecord['profile'] = implode(', ', $this->getField($profiles, 'title'));
  120. $courseRecord['univer_logo'] = $univerLogo ?? false;
  121. $courseRecord['univer_banner'] = $univerBanner ?? false;
  122. $courseRecord['univer_logo_alt'] = $logoAlt;
  123. }
  124.  
  125. $this->view->setVars([
  126. 'course' => $courseRecord,
  127. 'popularUnivers' => $this->getPopularUniversities($lang),
  128. 'relatedUnivers' => $this->getRelatedUniversities($courseRecord['country_id'], $courseRecord['city_id'], $courseRecord['university_id'], $lang),
  129. 'currentCity' => $courseRecord['city'],
  130. 'courseMedia' => $courseMedia,
  131. 'articles' => $course_articles,
  132. 'meta' => [
  133. 'title' => $courseRecord['seo_title'],
  134. 'description' => $courseRecord['seo_description'],
  135. 'keywords' => $courseRecord['seo_keywords'],
  136. 'cannonical' => $courseRecord['url_cannonical'],
  137. ],
  138. 'relatedCourses' => $this->getRelatedCourses($courseForCompare, $lang),
  139. ]);
  140.  
  141.  
  142. //language titles
  143. $course_translate = \CourseTranslates::findByCourseId($courseRecord['id']);
  144. $this->changeLangViewParams($course_translate);
  145.  
  146. $breadcrumbs = $this->getBaseBreadCrumbs($translates, $lang_code);
  147.  
  148. $breadcrumbs[] = [
  149. 'pos' => '2',
  150. 'title' => $translates['t_content']->accomodation_catalog,
  151. 'url' => '/' . $lang_code . '/accomodation'
  152. ];
  153.  
  154. $breadcrumbs[] = [
  155. 'pos' => '3',
  156. 'title' => $courseRecord['title'],
  157. 'url' => '/' . $lang_code . '/courses/' . $courseRecord['url_suffix'],
  158. 'last' => true
  159. ];
  160.  
  161. $this->view->breadcrumbs = $breadcrumbs;
  162. }
  163.  
  164. /**
  165. * @param $course
  166. * @param $lang
  167. * @param int $limit
  168. * @return array
  169. */
  170. public function getRelatedCourses($course, $lang, $limit = 5)
  171. {
  172. $course_langs = \CourseLanguages::find(["language_id IN ({langs_ids:array})", "bind" => ["langs_ids" => $course['langs']]])->toArray();
  173. $courses_ids = $this->getField($course_langs, 'course_id');
  174.  
  175. $bind = [
  176. 'first' => [
  177. "lang" => $lang,
  178. "exclude_id" => $course['id'],
  179. "title" => $course['title'],
  180. "courses_ids" => $courses_ids,
  181. ],
  182. 'second' => [
  183. "lang" => $lang,
  184. "exclude_id" => $course['id'],
  185. "title" => $course['title'],
  186. ],
  187. 'third' => [
  188. "lang" => $lang,
  189. "exclude_id" => $course['id'],
  190. "courses_ids" => $courses_ids,
  191. ]
  192. ];
  193.  
  194. $andWhere = [
  195. 'first' => ["ctr.title = :title:", "c.id IN ({courses_ids:array})"],
  196. 'second' => ["ctr.title = :title:"],
  197. 'third' => ["c.id IN ({courses_ids:array})"]
  198. ];
  199.  
  200. /* get courses with with equal title and languages */
  201. $relatedCourses['first'] = $this->getCoursesByQuery($bind['first'], $andWhere['first'], $limit);
  202.  
  203. /* get courses with equal title and different languages */
  204. if (!isset($relatedCourses['first']) || count($relatedCourses['first']) < $limit) {
  205. $secondLimit = isset($relatedCourses['first']) ? ($limit - count($relatedCourses['first'])) : $limit;
  206.  
  207. $excludeIds = isset($relatedCourses['first']) ? $this->getField($relatedCourses['first'], 'id') : false;
  208. if ($excludeIds) {
  209. $bind['second']['exclude_items'] = $excludeIds;
  210. $andWhere['second'][] = "c.id NOT IN ({exclude_items:array})";
  211. }
  212.  
  213. $relatedCourses['second'] = $this->getCoursesByQuery($bind['second'], $andWhere['second'], $secondLimit);
  214. }
  215.  
  216. /* get courses with equal languages */
  217. if (!isset($relatedCourses['second']) || count($relatedCourses['second']) < $secondLimit) {
  218. $thirdLimit = (isset($relatedCourses['second'])) ? ($secondLimit - count($relatedCourses['second'])) : $secondLimit;
  219.  
  220. if ($excludeIds) {
  221. if (isset($relatedCourses['second']) && count($relatedCourses['second'])) {
  222. $excludeIds = array_merge($excludeIds, $this->getField($relatedCourses['second'], 'id'));
  223. }
  224. $bind['third']['exclude_items'] = $excludeIds;
  225. $andWhere['third'][] = "c.id NOT IN ({exclude_items:array})";
  226. } else {
  227. if (isset($relatedCourses['second']) && count($relatedCourses['second'])) {
  228. $excludeIds = $this->getField($relatedCourses['second'], 'id');
  229. if ($excludeIds) {
  230. $bind['third']['exclude_items'] = $excludeIds;
  231. $andWhere['third'][] = "c.id NOT IN ({exclude_items:array})";
  232. }
  233. }
  234. }
  235.  
  236. $relatedCourses['third'] = $this->getCoursesByQuery($bind['third'], $andWhere['third'], $thirdLimit);
  237. }
  238.  
  239. $relatedCourses = array_merge($relatedCourses['first'], $relatedCourses['second'], $relatedCourses['third']);
  240.  
  241. return $relatedCourses;
  242. }
  243.  
  244. public function getCoursesByQuery($bind, $andWhere, $limit)
  245. {
  246.  
  247. $relatedCourses = $this->modelsManager->createBuilder()
  248. ->addFrom('Courses', 'c')
  249. ->columns("
  250. c.id id, c.cost cost, ctr.title title, ctr.url_suffix as url, utr.title as university, utr.url_suffix as univer_url,
  251. cot.title as country, cit.title as city, m.large_url as image, ms.alt as image_alt, ms.title as image_title, ctr.duration duration")
  252. ->leftjoin('CourseTranslates', 'ctr.course_id = c.id AND ctr.language_id = :lang:', 'ctr')
  253. ->leftjoin('UniversityTranslates', 'utr.university_id = c.university_id AND utr.language_id = :lang:', 'utr')
  254. ->leftjoin('CountriesTranslates', 'cot.country_id = c.country_id AND cot.language_id = :lang:', 'cot')
  255. ->leftjoin('CitiesTranslates', 'cit.city_id = c.city_id AND cit.language_id = :lang:', 'cit')
  256. ->leftjoin('Universities', 'u.id = c.university_id', 'u')
  257. ->leftjoin('Medias', 'm.id = u.banner_image_id', 'm')
  258. ->leftjoin('MediaSeo', 'ms.media_id = m.id AND ms.language_id = :lang:', 'ms')
  259. ->where("c.id <> :exclude_id:")
  260. ->andWhere("c.is_published = 1");
  261.  
  262. foreach ($andWhere as $value) {
  263. if (strpos($value, ':array}') === false) {
  264. $relatedCourses = $relatedCourses->andWhere($value);
  265. } else {
  266. preg_match('/({(.*?):array})/', $value, $match);
  267. $key = trim(str_replace(":array}", "", $match[1]), "{");
  268.  
  269. $relatedCourses = $relatedCourses->andWhere($value, [$key => $bind[$key]]);
  270. unset($bind[$key]);
  271. }
  272. }
  273.  
  274.  
  275. $relatedCourses = $relatedCourses->limit($limit)
  276. ->getQuery()
  277. ->execute($bind)
  278. ->toArray();
  279.  
  280.  
  281. foreach ($relatedCourses as $key => $item) {
  282. $course_langs = \CourseLanguages::findByCourseId($item['id'])->toArray();
  283. $langs_ids = $this->getField($course_langs, 'language_id');
  284. if (count($langs_ids)) {
  285. $langs = \FilterTranslates::find([
  286. "id IN ({langs_ids:array}) AND language_id = :lang:",
  287. "bind" => ["langs_ids" => $langs_ids, "lang" => $bind['lang']]])->toArray();
  288. }
  289. $relatedCourses[$key]['study_langs'] = implode(', ', $this->getField($langs, 'title'));
  290. }
  291.  
  292. return $relatedCourses;
  293. }
  294. }
#1Modules\Frontend\Controllers\CourseProfileController->indexAction
#2Phalcon\Dispatcher\AbstractDispatcher->callActionMethod
#3Phalcon\Dispatcher\AbstractDispatcher->dispatch
#4Phalcon\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.