Created
November 24, 2014 12:26
-
-
Save YordiLorenzo/2afb6f2bc31565a4767a to your computer and use it in GitHub Desktop.
Portfolio - Art Explorer sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Class for creating an Application | |
| */ | |
| <?php | |
| require_once 'includes/config.inc.php'; | |
| require_once 'database.class.php'; | |
| class Application | |
| { | |
| private $APPLICATION_NAME; | |
| private $APPLICATION_PUBLISH_DATE; | |
| private $APPLICATION_UPDATE_DATE = array(); | |
| private $USER_AGENT; | |
| private $ERRORS = array(); | |
| private $db; | |
| function __construct($name, $publish, $update) | |
| { | |
| $this->APPLICATION_NAME = $name; | |
| $this->APPLICATION_PUBLISH_DATE = $publish; | |
| $this->APPLICATION_UPDATE_DATE = array_push($this->APPLICATION_UPDATE_DATE, $update); | |
| $this->db = new Database(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
| } | |
| private $nav = array("index.php", "map.php", "user-management.php"); | |
| public function getName() | |
| { | |
| return $this->APPLICATION_NAME; | |
| } | |
| public function getPublishDate() | |
| { | |
| return $this->APPLICATION_PUBLISH_DATE; | |
| } | |
| public function getUpdateDate() | |
| { | |
| return '*no date availble*' ; | |
| } | |
| public function getUserAgent() | |
| { | |
| $temp = $_SERVER['HTTP_USER_AGENT']; | |
| if(strstr($temp, 'MSIE')){$this->USER_AGENT = 'Internet Explorer';} | |
| elseif(strstr($temp, 'Opera')){$this->USER_AGENT = 'Opera';} | |
| elseif(strstr($temp, 'Firefox')){$this->USER_AGENT = 'Mozilla Firefox';} | |
| elseif(strstr($temp, 'Chrome')){$this->USER_AGENT = 'Google Chrome';} | |
| else{$this->USER_AGENT = "Different";} | |
| return $this->USER_AGENT; | |
| } | |
| //Create navigation variable (dynamic) | |
| public function nav() | |
| { | |
| //Database query | |
| $this->db->query("SELECT * FROM navigationRoutes"); | |
| //Database resultset | |
| $row = $this->db->resultset(); | |
| $navigation = ''; | |
| for($i = 0; $i < count($row); $i++) | |
| { | |
| $navigation = $navigation."<a href=".$row[$i]['permalink']."><div class='nav_item'> | |
| ".$row[$i]['name']." | |
| </div></a>"; | |
| } | |
| return $navigation; | |
| } | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * File to bootstrap the complete application and instantiate a new View | |
| */ | |
| <?php | |
| ob_start(); | |
| include 'includes/config.inc.php'; | |
| include 'classes/database.class.php'; | |
| include 'classes/application.class.php'; | |
| include 'classes/view.class.php'; | |
| include 'classes/user.class.php'; | |
| include 'classes/google.class.php'; | |
| include 'classes/articles.class.php'; | |
| include 'classes/statics.class.php'; | |
| //New user | |
| $user = new User(); | |
| $statics = new Statics(); | |
| //Instantiate a new database connection | |
| $db = new Database(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
| //First you create a new application with instantiatng the Application class | |
| $application = new Application("What do I see", "7-10-13", "Never updated"); | |
| //Confirm that user is loged in | |
| $user->confirmStatus(); | |
| //Then we create a new view, with naviagtion, content, username and userimage | |
| $articles = new Articles(); | |
| $view = new View("STATISTICS_VIEW", "Startpagina", "There is no content", $_SESSION['username'], $_SESSION['userPic'], $application->nav()); | |
| //Now we created a view inside our application in the future we will have all our views available inside the application class and count al //the created views. | |
| //Now we can get values from the created view and the application class | |
| $statics->parseInfo(); | |
| $statics->parseModel(); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Class for getting statistics of API registered devices | |
| */ | |
| <?php | |
| class Statics | |
| { | |
| private $db; | |
| public function __construct(){ | |
| $this->db = new Database(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
| } | |
| public function parseInfo(){ | |
| $dates = array(); | |
| $devices = array(); | |
| $markers = array(); | |
| $currentDate = date('Y-m-d'); | |
| $currentTime = date('H:i:s'); | |
| $dates[0] = $currentDate; | |
| for($i = 1; $i < 7; $i++){ | |
| $dates[$i] = date('Y-m-d', strtotime($currentDate .' -'.$i.' day')); | |
| } | |
| for($e = 0; $e < 7; $e++) | |
| { | |
| $day[$e] = date('Y-m-d', strtotime($dates[$e])); | |
| $this->db->query("select id from `applicationDevices` where `ADDED` < '".$day[$e]." ".$currentTime."' "); | |
| //$this->db->query("select id from `applicationDevices` where `ADDED` between '".$day[$e]." 00:00:01' and '".$day[$e]." 23:59:59'"); | |
| $this->db->execute(); | |
| $devices[$e] = $this->db->rowCount(); | |
| $this->db->query("SELECT id FROM `artObjects` WHERE `timestamp` < '".$day[$e]." ".$currentTime."'"); | |
| $this->db->execute(); | |
| $markers[$e] = $this->db->rowCount(); | |
| } | |
| $fileString = '[ | |
| {"day" : "'.date("D", strtotime($dates[0])).'", "devices" : "'.$devices[0].'", "markers" : "'.$markers[0].'"}, | |
| {"day" : "'.date("D", strtotime($dates[1])).'", "devices" : "'.$devices[1].'", "markers" : "'.$markers[1].'"}, | |
| {"day" : "'.date("D", strtotime($dates[2])).'", "devices" : "'.$devices[2].'", "markers" : "'.$markers[2].'"}, | |
| {"day" : "'.date("D", strtotime($dates[3])).'", "devices" : "'.$devices[3].'", "markers" : "'.$markers[3].'"}, | |
| {"day" : "'.date("D", strtotime($dates[4])).'", "devices" : "'.$devices[4].'", "markers" : "'.$markers[4].'"}, | |
| {"day" : "'.date("D", strtotime($dates[5])).'", "devices" : "'.$devices[5].'", "markers" : "'.$markers[5].'"}, | |
| {"day" : "'.date("D", strtotime($dates[6])).'", "devices" : "'.$devices[6].'", "markers" : "'.$markers[6].'"} | |
| ]'; | |
| $handle = fopen('js/dates.json', 'w'); | |
| fwrite($handle, $fileString); | |
| fclose($handle); | |
| return true; | |
| } | |
| public function parseModel(){ | |
| $this->db->query("SELECT DISTINCT OS from applicationDevices"); | |
| $this->db->execute(); | |
| $result = $this->db->resultSet(); | |
| $count = $this->db->rowCount(); | |
| $i = -1; | |
| $fileString = '['; | |
| foreach($result as $row) | |
| { | |
| $i += 1; | |
| $os = '%'.$row['OS'].'%'; // Formats the OS to the right string | |
| $this->db->query("SELECT id FROM applicationDevices WHERE OS LIKE :os"); | |
| $this->db->bind(':os', $os); | |
| $this->db->execute(); | |
| $amount = $this->db->rowCount(); | |
| if($i !== ($count-1))$fileString .= '{"model" : "'.$row["OS"].'", "amount" : "'.$amount.'"},'; | |
| if($i === ($count-1))$fileString .= '{"model" : "'.$row["OS"].'", "amount" : "'.$amount.'"}'; | |
| } | |
| $fileString .= ']'; | |
| $handle = fopen('js/models.json', 'w'); | |
| fwrite($handle, $fileString); | |
| fclose($handle); | |
| return true; | |
| } | |
| public function countMarkers(){ | |
| $this->db->query("SELECT id FROM `artObjects`"); | |
| $this->db->execute(); | |
| return $this->db->rowCount(); | |
| } | |
| public function countUsers(){ | |
| $this->db->query("SELECT id FROM users"); | |
| $this->db->execute(); | |
| return $this->db->rowCount(); | |
| } | |
| public function countDevices(){ | |
| $this->db->query("SELECT id FROM applicationDevices"); | |
| $this->db->execute(); | |
| return $this->db->rowCount(); | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment