Ejemplo n.º 1
0
 public static function getMapSeats($fileName, array $seats = array())
 {
     $result = array();
     try {
         $dom = Map::factory()->loadFile($fileName)->getDomInstance();
         $gTag = $dom->getElementsByTagName('g');
         foreach ($gTag as $el) {
             $id = $el->getAttribute('id');
             if (in_array($id, $seats)) {
                 if ($el->parentNode->hasAttribute('data-plase')) {
                     $place = $el->parentNode->getAttribute('data-plase');
                 } elseif ($el->parentNode->parentNode->hasAttribute('data-plase')) {
                     $place = $el->parentNode->parentNode->getAttribute('data-plase');
                 }
                 if ($place) {
                     $dataInit = json_decode($el->getAttribute('data-init'));
                     $place = str_replace(' / места:', '', $place);
                     $place = trim($place);
                     $result[$id] = array('row' => $place, 'seat' => $dataInit->seat);
                 }
             }
         }
     } catch (\Exception $e) {
         die('Ошибка загрузки карты');
     }
     return $result;
 }
Ejemplo n.º 2
0
 function printTicketAction()
 {
     if (User::get_access_for_controller('afisha_brone') != 'edit') {
         $this->no_access();
     }
     $key = Route::param('key');
     $keys = (array) explode(',', $key);
     if (count($keys) == 0) {
         Message::GetMessage(0, 'Места не выбраны!');
         HTTP::redirect('backend/afisha/index');
     }
     $printType = Route::param('printType') ? Route::param('printType') : 'base';
     $afisha = DB::select('afisha.*', array('places.name', 'place'), 'places.filename', 'places.address', 'places.city_id')->from('afisha')->join('places')->on('afisha.place_id', '=', 'places.id')->where('afisha.id', '=', (int) Route::param('id'))->find();
     if (!$afisha) {
         return Config::error();
     }
     $city = DB::select()->from('cities')->where('id', '=', $afisha->city_id)->find();
     $seatStr = array();
     $termoSeatStr = array();
     try {
         $dom = Map::factory()->loadFile($afisha->filename)->getDomInstance();
         $gTag = $dom->getElementsByTagName('g');
         foreach ($gTag as $el) {
             $id = $el->getAttribute('id');
             if (in_array($id, $keys)) {
                 if ($el->parentNode->hasAttribute('data-plase')) {
                     $originalPlace = $el->parentNode->getAttribute('data-plase');
                 } elseif ($el->parentNode->parentNode->hasAttribute('data-plase')) {
                     $originalPlace = $el->parentNode->parentNode->getAttribute('data-plase');
                 }
                 if ($originalPlace) {
                     $place = $originalPlace;
                     $place = str_replace(array('места', 'Места'), 'место', $place);
                     $place = str_replace('(левая сторона)', '(лев. сторона)', $place);
                     $place = str_replace('(правая сторона)', '(пр. сторона)', $place);
                     $place = str_replace(',', '<br />', $place);
                     $place = str_replace('ряд', 'ряд:', $place);
                     $seatStr[$id] = $place;
                     $dataInit = json_decode($el->getAttribute('data-init'));
                     $seatStr[$id] .= $dataInit->seat;
                     //                          For termo print
                     preg_match('#^(.*)?, ряд ([0-9]+)#', $originalPlace, $matches);
                     $termoSeatStr[$id]['block'] = $matches[1];
                     $termoSeatStr[$id]['block'] = str_replace('(левая сторона)', '(лев. сторона)', $termoSeatStr[$id]['block']);
                     $termoSeatStr[$id]['block'] = str_replace('(правая сторона)', '(пр. сторона)', $termoSeatStr[$id]['block']);
                     $termoSeatStr[$id]['row'] = $matches[2];
                     $termoSeatStr[$id]['seat'] = $dataInit->seat;
                 }
             }
         }
     } catch (\Exception $e) {
         die('Ошибка загрузки карты');
     }
     $tickets = array();
     foreach ($keys as $key) {
         $priceRow = DB::select('price', 'seats.id')->from('prices')->join('seats', 'LEFT')->on('prices.id', '=', 'seats.price_id')->where('afisha_id', '=', $afisha->id)->where('seats.view_key', '=', $key)->find();
         $tickets[] = Arr::to_object(array('event_name' => $afisha->name, 'print_name' => $afisha->print_name, 'print_name_small' => $afisha->print_name_small, 'event_date' => date('j', $afisha->event_date) . ' ' . Dates::month(date('m', $afisha->event_date)) . ' ' . date('Y', $afisha->event_date) . ' в ' . $afisha->event_time, 'event_place' => $afisha->place, 'event_just_date' => date('j', $afisha->event_date) . ' ' . Dates::month(date('m', $afisha->event_date)) . ' ' . date('Y', $afisha->event_date), 'event_time' => $afisha->event_time, 'event_address' => $afisha->address, 'place_string' => $seatStr[$key], 'place_block' => $termoSeatStr[$key]['block'], 'place_row' => $termoSeatStr[$key]['row'], 'place_seat' => $termoSeatStr[$key]['seat'], 'price' => $priceRow->price, 'phone' => $city->phone, 'barcode' => $afisha->id . '-' . $key));
     }
     if ($printType == 'base') {
         echo View::tpl(array('tickets' => $tickets), 'Afisha_orders/Print');
     } else {
         echo View::tpl(array('tickets' => $tickets), 'Afisha_orders/PrintTermo');
     }
     die;
 }
Ejemplo n.º 3
0
 public function getMapAction()
 {
     $post = $_POST;
     // Check data
     $id_place = Arr::get($post, 'id_place');
     $id_afisha = Arr::get($post, 'id_afisha');
     if (!isset($id_place)) {
         die(json_encode(array('success' => false, 'error' => 'Ошибка обработки')));
     }
     $result = DB::select()->from('places')->where('id', '=', $id_place)->find();
     if (!$result) {
         die(json_encode(array('success' => false, 'error' => 'Ошибка выборки места с БД')));
     }
     $seats = \Modules\Afisha\Models\Afisha::getMapSeats($id_afisha);
     // getMap
     try {
         $obj = \Modules\Afisha\Models\Map::factory()->loadFile($result->filename);
         // parse Data
         $map = $obj->parseDom($seats, true, true);
         $mapTpl = View::tpl(array('map' => $map), 'Map/Main');
         die(json_encode(array('success' => true, 'map' => $mapTpl)));
     } catch (\Exception $e) {
         die(json_encode(array('success' => false, 'error' => $e->getMessage(), 'code' => $e->getCode())));
     }
 }
Ejemplo n.º 4
0
 public function mapAction()
 {
     // Get afisha post and validate
     $item = Model::getItem(Route::param('alias'));
     if (!$item->id) {
         return Config::error();
     }
     // Seo
     $this->setSeoForItem($item, true);
     $this->setBreadcrumbs('Схема зала');
     // Get seats for available places
     $seats = Model::getMapSeats($item->id);
     // Get prices list
     $prices = Model::getMapPrices($item->id, true);
     try {
         $map = Map::factory();
         $map->loadFile($item->p_filename);
         $map->addPrices($prices);
         $mapTpl = $map->parseDom($seats, true);
     } catch (\Exception $e) {
         if ($item->url != '') {
             header('Location: ' . $item->url);
         } else {
             HTTP::redirect('brone?name=' . $item->name);
         }
         exit;
     }
     $this->_content = View::tpl(array('item' => $item, 'map' => $mapTpl), 'Map/Main');
 }
Ejemplo n.º 5
0
 function printAction()
 {
     if (User::get_access_for_controller('afisha_brone') != 'edit') {
         $this->no_access();
     }
     $seats = (array) $_POST['SEATS'];
     $printType = $_POST['print-type'] ? $_POST['print-type'] : 'base';
     if (count($seats) == 0) {
         Message::GetMessage(0, 'Места не выбраны!');
         HTTP::redirect('backend/afisha_orders/edit/' . Route::param('id'));
     }
     $order = DB::select()->from($this->tablename)->where('id', '=', Route::param('id'))->find();
     if (!$order) {
         return Config::error();
     }
     $afisha = DB::select('afisha.*', array('places.name', 'place'), 'places.filename', 'places.address', 'places.city_id')->from('afisha')->join('places')->on('afisha.place_id', '=', 'places.id')->where('afisha.id', '=', $order->afisha_id)->find();
     if (!$afisha) {
         return Config::error();
     }
     $city = DB::select()->from('cities')->where('id', '=', $afisha->city_id)->find();
     $seatStr = array();
     $termoSeatStr = array();
     try {
         $dom = Map::factory()->loadFile($afisha->filename)->getDomInstance();
         $gTag = $dom->getElementsByTagName('g');
         foreach ($gTag as $el) {
             $id = $el->getAttribute('id');
             if (in_array($id, $seats)) {
                 if ($el->parentNode->hasAttribute('data-plase')) {
                     $originalPlace = $el->parentNode->getAttribute('data-plase');
                 } elseif ($el->parentNode->parentNode->hasAttribute('data-plase')) {
                     $originalPlace = $el->parentNode->parentNode->getAttribute('data-plase');
                 }
                 if ($originalPlace) {
                     $place = str_replace('(левая сторона)', '(лев. сторона)', $originalPlace);
                     $place = str_replace('(правая сторона)', '(пр. сторона)', $place);
                     $place = str_replace(',', '<br />', $place);
                     $place = str_replace('ряд', 'ряд:', $place);
                     $seatStr[$id] = str_replace(array('места', 'Места'), 'место', $place);
                     $dataInit = json_decode($el->getAttribute('data-init'));
                     $seatStr[$id] .= $dataInit->seat;
                     //                          For termo print
                     preg_match('#^(.*)?, ряд ([0-9]+)#', $originalPlace, $matches);
                     $termoSeatStr[$id]['block'] = $matches[1];
                     $termoSeatStr[$id]['row'] = $matches[2];
                     $termoSeatStr[$id]['seat'] = $dataInit->seat;
                     $termoSeatStr[$id]['block'] = str_replace('(левая сторона)', '(лев. сторона)', $termoSeatStr[$id]['block']);
                     $termoSeatStr[$id]['block'] = str_replace('(правая сторона)', '(пр. сторона)', $termoSeatStr[$id]['block']);
                 }
             }
         }
     } catch (\Exception $e) {
         die('Ошибка загрузки карты');
     }
     $tickets = array();
     foreach ($seats as $seat) {
         if (User::info()->role_id != 2 && User::get_access_for_controller('afisha_print_unlimit') == 'edit' && strpos($order->printed_seats, $seat) !== false) {
             continue;
         }
         $priceRow = DB::select('price')->from('prices')->join('seats', 'LEFT')->on('prices.id', '=', 'seats.price_id')->where('afisha_id', '=', $order->afisha_id)->where('seats.view_key', '=', $seat)->find();
         $tickets[] = Arr::to_object(array('event_name' => $afisha->name, 'print_name' => $afisha->print_name, 'print_name_small' => $afisha->print_name_small, 'event_date' => date('d', $afisha->event_date) . ' ' . Dates::month(date('m', $afisha->event_date)) . ' ' . date('Y', $afisha->event_date) . ' в ' . $afisha->event_time, 'event_place' => $afisha->place, 'event_just_date' => date('j', $afisha->event_date) . ' ' . Dates::month(date('m', $afisha->event_date)) . ' ' . date('Y', $afisha->event_date), 'event_time' => $afisha->event_time, 'event_address' => $afisha->address, 'place_string' => $seatStr[$seat], 'place_block' => $termoSeatStr[$seat]['block'], 'place_row' => $termoSeatStr[$seat]['row'], 'place_seat' => $termoSeatStr[$seat]['seat'], 'price' => $priceRow->price, 'phone' => $city->phone, 'barcode' => $afisha->id . '-' . $order->id . '-' . $seat));
     }
     //            Update print seats keys
     if (User::info()->role_id != 2 && User::get_access_for_controller('afisha_print_unlimit') == 'edit') {
         $oldSeats = $order->printed_seats;
         $newSeats = array();
         if (strlen($oldSeats)) {
             $oldSeats = explode(',', $oldSeats);
             if (count($oldSeats)) {
                 $newSeats = (array) $oldSeats;
             }
         }
         foreach ($seats as $seat) {
             $newSeats[] = $seat;
         }
         $newSeats = array_filter(array_unique($newSeats));
         $newSeats = implode(',', $newSeats);
         DB::update($this->tablename)->set(array('printed_seats' => $newSeats))->where('id', '=', $order->id)->execute();
     }
     //            Update order status
     $newOrder = DB::select()->from('afisha_orders')->where('id', '=', $order->id)->find();
     $printedAllSeats = true;
     $printedSeats = array_filter(explode(',', $newOrder->printed_seats));
     foreach (array_filter(explode(',', $newOrder->seats_keys)) as $seat) {
         if (!in_array($seat, $printedSeats)) {
             $printedAllSeats = false;
         }
     }
     if (User::info()->role_id != 2 && $printedAllSeats) {
         \Core\Common::update('afisha_orders', array('status' => 'success'))->where('id', '=', (int) $order->id)->execute();
         $prices = DB::select('id')->from('prices')->where('afisha_id', '=', $order->afisha_id)->find_all();
         $pricesArr = array();
         if (count($prices)) {
             foreach ($prices as $key => $value) {
                 $pricesArr[] = $value->id;
             }
             \Core\Common::update('seats', array('status' => 3))->where('view_key', 'IN', array_filter(explode(',', $order->seats_keys)))->where('price_id', 'IN', $pricesArr)->execute();
         }
     }
     if ($printType == 'base') {
         echo View::tpl(array('tickets' => $tickets), 'Afisha_orders/Print');
     } else {
         echo View::tpl(array('tickets' => $tickets), 'Afisha_orders/PrintTermo');
     }
     die;
 }