protected static function load_discount_item($id = null)
 {
     $id = mysql_real_escape_string($id);
     $item = DiscountItem::find_by_id($id);
     if ($item == null) {
         $item = new DiscountItem();
     }
     return $item;
 }
 public function index($permalink = null)
 {
     $event = self::load_event($permalink);
     $event_id = mysql_real_escape_string($event->id);
     $service_discounts = DiscountItem::find_all("discount_items.item_class = 'Service' AND services.event_id = '{$event_id}'", 'services.id ASC');
     $this->assign("event", $event);
     $this->assign("services", $event->services());
     $this->assign("service_discounts", $service_discounts);
     $this->title = "Events :: {$event->name} :: Services";
     $this->render("service/index.tpl");
 }
 public function show($permalink = null)
 {
     $event = self::load_event($permalink);
     $event_id = mysql_real_escape_string($event->id);
     $ticket_discounts = DiscountItem::find_all("discount_items.item_class = 'EventTicket' AND event_tickets.event_id = '{$event_id}'", 'event_tickets.id ASC');
     $this->assign("event", $event);
     $this->assign("tickets", $event->tickets());
     $this->assign("ticket_discounts", $ticket_discounts);
     $this->title = "Events :: " . $event->name;
     $this->render("event/show.tpl");
 }
 protected static function load_discount_item($discount_id = null, $item_id = null)
 {
     $discount_id = mysql_real_escape_string($discount_id);
     $item_id = mysql_real_escape_string($item_id);
     $item = DiscountItem::find("discount_items.item_id='{$item_id}' and discount_items.discount_id='{$discount_id}'");
     if ($item == null) {
         $item = new DiscountItem();
     }
     return $item;
 }
 public function add_item($obj)
 {
     return DiscountItem::create_from_object($obj, $this);
 }
 public static function create_from_object($obj, $discount)
 {
     if (!is_a($obj, 'Service') || !is_a($obj, 'EventTicket')) {
         return false;
     }
     $item = new DiscountItem();
     $item->item_id = $obj->id;
     $item->item_class = get_class($obj);
     $item->discount_id = $discount->id;
     $result = $item->save();
     if (!$result) {
         return false;
     }
     return $item;
 }