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; }
public static function handlePostQuery(array $sanitized_post_array, $view) { /* @var $view Smarty */ // 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 .'; $view->assign('ad_in_table', $ad); $class_name = $ad->getOrganizationFormId() == '1' ? 'organization' : 'individual'; $ajax_result['data'] = $view->fetch('table_row_' . $class_name . '.tpl.html'); } else { $ajax_result['status'] = 'error'; $ajax_result['message'] = 'Error while ad "' . $sanitized_title . ($is_edit_mode ? '" updating ' : '" adding') . '.'; } return $ajax_result; }