92 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| defined('BASEPATH') OR exit('No direct script access allowed');
 | |
| 
 | |
| use Coduo\PHPHumanizer\DateTimeHumanizer;
 | |
| 
 | |
| class Projects extends MY_Controller
 | |
| {
 | |
| 
 | |
|     public function __construct()
 | |
|     {
 | |
|         parent::__construct('projects');
 | |
|         $this->load->model('ProjectsModel', '', TRUE);
 | |
|     }
 | |
| 
 | |
|     public function index($album = 'all')
 | |
|     {
 | |
|         $categories = $this->ProjectsModel->getCategories($album);
 | |
|         $content = $this->ProjectsModel->getEntries('all');
 | |
| 
 | |
|         $this->load->view('header', ['active' => 'projects', 'title' => lang('projects_sitetitle'), 'additionalStyles' => ['sortlist.css', 'projects.css']]);
 | |
|         $this->load->view('projects', ['content' => $content, 'album' => $album, 'categories' => $categories]);
 | |
|         $this->load->view('footer', ['additionalScripts' => ['lib/isotope.pkgd.min.js', 'projects.js']]);
 | |
|     }
 | |
| 
 | |
|     public function entry($entry = null)
 | |
|     {
 | |
|         if ($entry == null) {
 | |
|             redirect(base_url('projects'));
 | |
|         } else {
 | |
|             if ($this->ProjectsModel->checkIfNameExists($entry)) {
 | |
|                 $data = $this->ProjectsModel->getEntryByName($entry, $_SESSION['site_lang']);
 | |
|                 $timecreated = strtotime($data['datetime']);
 | |
|                 $data['time_existing'] = DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$timecreated"), $_SESSION['site_lang']);
 | |
| 
 | |
|                 $voteCount = $this->ProjectsModel->getVoteCount($data['ID']);
 | |
|                 $voteType = 0;
 | |
|                 if (isset($_SESSION['user']['ID']))
 | |
|                     $voteType = $this->ProjectsModel->getUserVoteType($data['ID'], $_SESSION['user']['ID']);
 | |
|                 $prevProject = $this->ProjectsModel->getPrevProject($data['ID']);
 | |
|                 $nextProject = $this->ProjectsModel->getNextProject($data['ID']);
 | |
| 
 | |
|                 $this->load->view('header', ['active' => 'projects', 'title' => $data['title'] . ' - ' . lang('projects_sitetitle'), 'additionalStyles' => ['project_entry.css']]);
 | |
|                 $this->load->view('projects_entry', ['data' => $data, 'voteCount' => $voteCount, 'voteType' => $voteType, 'prevProject' => $prevProject, 'nextProject' => $nextProject]);
 | |
|                 $this->load->view('footer', ['additionalScripts' => ['project-entry.js']]);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public function getEntries()
 | |
|     {
 | |
|         $items = $this->ProjectsModel->getEntries('all');
 | |
|         var_dump($items);
 | |
|         foreach ($items as $item) {
 | |
|             var_dump($item);
 | |
|             $this->load->view('projects_list_entry', $item);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public function addVote()
 | |
|     {
 | |
|         header('Content-Type: text/json');
 | |
|         if (!isset($_SESSION['user']) || empty($_SESSION['user'])) {
 | |
|             $result = ['type' => 'error', 'msg' => 'Du musst eingeloggt sein, um dieses Projekt zu bewerten.'];
 | |
|             echo json_encode($result);
 | |
|             exit;
 | |
|         }
 | |
| 
 | |
|         $projectID = $this->input->post('id');
 | |
|         $voteType = $this->input->post('type');
 | |
| 
 | |
|         if (!isset($projectID) || !isset($voteType)) {
 | |
|             $result = ['type' => 'error', 'msg' => 'Es ist ein unbekannter Fehler aufgetreten.'];
 | |
|             echo json_encode($result);
 | |
|             exit;
 | |
|         }
 | |
| 
 | |
|         $projectID = intval($projectID);
 | |
|         $voteType = intval($voteType);
 | |
| 
 | |
|         if ($voteType < 0)
 | |
|             $voteType = -1;
 | |
|         else
 | |
|             $voteType = 1;
 | |
| 
 | |
|         $this->ProjectsModel->addVote($projectID, $_SESSION['user']['ID'], $voteType);
 | |
|         $voteCount = $this->ProjectsModel->getVoteCount($projectID);
 | |
| 
 | |
|         $result = ['type' => 'success', 'msg' => 'Vielen Dank für deine Bewertung.', 'voteCount' => $voteCount];
 | |
|         echo json_encode($result);
 | |
|     }
 | |
| }
 |