source: Dev/trunk/getInfo.php @ 186

Last change on this file since 186 was 186, checked in by jkraaijeveld, 13 years ago

Implemented lazy evaluation.

  • Initially, references to other database objects are now given as an ID rather than an object.
  • Every model class now has an evaluate() function, which gets all the objects that object has references to. Returns true if it got all the values correctly, false if there are invalid references.
  • Every connector now first evaluates an object before storing, to make sure only objects with valid references get stored.
File size: 3.6 KB
Line 
1<?php
2
3require 'classes/master.php'; //should be at top of every page
4
5if (isset($_POST['uid']) && isset($_POST['type'])) {
6    if (!empty($_POST['uid']) && !empty($_POST['type'])) {
7        $uid = $_POST['uid'];
8        $type = $_POST['type'];
9    } else {
10//$errors[] = "No uid passed!";
11        return;
12    }
13} else {
14//$errors[] = "Wrong call, no uid property in POST data!";
15    return;
16}
17
18$dbi = new DatabaseInterface();
19
20$results = $dbi->get($type, array("uid" => $uid));
21
22if (count($results) > 0) {      // check if DB object exists and assign it to variable
23    if ($results[0] != null) {
24        $returnString = "";
25        $result = $results[0];
26    } else
27        return;
28} else
29    return;
30
31// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
32// Note: the next part needs to be converted to JSON operation, so that the javascript can easily handle any style changes to the information retrieved. This implementation is just silly.
33// Basic idea: return a JSON array of property: value pairs, then let javascript loop through these properties and format them suitably. This is both more flexible and easier to adjust, as well as resulting in smaller packets.
34// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
35
36switch ($type) {
37    case "Session":
38        $returnString .= "<span class='property'>Title: </span><span class='value'>$result->title</span>";
39        $returnString .= "<span class='property'>Created: </span><span class='value'>" . $result->datetime->format("H:i:s, d-m-Y") . " by " . $result->creator->name . "</span>";
40        $cS = 0; $cD = 0; $cA = 0;
41        foreach ($result->pipeline as $step) {
42            switch (get_class($step)){
43                case "Survey":
44                    $cS++;
45                    break;
46                case "Application":
47                    $cA++;
48                    break;
49                case "Dashboard":
50                    $cD++;
51                    break;
52                default:
53                    //derp?
54                    break;
55            }
56        }
57        $returnString .= "<span class='property'>Number of steps: </span><span class='value'><ul style='list-style-type: none;'><li style='margin-left: -40px;'>$cS Surveys<li style='margin-left: -40px;'>$cA Applications<li style='margin-left: -40px;'>$cD Dashboards</ul></span>";
58        break;
59    case "Survey":
60        $returnString .= "<span class='property'>Title: </span><span class='value'>$result->title</span>";
61        $returnString .= "<span class='property'>Creator: </span><span class='value'>LOLOL ME!!!</span>";
62        $qCount = 0;
63        $qCount = count($result->questions);
64        $returnString .= "<span class='property'>Questions: </span><span class='value'>$qCount</span>";
65        $returnString .= "<span class='property'>Description: </span><span class='value'>$result->description</span>";
66        break;
67    case "Application":
68        $returnString .= "<span class='property'>Title: </span><span class='value'>$result->title</span>";
69        $returnString .= "<span class='property'>Path: </span><span class='value'>C:/folder_of_awesomeness/epicgame.exe</span>";
70        $returnString .= "<span class='property'>Description: </span><span class='value'>$result->description</span>";
71        break;
72    case "Dashboard":
73        break;
74    case "Respondent":
75        break;
76    case "Question":
77        break;
78    case "Answer":
79        break;
80    default:
81        break;
82}
83
84echo $returnString;
85?>
Note: See TracBrowser for help on using the repository browser.