1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

74 lines
1.8 KiB
PHP

<?php
/**
* Informatica Eindproject D4p
* 6in3, Stedelijk Gymnasium Nijmegen
* Docent: Hans de Wolf
*
* ==================
*
* Daniel Boutros,
* Christiaan Goossens,
* Jelmer Hinssen
*/
namespace Inforbank\Application\Helper;
use Inforbank\Application;
class Berichten
{
/**
* Get all messages for a user
* @return array
*/
public static function getUserBerichten()
{
$container = Application::getContainer();
$db = $container->db;
$berichten = $db->berichten->where('klantid', $container->auth->getUserID())->order('datum DESC, id DESC');
$berichtArray = array();
foreach ($berichten as $bericht) {
$datum = new \DateTime($bericht['datum']);
$datum = $datum->format('d-m-Y');
$berichtArray[] = array(
"afzender" => $bericht['afzender'],
"bericht" => $bericht['bericht'],
"datum" => $datum,
"gelezen" => $bericht['gelezen']
);
if (!$bericht['gelezen']) {
$bericht->update([
"gelezen" => true
]);
}
}
return $berichtArray;
}
/**
* Send new message
* @param int $user Klantid
* @param string $afzender String name of the sender
* @param string $bericht Message
*/
public static function newBericht($user, $afzender, $bericht)
{
$container = Application::getContainer();
$db = $container->db;
$array = array(
'klantid' => (int) $user,
'afzender' => $afzender,
'bericht' => $bericht,
'datum' => date('Y-m-d')
);
$row = $db->berichten->insert($array);
}
}