function OnPostback() { # Get the item info and store it $id = $this->manager->GetItemId($this->data_object); $this->manager->ReadById(array($id)); $this->data_object = $this->manager->GetFirst(); # Check whether cancel was clicked if (isset($_POST['cancel'])) { $this->Redirect($this->data_object->GetNavigateUrl()); } # Check whether delete was clicked if (isset($_POST['delete'])) { # Only offer delete option if there's more than one season. Don't want to delete last season because # that leaves an empty competition which won't display. Instead, must delete whole competition with its one remaining season. # How many seasons in this competition? if (is_object($this->data_object) and $this->data_object->GetCompetition() instanceof Competition and $this->data_object->GetCompetition()->GetId()) { $this->manager->Clear(); $this->manager->ReadByCompetitionId(array($this->data_object->GetCompetition()->GetId())); $this->seasons_in_competition = $this->manager->GetCount(); } if ($this->seasons_in_competition > 1) { # Check again that the requester has permission to delete this item if ($this->has_permission) { # Delete it $this->manager->Delete(array($id)); # Update the competition in the search engine, because the latest season may have changed. require_once 'stoolball/competition-manager.class.php'; require_once "search/competition-search-adapter.class.php"; $this->SearchIndexer()->DeleteFromIndexById("competition" . $this->data_object->GetCompetition()->GetId()); $competition_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); $competition_manager->ReadById(array($this->data_object->GetCompetition()->GetId())); $competition = $competition_manager->GetFirst(); $adapter = new CompetitionSearchAdapter($competition); $this->SearchIndexer()->Index($adapter->GetSearchableItem()); $this->SearchIndexer()->CommitChanges(); # Note success $this->deleted = true; } } } }
/** * @access public * @return void * @param int[] $a_ids * @desc Delete from the db the Competitions matching the supplied ids */ function Delete($a_ids) { # check paramter if (!is_array($a_ids)) { die('No Competitions to delete'); } # build query $s_comp = $this->o_settings->GetTable('Competition'); $s_season = $this->o_settings->GetTable('Season'); $s_ids = join(', ', $a_ids); # get the seasons and use SeasonManager to deal with them $season_ids = array(); $s_sql = 'SELECT season_id FROM ' . $s_season . ' WHERE competition_id IN (' . $s_ids . ') '; $result = $this->GetDataConnection()->query($s_sql); while ($row = $result->fetch()) { $season_ids[] = $row->season_id; } $result->closeCursor(); require_once 'stoolball/season-manager.class.php'; $season_manager = new SeasonManager($this->GetSettings(), $this->GetDataConnection()); $season_manager->Delete($season_ids); unset($season_manager); # delete from short URL cache require_once 'http/short-url-manager.class.php'; $o_url_manager = new ShortUrlManager($this->GetSettings(), $this->GetDataConnection()); $s_sql = "SELECT short_url FROM {$s_comp} WHERE competition_id IN ({$s_ids})"; $result = $this->GetDataConnection()->query($s_sql); while ($row = $result->fetch()) { $o_url_manager->Delete($row->short_url); } $result->closeCursor(); unset($o_url_manager); # delete competition(s) $s_sql = 'DELETE FROM ' . $s_comp . ' WHERE competition_id IN (' . $s_ids . ') '; $o_result = $this->GetDataConnection()->query($s_sql); return $this->GetDataConnection()->GetAffectedRows(); }