Ignore:
Timestamp:
11/22/11 18:10:47 (13 years ago)
Author:
fpvanagthoven
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/returnStep.php

    r163 r165  
    1212if (isset($_POST['uids'])) {
    1313    if (!empty($_POST['uids'])) {
    14         $uids = $_POST['uids'];
     14        $sUids = $_POST['uids'];    // string uids
    1515    } else {
    1616        echo "Invalid UIDs passed!";
     
    2121}
    2222
    23 $sUids = explode(",", $uids);
     23$sTypes = "unknown";    // string types
     24if (isset($_POST['types'])) {
     25    if (!empty($_POST['types'])) {
     26        $sTypes = $_POST['types'];
     27    }
     28}
     29
     30$uids = explode(",", $sUids);   // array uids
     31if ($sTypes != "unknown") {
     32    $types = explode(",", $sTypes);
     33}
    2434$response = "";
    2535$dbi = new DatabaseInterface();
    26 foreach ($sUids as $uid) {
    27     $response .= processUid($uid);
     36
     37if (isset($types)) {
     38    for ($i = 0; $i < count($uids); $i++) {
     39        $response .= processUid($uids[$i], $types[$i]);
     40    }
     41} else {
     42    foreach ($uids as $uid) {
     43        $response .= processUid($uid);
     44    }
    2845}
     46
     47
    2948
    3049echo $response;
     
    3655 */
    3756
     57function processUid($uid, $type = null) {
     58    $dbi = new DatabaseInterface();
    3859
     60    if ($uid == "divider") {    //a divider has been requested instead of a displaystep
     61        $responsePart = '<div class="divider"></div>';
     62        return $responsePart;
     63    }
    3964
    40 function processUid($uid) {
    41         $dbi = new DatabaseInterface();
    42         if ($uid == "divider") {    //a divider has been requested instead of a displaystep
    43             $responsePart = '<div class="divider"></div>';
    44             return $responsePart;
    45         } else {        // an actual step has been requested.
    46            
    47 //Check in order: survey, application, dashboard.
    48             $result = null;
    49             $resultType = null;
    50             $surveys = $dbi->get("Survey", array("uid" => $uid));
    51             if (count($surveys) > 0) {
    52                 if ($surveys[0] != null) {
    53                     // A survey exists with the given UID!
    54                     $result = $surveys[0];
    55                     $resultType = "Survey";
     65    $result = null;
     66    $resultType = null;
     67
     68    if ($type != null) {    // Als er een type is gespecificeerd
     69        $resultType = $type;
     70        $results = $dbi->get($type, array("uid" => $uid));
     71        if (count($results) > 0) {
     72            $result = $results[0];
     73        }
     74    }
     75
     76    // Als er geen type is gespecificeerd, doorloop de queries in de volgorde: Survey, Application, Dashboard
     77    else {
     78        $surveys = $dbi->get("Survey", array("uid" => $uid));
     79        if (count($surveys) > 0) {
     80            if ($surveys[0] != null) {
     81                // A survey exists with the given UID!
     82                $result = $surveys[0];
     83                $resultType = "Survey";
     84            }
     85        }
     86
     87        if ($result == null) {
     88            $applications = $dbi->get("Application", array("uid" => $uid));
     89            if (count($applications) > 0) {
     90                if ($applications[0] != null) {
     91                    // An application exists with the given UID!
     92                    $result = $applications[0];
     93                    $resultType = "Application";
    5694                }
    5795            }
     96        }
    5897
    59             if ($result == null) {
    60                 $applications = $dbi->get("Application", array("uid" => $uid));
    61                 if (count($applications) > 0) {
    62                     if ($applications[0] != null) {
    63                         // An application exists with the given UID!
    64                         $result = $applications[0];
    65                         $resultType = "Application";
    66                     }
     98        if ($result == null) {
     99            $dashboards = $dbi->get("Dashboard", array("uid" => $uid));
     100            if (count($dashboards) > 0) {
     101                if ($dashboards[0] != null) {
     102                    // A dashboard exists with the given UID!
     103                    $result = $dashboards[0];
     104                    $resultType = "Dashboard";
    67105                }
    68106            }
    69 
    70             if ($result == null) {
    71                 $dashboards = $dbi->get("Dashboard", array("uid" => $uid));
    72                 if (count($dashboards) > 0) {
    73                     if ($dashboards[0] != null) {
    74                         // A dashboard exists with the given UID!
    75                         $result = $dashboards[0];
    76                         $resultType = "Dashboard";
    77                     }
    78                 }
    79             }
     107        }
     108    }
    80109
    81110// If result is still null at this point, the passed UID does not refer to an existing object!
    82             if ($result == null || $resultType == null) {
    83                 echo "Non-existing UID passed!";
    84             } else {
     111    if ($result == null || $resultType == null) {
     112        echo "Non-existing UID passed!";
     113    } else {
    85114
    86                 // set relevant variables based on the type and properties of the step in question (currently stored in $result)
    87                 switch (strtolower($resultType)) {
    88                     case "survey":
    89                         $imageURL = "images/icons/survey.png";
    90                         break;
    91                     case "dashboard":
    92                         $imageURL = "images/icons/dashboard.png";
    93                         break;
    94                     case "application":
    95                         $imageURL = "images/icons/application.png";
    96                         break;
    97                     default:
    98                         $imageURL = "images/icons/unknowntype.png";
    99                         break;
    100                 }
     115        // set relevant variables based on the type and properties of the step in question (currently stored in $result)
     116        switch (strtolower($resultType)) {
     117            case "survey":
     118                $imageURL = "images/icons/survey.png";
     119                break;
     120            case "dashboard":
     121                $imageURL = "images/icons/dashboard.png";
     122                break;
     123            case "application":
     124                $imageURL = "images/icons/application.png";
     125                break;
     126            default:
     127                $imageURL = "images/icons/unknowntype.png";
     128                break;
     129        }
    101130
    102131//echo out the HTML markup
    103                 $responsePart = '<div class="displayStep" id="' . $result->uid . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . $result->title . '</div>';
    104                 return $responsePart;
    105             }
    106         }
    107    
     132        $responsePart = '<div class="displayStep" id="' . $result->uid . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . $result->title . '</div>';
     133        return $responsePart;
     134    }
    108135}
    109136
Note: See TracChangeset for help on using the changeset viewer.