/** * Action: combine */ public function action_combine() { $this->history = false; // Load original venue $venue_id = (int) $this->request->param('id'); $venue = Model_Venue::factory($venue_id); if (!$venue->loaded()) { throw new Model_Exception($venue, $venue_id); } Permission::required($venue, Model_Venue::PERMISSION_COMBINE); // Build page $this->view = new View_Page($venue->name); $this->view->tab = 'venue'; $this->view->tabs[] = array('link' => Route::url('venues'), 'text' => '« ' . __('Back to Venues')); $this->view->tabs['venue'] = array('link' => Route::model($venue), 'text' => __('Venue')); // Load duplicate venue $duplicate_id = (int) $this->request->param('param'); if ($duplicate_id) { $duplicate = Model_Venue::factory($duplicate_id); if (!$duplicate->loaded()) { throw new Model_Exception($duplicate, $duplicate_id); } if (Security::csrf_valid()) { // Combine // Update events Model_Event::merge_venues($venue_id, $duplicate_id); // Copy info from duplicate $new_data = false; foreach (array('description', 'url', 'hours', 'info', 'address', 'zip', 'city_name', 'latitude', 'longitude', 'foursquare_id', 'foursquare_category_id') as $data) { if ($duplicate[$data] && !$venue[$data]) { $venue[$data] = $duplicate[$data]; $new_data = true; } } if ($new_data) { $venue->save(); } // Remove duplicate $duplicate->delete(); $this->request->redirect(Route::model($venue)); } else { // Confirm $this->view->add(View_Page::COLUMN_CENTER, $this->section_venue_combine($venue, $duplicate)); } } else { // Select parent $this->view->add(View_Page::COLUMN_CENTER, $this->section_venue_combine($venue)); } }