HEX
Server: Apache
System: Linux v38079.2is.nl 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: democfellows (10015)
PHP: 8.1.34
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/creativefellows.nl/kjs.creativefellows.nl/src/KJS/KjsController.php
<?php
	
	namespace KJS;
	
	use Cassette\MainController;
	use Cassette\BaseController;
	
	class KjsController extends MainController{
	
	
		function __construct($container)
		{
		
		    $this->db 		= $container->get('db');
		    $this->router	= $container->get('router');
		    $this->view  	= $container->get('renderer');		
			$this->settings	= $container->get('settings');
		
			$this->client_settings 		= $this->getClientSettings();
			$this->config				= new BaseController($this->settings,$this->client_settings);				
					
		}
		
		
		public function locations($request, $response, $args)
		{
			// get request contents
			$category = isset($args["category"]) ? $args["category"] : 30;

			$locations	= $this->getPage(6,$category);
			
						
			
			$json = [];
			foreach($locations as $loc)
			{
		
				
				if($loc->getProperty("breedtegraad") == "" || $loc->getProperty("lengtegraad") == "") continue;
				
				$entry = [
					"name" 	=> $loc->getProperty("naam"),
					"intro" => $loc->getProperty("intro"),
					"lat" 	=> $loc->getProperty("breedtegraad"),
					"long"	=> $loc->getProperty("lengtegraad"),
					"link" 	=> $loc->getProperty("entry_link"),
					"image" => $loc->getProperty("favicon","links"),
					"color" => $loc->getProperty("kleur")
				];
				
				$json[] = $entry;
			}
			

			
			return $response->withHeader('Content-Type', 'application/json')->withStatus(200)->write(json_encode($json,JSON_NUMERIC_CHECK));
						
		}
		
		public function location($request, $response, $args)
		{
			
			// get url parameters
			$location		= isset($args["location_name"]) ? $args["location_name"] : 0;			

			
			// get topbar navigation
			$navigation = $this->getMainNavigation(true,$this->section_name);
				
						
			// get page contents
			$page 	= $this->getPage("locaties",0,$location);

			
			// return 404 if no page has been $found
			if(empty($page)) return $this->get404Page($request, $response, $args);
			
			
			// filter maps
			$category_filter = $this->entryCategory( $page[0]->getProperty("uid") );	
			
			
			// agenda
			$agenda_school = $this->locationAgenda( $page[0]->getProperty("tags")["tags"],$page[0]->getProperty("uid"),"LIMIT 0,10");
			
								
			// return the page
			return $this->view->render($response, $this->getViewCanvas($page[0]->page_canvas,$page[0]->pagination_view), array(
				"config" 		=> $this->config,
				"page" 			=> $page, 
				"navigation" 	=> $navigation,
				"agenda_school" => $agenda_school,
				"maps_filter"	=> $category_filter->getCategoryUrl(),
			));
			
		}

		public function agenda($request, $response, $args)
		{

			// get url parameters
			$this->section_name 	= "agenda";
			$this->category_name 	= isset($args["category"]) ? $args["category"] : 0;
			$this->entry_name		= isset($args["entry"]) ? $args["entry"] : 0;			
			$this->get_uid			= isset($args["uid"]) ? $args["uid"] : 0;			
			
			$current_pagination 	= isset($args["pagination"]) ? $args["pagination"] : 1;
			
			// get topbar navigation
			$navigation = $this->getMainNavigation(true,$this->section_name);
			
						
			// get page contents
			$page 	= $this->getPage($this->section_name,0,$this->entry_name,$current_pagination,true,0,true);


			// return 404 if no page has been $found
			if(empty($page)) return $this->get404Page($request, $response, $args);
			
			
			// list agenda	
			//$agenda = $this->listAgenda($this->category_name);
			
			$baseurl_parts = implode("/",[$this->section_name,""]);
			$categories = $this->getCategory(0,$this->section_name,$this->entry_name,true,$baseurl_parts);
			
			foreach($categories as $c){
				//echo $c->name();
				$c->items = $this->listAgenda( $c->name() );
			}

			
			// return the page
			return $this->view->render($response, "view.agenda.php", array(
				"cassette"		=> $this,
				"config" 		=> $this->config,
				"router" 		=> $this->router, 
				"page" 			=> $page, 
				"navigation" 	=> $navigation,
				"categories"	=> $categories,
				"section_name"	=> $this->section_name,
				"category_name"	=> $this->category_name,
				"meta_title"	=> $page[0]->getMetaTitle(),
				"agenda" 		=> $agenda,
				"pagination" 	=> [
					"pagination_rows_total" => $this->pagination_rows_total, 
					"pagination_count" => $this->pagination_count, 
					"current_page" => $current_pagination, 
					"next_page" => $current_pagination + 1 , 
					"previous_page" => $current_pagination - 1 
				]
			));
			
		}
		
		public function brochure($request, $response, $args)
		{
		
			// get url parameters
			$this->section_name 	= "brochure";
			$this->category_name 	= isset($args["category"]) ? $args["category"] : 0;
			$this->entry_name		= isset($args["entry"]) ? $args["entry"] : 0;			
			$this->get_uid			= isset($args["uid"]) ? $args["uid"] : 0;			
			$this->current_pagination = isset($args["pagination"]) ? $args["pagination"] : 1;
			
			
			// get topbar navigation
			$navigation = $this->getMainNavigation(true,$this->section_name);
					
			// get page contents
			$page 	= $this->getPage($this->section_name,$this->category_name,$this->entry_name,$this->current_pagination,true,0,true);

			// return 404 if no page has been $found
			if(empty($page)) return $this->get404Page($request, $response, $args);
			
			// return the page
			return $this->view->render($response, "view.default.php", array(
				"cassette"		=> $this,
				"config" 		=> $this->config,
				"router" 		=> $this->router, 
				"page" 			=> $page, 
				"navigation" 	=> $navigation,
				"categories"	=> $categories,
				"section_name"	=> $this->section_name,
				"category_name"	=> $this->category_name
			));
			
		}
		
		
		public function keuzehulp($request, $response, $args)
		{
		
			// get url parameters
			$this->section_name 	= "keuzehulp";
			$this->category_name 	= isset($args["category"]) ? $args["category"] : 0;
			$this->entry_name		= isset($args["entry"]) ? $args["entry"] : 0;			
			$this->get_uid			= isset($args["uid"]) ? $args["uid"] : 0;			
			
			
			// get topbar navigation
			$navigation = $this->getMainNavigation(true,$this->section_name);
			
						
			// get page contents
			$page 	= $this->getPage($this->section_name);//,$this->category_name,$this->entry_name,$current_pagination,true,0,true);

			
			// return 404 if no page has been $found
			if(empty($page)) return $this->get404Page($request, $response, $args);
			
			
			// list agenda	
			$scholen = $this->listScholen("locaties",$this->category_name);
			
			
			// categories
			$baseurl_parts = implode("/",[$this->section_name,""]);
			$categories = $this->getCategory(0,$this->section_name,$this->entry_name,true,$baseurl_parts);
			
			
			// return the page
			return $this->view->render($response, "view.keuzehulp.php", array(
				"cassette"		=> $this,
				"config" 		=> $this->config,
				"router" 		=> $this->router, 
				"page" 			=> $page, 
				"navigation" 	=> $navigation,
				"categories"	=> $categories,
				"section_name"	=> $this->section_name,
				"category_name"	=> $this->category_name,
				"meta_title"	=> $page[0]->getMetaTitle(),
				"locaties" 		=> $scholen,
				"pagination" 	=> [
					"pagination_rows_total" => $this->pagination_rows_total, 
					"pagination_count" => $this->pagination_count, 
					"current_page" => $current_pagination, 
					"next_page" => $current_pagination + 1 , 
					"previous_page" => $current_pagination - 1 
				]
			));
			
		
		}
		
		
		private function locationAgenda($tags,$uid,$limit)
		{

			$sql = "SELECT
					td_agenda.evenement,
					td_agenda.omschrijving,
					td_agenda.datum,
					td_agenda.tijd,
					td_agenda.logo,
					td_agenda.unique_id,
					count(*) as filter_count,
					unique_ids.url
					FROM tags 
					LEFT JOIN entry_tags 
						ON tags.tag_id = entry_tags.tag_id
					LEFT JOIN unique_ids
						ON unique_ids.unique_id = entry_tags.unique_id
					LEFT JOIN td_agenda
						ON td_agenda.unique_id = unique_ids.unique_id
					WHERE tags.name 
						IN ('". implode("','",$tags)."')
					AND entry_tags.unique_id != :uid
					AND unique_ids.status = 2
					AND unique_ids.sectie_id = 2
					
					GROUP BY entry_tags.unique_id 
					HAVING filter_count >= 2
					ORDER BY td_agenda.datum ASC ";

			$sth = $this->db->prepare($sql . $limit_query);
			$sth->execute([
				"uid" => $uid
			]);		
			
				
			$items = [];
	        while($entry = $sth->fetch())
			{
				$items[] = new AgendaItem($entry);
			}

			return $items;
					
		}
		
		
		
		
		private function listScholen($section_name,$category_name=0)
		{
			if($category_name !== 0){
				
				$category_id 	= $this->getCategoryId(6,$category_name);	
				
				
				$sql = "SELECT *, unique_ids.unique_id as uid 
					FROM unique_ids 
					JOIN entry_categories
					ON unique_ids.unique_id  = entry_categories.unique_id 
					JOIN td_scholen
					ON unique_ids.unique_id = td_scholen.unique_id
					AND category_id = :cat_id
					AND td_scholen.keuzehulp = 1
					AND unique_ids.status = 2";
					
				
				// query results	
				$sth = $this->db->prepare($sql . $sort_query . $limit_query);
				$sth->execute([
					"cat_id" => $category_id
				]);
								
			}
			else{
				
				 $sql = "SELECT *, unique_ids.unique_id as uid 
							FROM td_scholen
							LEFT JOIN unique_ids 
							ON unique_ids.unique_id = td_scholen.unique_id
							WHERE unique_ids.sectie_id = 6 
							AND unique_ids.status = 2 
							AND td_scholen.keuzehulp = 1
							ORDER BY td_scholen.naam ASC";
		
				$sth = $this->db->prepare($sql . $limit_query);
				$sth->execute();
				
			}
			
			$uids = [];
			
	
	        while($entry = $sth->fetch())
			{
				$school = (new SchoolLocatie($entry));
				$school->setHTML( $this->sectionHTML( $school->uid() ) );
				
		
				
				$uids[] = $school;
			}
			
		
			return $uids;
							
		}
		
		
		private function sectionHTML($uid,$sub_of=0)
		{	
			$sql = "SELECT * FROM page_section_content WHERE page_id = :uid AND sub_of = :sub_of AND status = '1' AND element_class = '' ORDER BY position ASC";
			$sth = $this->db->prepare($sql);
			
			$sth->execute(["uid" => $uid, "sub_of" => $sub_of]);
			
			$data = $sth->fetch();
			return $data["html"];
			
			
			//return "<p>test test test test test</p>";
		}
		
		
		private function listAgenda($category_name)
		{


			if($category_name !== 0){

				$category_id 	= $this->getCategoryId(2,$category_name);	
				
				//die($now);
				$sql = "SELECT *, unique_ids.unique_id as uid 
					FROM unique_ids 
					LEFT JOIN entry_categories
					ON unique_ids.unique_id  = entry_categories.unique_id 
					LEFT JOIN td_agenda
					ON unique_ids.unique_id = td_agenda.unique_id
					WHERE ( datum >= NOW() )
					AND category_id = :cat_id
					AND unique_ids.status = 2
					ORDER BY td_agenda.datum ASC";
					
				
				// query results	
				$sth = $this->db->prepare($sql . $sort_query . $limit_query);
				$sth->execute([
					"cat_id" => $category_id
				]);
				
			}
			else{
				
				$sql = "SELECT *, unique_ids.unique_id as uid 
							FROM td_agenda 
							LEFT JOIN unique_ids 
							ON unique_ids.unique_id = td_agenda.unique_id
							WHERE unique_ids.sectie_id = 2 
							AND unique_ids.status = 2 
							AND (datum >= NOW() )
							ORDER BY td_agenda.datum ASC";
				
				$sth = $this->db->prepare($sql . $limit_query);
				$sth->execute([
					"sectie_id" => 2
				]);
					
			}
				
			
		
		
			$uids = [];
	        while($entry = $sth->fetch())
			{
				$uids[] = new AgendaItem($entry);
			}
			
			return $uids;
											
			
		}
		
		
	}
	
	
?>