42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
|
<?php
|
||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||
|
|
||
|
class ContactModel extends CI_Model
|
||
|
{
|
||
|
|
||
|
public function __construct()
|
||
|
{
|
||
|
parent::__construct();
|
||
|
}
|
||
|
|
||
|
public function getContactMessages()
|
||
|
{
|
||
|
$results = $this->db->query('SELECT * FROM contact_messages ORDER BY isUnread DESC')->result_array();
|
||
|
$results = $this->mergeUserName($results);
|
||
|
return $results;
|
||
|
}
|
||
|
|
||
|
private function mergeUserName($results)
|
||
|
{
|
||
|
foreach ($results as $i => $result) {
|
||
|
$result['username'] = null;
|
||
|
$result['displayname'] = null;
|
||
|
if ($result['userID'] == null)
|
||
|
goto next;
|
||
|
|
||
|
$user = $this->db->query('SELECT displayname, username FROM users WHERE ID = ?', [$result['userID']])->result_array();
|
||
|
if (empty($user)) {
|
||
|
$result['userID'] = null;
|
||
|
goto next;
|
||
|
}
|
||
|
|
||
|
$user = $user[0];
|
||
|
$result['username'] = $user['username'];
|
||
|
$result['displayname'] = $user['displayname'];
|
||
|
|
||
|
next: $results[$i] = $result;
|
||
|
}
|
||
|
return $results;
|
||
|
}
|
||
|
}
|