Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/application/models/MessageModel.php

35 lines
1.8 KiB
PHP
Raw Normal View History

2018-10-16 16:28:42 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class MessageModel extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function getFeedbackMessages() {
return $this->db->query('SELECT feedback.*, feedback_states.name feedbackStateName, feedback_states.displayname feedbackStateDisplayname, users.username username, users.displayname userDisplayname, supporter.username supporterUsername, supporter.displayname supporterDisplayname FROM feedback LEFT JOIN feedback_states ON feedback.feedbackState = feedback_states.ID LEFT JOIN users ON feedback.userID = users.ID LEFT JOIN users supporter ON feedback.supporterID = supporter.ID ORDER BY feedbackState ASC, datetime DESC')->result_array();
}
public function setFeedbackSupporter($feedbackID, $userID, $feedbackState = 1) {
if($feedbackState == 0)
$feedbackState = 1;
$this->db->query('UPDATE feedback SET feedbackState = ?, supporterID = ?, lastStateUpdate = NOW() WHERE ID = ?', [$feedbackState, $userID, $feedbackID]);
}
public function updateState($feedbackID, $userID, $feedbackState) {
$this->db->query('UPDATE feedback SET feedbackState = (SELECT ID FROM feedback_states WHERE name = ?), lastStateUpdate = NOW() WHERE ID = ? AND supporterID = ?', [$feedbackState, $feedbackID, $userID]);
}
public function archiveFeedback($feedbackID) {
$data = $this->db->query('SELECT * FROM feedback WHERE ID = ? AND feedbackState >= 10', [$feedbackID])->result_array();
if(!empty($data)) {
$this->db->query('INSERT INTO feedback_archive (ID, page, message, datetime, anonymous, userID, email, feedbackState, feedbackStatusMessage, supporterID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $data[0]);
}
return !empty($data);
}
}