Ejemplo n.º 1
0
 /**
  * Retrieves all orders (if the authenticated user is an admin) or orders 
  * of a certain customer (if the authenticated user is a customer) from the 
  * database as well as their products. Displays the order list.
  */
 public static function get_orders()
 {
     $orders = array();
     $user = self::get_user_logged_in();
     if ($user) {
         if ($user->username == 'admin') {
             $orders = Orders::findAll();
         } else {
             $orders = Orders::findByUser($user->id);
         }
     }
     foreach ($orders as $order) {
         $order_products = OrderProduct::findByOrder($order->id);
         foreach ($order_products as $index => $order_product) {
             $order->products[$index] = json_decode($order_product->product_info);
         }
         $order->user_info = json_decode($order->user_info);
     }
     View::make('order/list.html', array('orders' => $orders));
 }