Exemple #1
0
 public static function generateTable($array)
 {
     if (is_array($array)) {
         $i = 0;
         $find = 'id';
         // ID should be generated as links
         $htmlTABLE = '<table><tr>';
         // Get table headings
         foreach ($array as $key => $innerArray) {
             if (is_array($innerArray)) {
                 foreach ($innerArray as $attribute => $value) {
                     if (strpos($attribute, $find) !== false) {
                         $htmlTABLE .= '<th>Action</th>';
                     } else {
                         $clean = HTML::cleanAttribute($attribute);
                         $htmlTABLE .= '<th>' . $clean . '</th>';
                     }
                 }
                 if (++$i == 1) {
                     break;
                 }
             }
         }
         $htmlTABLE .= '</tr>';
         // Get the rest of the table
         foreach ($array as $key => $innerArray) {
             if (is_array($innerArray)) {
                 $htmlTABLE .= '<tr>';
                 foreach ($innerArray as $attribute => $value) {
                     if (strpos($attribute, $find) !== false) {
                         $href = 'index.php?page=car&id=' . $value;
                         $htmlTABLE .= '<td>' . Link::newLink('View', $href, '_self') . '</td>';
                     } else {
                         $htmlTABLE .= '<td>' . $value . '</td>';
                     }
                 }
                 $htmlTABLE .= '</tr>';
             }
         }
         $htmlTABLE .= '</table>';
         return $htmlTABLE;
     }
 }
Exemple #2
0
 public function get($array = "")
 {
     if (is_array($array) && !empty($array)) {
         if (count($array) == count($array, COUNT_RECURSIVE)) {
             // If not multidimensional, it's most likely asking
             // for a single car
             echo Link::newLink('Return', 'index.php', '_self');
             echo '<br /><br />';
             // Display car details
             CarView::viewCarDetails($array);
         } else {
             // If it's multidimensional, it's most likely asking for
             // all cars
             // Show all cars
             CarView::viewCars($array);
             // Show a form to add a new car
             CarView::addNewCar();
         }
     } else {
         // Show form if no cars stored in the session
         CarView::addNewCar();
     }
 }