protected function addAds(Ad $ad) { if (!$this instanceof AdStorage) { die("Нельзя использовать этот метод в конструкторе классов."); } $this->ads[$ad->getId()] = $ad; }
public static function handlePostQuery(array $sanitized_post_array) { // The result of the request $ajax_result = array('status' => '', 'message' => '', 'data' => ''); $is_edit_mode = isset($sanitized_post_array['id']); $ad = new Ad($sanitized_post_array); $result = $ad->save(); $sanitized_title = htmlentities($ad->getTitle()); if ($result) { $ajax_result['status'] = 'success'; $ajax_result['message'] = 'Ad "' . $sanitized_title . '" has been ' . ($is_edit_mode ? '" updated' : '"added') . ' successfully .'; $ajax_result['data'] = ['id' => $ad->getId()]; } else { $ajax_result['status'] = 'error'; $ajax_result['message'] = 'Error while ad "' . $sanitized_title . ($is_edit_mode ? '" updating ' : '" adding') . '.'; } return $ajax_result; }
/** * Add ad to storage * @param Ad $ad */ public function addAd(Ad $ad) { $this->ads[$ad->getId()] = $ad; }