137 lines
3.8 KiB
PHP
137 lines
3.8 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class myfitUserReminders extends Model
|
|
{
|
|
protected $db;
|
|
public $con_name = 'mermsemr';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db = \Config\Database::connect($this->con_name);
|
|
}
|
|
|
|
public function readReminders($in)
|
|
{
|
|
$member_id =
|
|
isset($in['member_id']) && $in['member_id'] > 0
|
|
? $in['member_id']
|
|
: 0;
|
|
$reminder_category = $this->reminderCategory(); // [];
|
|
$sqlQ = "SELECT * FROM members_reminders WHERE member_id = $member_id";
|
|
$query = $this->db->query($sqlQ);
|
|
$data['reminders_data'] = $query->getResultArray();
|
|
return $inx = [
|
|
'reminder_category' => $reminder_category,
|
|
'reminders' => $data['reminders_data'],
|
|
'status' => 1,
|
|
'raw_data' => $in,
|
|
];
|
|
}
|
|
|
|
public function reminderCategory()
|
|
{
|
|
$sqlQ =
|
|
'SELECT uuid,category,code FROM reminder_category ORDER BY category';
|
|
$query = $this->db->query($sqlQ);
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
public function reminderMode()
|
|
{
|
|
$sqlQ = 'SELECT uuid,mode,code FROM reminder_modes';
|
|
$query = $this->db->query($sqlQ);
|
|
return $query->getResultArray();
|
|
}
|
|
|
|
public function reminderAddEdit($in)
|
|
{
|
|
/*
|
|
{
|
|
'member_id': 1,
|
|
'description': 'This is a test',
|
|
'category': 'APPT',
|
|
'mode' : 'SMS',
|
|
'start_date':'2022-01-01',
|
|
'end_date': '2022-01-01',
|
|
'notes':'This is te notes for the page '
|
|
}
|
|
|
|
*/
|
|
$in_test = [
|
|
'member_id' => 1,
|
|
'description' => 'This is a test',
|
|
'category' => 'APPT',
|
|
'mode' => 'SMS',
|
|
'start_date' => '2022-01-01',
|
|
'end_date' => '2022-01-01',
|
|
'notes' => 'This is te notes for the page ',
|
|
];
|
|
|
|
if (isset($in['member_id']) && $in['member_id'] > 0) {
|
|
if (isset($in['uuid']) && trim($in['uuid']) != '') {
|
|
return $this->editReminder($in);
|
|
} else {
|
|
return $this->addReminder($in);
|
|
}
|
|
}
|
|
return [
|
|
'error' => 'Invalid call to reminder',
|
|
'reason' => 'details commin in version 3',
|
|
];
|
|
}
|
|
|
|
private function addReminder($in)
|
|
{
|
|
$member_id = $in['member_id'];
|
|
$description = $in['description'];
|
|
$category = $in['category'];
|
|
$mode = $in['mode'];
|
|
$start_date = $in['start_date'];
|
|
$end_date = $in['end_date'];
|
|
$notes = $in['notes'];
|
|
|
|
// Create Rem
|
|
$sqlQ = "INSERT INTO members_reminders ( member_id,
|
|
description, category, mode, start_date, end_date,notes )
|
|
VALUES ($member_id,'$description','$category', '$mode','$start_date', '$end_date','$notes')";
|
|
if ($this->db->query($sqlQ)) {
|
|
$insert_id = $this->db->insertID();
|
|
|
|
$sqlQ = "SELECT * FROM members_reminders WHERE id = $insert_id ";
|
|
$query = $this->db->query($sqlQ);
|
|
$rem_data = $query->getResultArray();
|
|
} else {
|
|
$insert_id = 0;
|
|
$rem_data = [];
|
|
}
|
|
|
|
return ['insert_id' => $insert_id, 'new_data' => $rem_data];
|
|
}
|
|
|
|
private function editReminder($in)
|
|
{
|
|
$uuid = trim($in['uuid']);
|
|
$member_id = $in['member_id'];
|
|
$description = $in['description'];
|
|
$category = $in['category'];
|
|
$mode = $in['mode'];
|
|
$start_date = $in['start_date'];
|
|
$end_date = $in['end_date'];
|
|
$notes = $in['notes'];
|
|
|
|
$sqlQ = "SELECT * FROM members_reminders WHERE member_id = $member_id AND uuid ='$uuid' ";
|
|
$query = $this->db->query($sqlQ);
|
|
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/*
|
|
$sql = "INSERT INTO table (title) VALUES('" . $db->escapeString($title) . "')";
|
|
|
|
*/
|