From b5736e81214240f3123ad1781406ab992efb9949 Mon Sep 17 00:00:00 2001 From: "DESKTOP-BC3NEC6\\chiefsoft" Date: Fri, 17 Feb 2023 23:32:05 -0500 Subject: [PATCH] updates --- app/Config/Routes.php | 2 +- app/Controllers/Myfituser.php | 5 +++ app/Models/baseModel.php | 65 +++++++++++++++++-------------- app/Models/myfitPricing.php | 2 +- app/Models/myfitTracking.php | 37 ++++++++++++++++++ app/Models/myfitUserReminders.php | 19 ++++++++- app/Models/userAccess.php | 1 + 7 files changed, 99 insertions(+), 32 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7e3b43d..4210bf7 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -64,7 +64,7 @@ $routes->get('/en/desktop/api/v2/myfituser/profile', 'Myfituser::users'); $routes->get('/en/desktop/api/v2/myfituser/myfeed', 'Myfituser::users'); //Tracking -$routes->get('/en/desktop/api/v2/myfituser/tracking', 'Myfituser::users'); +$routes->post('/en/desktop/api/v2/myfituser/tracking', 'Myfituser::users'); $routes->get('/en/desktop/api/v2/myfituser/trackcategory', 'Myfituser::users'); // REMINDERS ------------------------------------------------------------- diff --git a/app/Controllers/Myfituser.php b/app/Controllers/Myfituser.php index 677c3eb..ea58ee7 100644 --- a/app/Controllers/Myfituser.php +++ b/app/Controllers/Myfituser.php @@ -59,6 +59,7 @@ class Myfituser extends BaseController 'resources' => ['GET'], 'trackcategory' => ['GET'], 'resetpass' => ['POST'], + 'tracking' => ['POST'], ]; $res1 = []; @@ -133,6 +134,10 @@ class Myfituser extends BaseController $myfitTracking = new \App\Models\myfitTracking(); $res1 = $myfitTracking->getTrackCategory(); break; + case 'tracking': + $myfitTracking = new \App\Models\myfitTracking(); + $res1 = $myfitTracking->trackEngine($raw_array); + break; } return $this->response->setJson($res1); diff --git a/app/Models/baseModel.php b/app/Models/baseModel.php index 5cfe9e6..768f786 100644 --- a/app/Models/baseModel.php +++ b/app/Models/baseModel.php @@ -16,41 +16,48 @@ class baseModel extends Model public function insert_db($inserDataArray, $insertTable) { - foreach ($inserDataArray as $arr) { - $ic = 0; - $fl_part = ''; - $val_part = ''; - $sqlQ = ''; - $fields = array_keys($arr); - foreach ($fields as $field) { - $fl_part .= $ic > 0 ? ',' : ''; - $fl_part .= $field; + $insert_id=0; + $ic = 0; + $fl_part = ''; + $val_part = ''; + $sqlQ = ''; + $fields = array_keys($inserDataArray); + foreach ($fields as $field) { + $fl_part .= $ic > 0 ? ',' : ''; + $fl_part .= $field; - $val_part .= $ic > 0 ? ',' : ''; - $val_part .= "'" . $arr[$field] . "'"; - $ic++; - } - $sqlQ = "INSERT INTO $insertTable ($fl_part) VALUES ($val_part)"; - $query = $this->db->query($sqlQ); + $val_part .= $ic > 0 ? ',' : ''; + $val_part .= "'" . $inserDataArray[$field] . "'"; + $ic++; } - return 0; + $sqlQ = "INSERT INTO $insertTable ($fl_part) VALUES ($val_part)"; + $query = $this->db->query($sqlQ); + $insert_id = $this->db->insert_id(); + return $insert_id; } public function update_db($UupdateDataArray,$whereAray, $updateTable) { - foreach ($UupdateDataArray as $arr) { - $ic = 0; - $UP_part = ''; - $val_part = ''; - $sqlQ = ''; - $fields = array_keys($arr); - foreach ($fields as $field) { - $UP_part .= $ic > 0 ? ',' : ''; - $UP_part .= $field="'" . $arr[$field] . "'"; - $ic++; - } - $sqlQ = "UPDATE $updateTable SET $UP_part WHERE ($val_part)"; - $query = $this->db->query($sqlQ); + $ic = 0; + $UP_part = ''; + $val_part = ''; + $sqlQ = ''; + $fields = array_keys($UupdateDataArray); + foreach ($fields as $field) { + $UP_part .= $ic > 0 ? ',' : ''; + $UP_part .= $field="'" . $UupdateDataArray[$field] . "'"; + $ic++; } + + $ic = 0; + $fields = array_keys($whereAray); + foreach ($fields as $field) { + $val_part .= $ic > 0 ? ' AND ' : ' WHERE '; + $val_part .= $field."='" . $whereAray[$field] . "'"; + $ic++; + } + + $sqlQ = "UPDATE $updateTable SET $UP_part $val_part"; + $query = $this->db->query($sqlQ); return 0; } } diff --git a/app/Models/myfitPricing.php b/app/Models/myfitPricing.php index c2359b2..e35af2e 100644 --- a/app/Models/myfitPricing.php +++ b/app/Models/myfitPricing.php @@ -31,7 +31,7 @@ class myfitPricing extends baseModel ], [ 'icon' => '/static/media/unlimited.png', - 'title' => 'Unlimited', + 'title' => 'Gold', 'text' => 'Professionals here.', 'price' => '$7.99/m', 'price_anual' => '$55/y', diff --git a/app/Models/myfitTracking.php b/app/Models/myfitTracking.php index 62de09b..f23e394 100644 --- a/app/Models/myfitTracking.php +++ b/app/Models/myfitTracking.php @@ -43,4 +43,41 @@ class myfitTracking extends baseModel { return []; } + + public function trackEngine($in){ + $insert_id=0; + switch($in['code']){ + case "WEIGT": + $inData = [ + 'member_id'=>$in['member_id'], + 'val1'=>$in['value'], + 'munit'=>$in['unit'], + ]; + $insert_id = $this->insert_db($inData, 'members_tracking_summary'); + break; + } + + return ['insert_id'=> $insert_id, 'raw_data'=>$in ]; + } } + +/* +------- TRACKING NOW + + CREATE TABLE members_tracking_summary ( + id SERIAL, + uuid UUID DEFAULT (gen_random_uuid()), + code VARCHAR(5) REFERENCES tracking_category(code) NOT NULL, + val1 VARCHAR(25), + val2 VARCHAR(25), + munit VARCHAR(15), + track_uuid VARCHAR(100), + added timestamp without time zone DEFAULT now(), + loc INET + ); + +ALTER TABLE ONLY members_tracking_summary + ADD CONSTRAINT members_tracking_summary_id_key UNIQUE (id) +; + +*/ diff --git a/app/Models/myfitUserReminders.php b/app/Models/myfitUserReminders.php index 5a8f70b..c3e56a3 100644 --- a/app/Models/myfitUserReminders.php +++ b/app/Models/myfitUserReminders.php @@ -124,14 +124,31 @@ class myfitUserReminders extends baseModel $end_date = $in['end_date']; $notes = $in['notes']; + $inData = [ + 'description'=>$description, + 'category'=>$category, + 'mode'=>$mode, + 'start_date'=>$start_date, + 'end_date'=>$end_date + ]; + $inWhere=[ + 'member_id' =>$member_id, + 'uuid'=> $uuid + ]; + $ret11 = $this->update_db($inData,$inWhere, 'members_reminders'); + $sqlQ = "SELECT * FROM members_reminders WHERE member_id = $member_id AND uuid ='$uuid' "; $query = $this->db->query($sqlQ); + $updated_reminder = $query->getResultArray(); - return []; + return [ + 'updated_reminder' => $updated_reminder + ]; } } /* +public function update_db($UupdateDataArray,$whereAray, $updateTable) $sql = "INSERT INTO table (title) VALUES('" . $db->escapeString($title) . "')"; */ diff --git a/app/Models/userAccess.php b/app/Models/userAccess.php index ffca645..1cc3148 100644 --- a/app/Models/userAccess.php +++ b/app/Models/userAccess.php @@ -42,6 +42,7 @@ class userAccess extends baseModel 'session_token' => $this->generateSession($member_id), 'member_id' => $member_id, 'member_uuid' => $member_uid, + 'guid' => $member_uid, 'profile' => $data['profile_data'][0], 'settings' => [], 'layout'=> ['dash'=>$computedDash],