Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
class Stats {
//Set global
private $config;
private $mysqli;
private $userId;
//Magic function that is called when the class is created
//Creates the required objects for the class to function
public function __construct(){
//Load the required files
require_once('config.php');
require_once('db.class.php');
//Create the required objects
$this->config = generateConfig();
$this->mysqli = new Db($this->config['db_host'], $this->config['db_user'], $this->config['db_pass'], $this->config['db_db']);
//Get the userId
if (session_status() == PHP_SESSION_NONE) session_start();
$this->userId = $_SESSION['userId'];
}
/**
Function that returns the different Health Statistics
@param output Specifies the output type of the return array
@return Returns the return array containing all the stats and the users awnser
**/
public function getStats($output = 'array'){
//Get all the stats that are active
$this->db->where('active', 1);
$stats = $this->db->get('health_stats');
//Create return array
$return = array();
//Loop through the stats and fill return array for each stat
foreach($stats as $key => $stat){
$return[$key]['name'] = $stat['name'];
//Get the awnser belonging to the stat and user
$this->db->where('userId', $this->userId);
$this->db->where('statId', $stat['statId']);
$awnser = $this->db->get('health_stats_awnser');
$return[$key]['value'] = $awnser[0]['value'];
}
//Output the return array
switch($output) {
case 'array': return $return;
case 'json': return json_encode($return);
default: return $return;
}
}
/**
Sets an awnser for a stat
@param statId Id of the stat the awnser belongs to
@param data Array containing the insert data for the awnser
@return Return true if succesfull
**/
public function setStatAwnser($statId, $data){
//Create the complete
$data['statId'] = $statId;
$data['userId'] = $this->userId;
//Check if stat already exists
$this->db->where('statId', $statId);
$this->db->where('userId', $this->userId);
$this->db->where('archived', 0);
$awnser = $this->db->get('health_stats_awnser');
if(empty($stat)){
//Insert the awnser into the table
$this->db->insert('health_stats_awnser', $data);
}
else {
//Archive the old awnser
$this->db->where('awnserId', $awnser[0]['awnserId']);
$this->db->update('health_stats_awnser', array('archived' => 0));
//Insert the new awnser
$this->db->insert('health_stats_awnser', $data);
}
//Succesfull
return true;
}
}
?>
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team