public function updateContent($attractionBO) { if (isset($attractionBO->postBO)) { $postBO = $attractionBO->postBO; try { $sql = "UPDATE " . TABLE_POSTS . " "; $set = "SET "; $where = " WHERE " . TB_POST_COL_ID . " = :post_id;"; $para_array = []; $para_array[":post_id"] = $postBO->ID; if (isset($attractionBO->name)) { $postBO->post_title = $attractionBO->name; $set .= " " . TB_POST_COL_POST_TITLE . " = :post_title,"; $para_array[":post_title"] = $postBO->post_title; } if (isset($attractionBO->post_content_1) || isset($attractionBO->post_content_2)) { $post_content = new stdClass(); if (isset($attractionBO->post_content_1)) { $post_content->post_content_1 = $attractionBO->post_content_1; } if (isset($attractionBO->post_content_2)) { $post_content->post_content_2 = $attractionBO->post_content_2; } $postBO->post_content = json_encode($post_content); $set .= " " . TB_POST_COL_POST_CONTENT . " = :post_content,"; $para_array[":post_content"] = $postBO->post_content; } if (isset($attractionBO->name)) { $postBO->post_name = Utils::createSlug($attractionBO->name); $set .= " " . TB_POST_COL_POST_NAME . " = :post_name,"; $para_array[":post_name"] = $postBO->post_name; } if (isset($postBO->image_ids)) { $image_ids = json_decode($postBO->image_ids); } else { $image_ids = array(); } Model::autoloadModel("image"); $imageModel = new ImageModel($this->db); if (isset($attractionBO->images_upload)) { $imageModel->is_create_thumb = true; $imageModel->is_slider_thumb = true; $imageModel->is_large = true; // $imageModel->slider_thumb_crop = true; $image_array_id = $imageModel->uploadImages("images"); if (!is_null($image_array_id) && is_array($image_array_id) && sizeof($image_array_id) != 0) { $image_ids = array_merge($image_ids, $image_array_id); } else { return FALSE; } } if (isset($attractionBO->image_delete_list) && $attractionBO->image_delete_list != "" && $attractionBO->image_delete_list != NULL) { $image_delete_array = explode(",", $attractionBO->image_delete_list); if (count($image_delete_array) > 0) { foreach ($image_delete_array as $image_delete_id) { $image_ids = array_diff($image_ids, [$image_delete_id]); // array_slice($image_ids, $image_delete_id, 1); } } } if (count($para_array) != 0) { $set = substr($set, 0, strlen($set) - 1); $sql .= $set . $where; $sth = $this->db->prepare($sql); $sth->execute($para_array); Model::autoloadModel("post"); $postModel = new PostModel($this->db); $image_ids = json_encode($image_ids); if (isset($image_ids) && $image_ids != "") { if (isset($postBO->image_ids)) { if (!$postModel->updateMetaInfoToDatabase($postBO->ID, "image_ids", $image_ids)) { if (isset($imageModel) && isset($image_array_id)) { foreach ($image_array_id as $image_id) { $imageModel->delete($image_id); } } return FALSE; } else { //thanh cong xoa image bi tich bo if (isset($imageModel) && isset($image_delete_array)) { foreach ($image_delete_array as $image_id) { $imageModel->delete($image_id); } } } } else { if (!$postModel->addMetaInfoToDatabase($postBO->ID, "image_ids", $image_ids)) { if (isset($imageModel) && isset($image_array_id)) { foreach ($image_array_id as $image_id) { $imageModel->delete($image_id); } } return FALSE; } else { //thanh cong xoa image bi tich bo if (isset($imageModel) && isset($image_delete_array)) { foreach ($image_delete_array as $image_id) { $imageModel->delete($image_id); } } } } } return TRUE; } } catch (Exception $e) { } } }
public function updateContent($countryBO) { if (isset($countryBO->postBO)) { $postBO = $countryBO->postBO; try { $sql = "UPDATE " . TABLE_POSTS . " "; $set = "SET "; $where = " WHERE " . TB_POST_COL_ID . " = :post_id;"; $para_array = []; $para_array[":post_id"] = $postBO->ID; if (isset($countryBO->name)) { $postBO->post_title = $countryBO->name; $set .= " " . TB_POST_COL_POST_TITLE . " = :post_title,"; $para_array[":post_title"] = $postBO->post_title; } if (isset($countryBO->overview) || isset($countryBO->history) || isset($countryBO->weather) || isset($countryBO->passport_visa) || isset($countryBO->currency) || isset($countryBO->phone_internet_service) || isset($countryBO->transportation) || isset($countryBO->food_drink) || isset($countryBO->public_holiday) || isset($countryBO->predeparture_check_list)) { $post_content = new stdClass(); if (isset($countryBO->overview)) { $post_content->overview = $countryBO->overview; } if (isset($countryBO->history)) { $post_content->history = $countryBO->history; } if (isset($countryBO->weather)) { $post_content->weather = $countryBO->weather; } if (isset($countryBO->passport_visa)) { $post_content->passport_visa = $countryBO->passport_visa; } if (isset($countryBO->currency)) { $post_content->currency = $countryBO->currency; } if (isset($countryBO->phone_internet_service)) { $post_content->phone_internet_service = $countryBO->phone_internet_service; } if (isset($countryBO->transportation)) { $post_content->transportation = $countryBO->transportation; } if (isset($countryBO->food_drink)) { $post_content->food_drink = $countryBO->food_drink; } if (isset($countryBO->public_holiday)) { $post_content->public_holiday = $countryBO->public_holiday; } if (isset($countryBO->predeparture_check_list)) { $post_content->predeparture_check_list = $countryBO->predeparture_check_list; } $postBO->post_content = json_encode($post_content); $set .= " " . TB_POST_COL_POST_CONTENT . " = :post_content,"; $para_array[":post_content"] = $postBO->post_content; } if (isset($countryBO->name)) { $postBO->post_name = Utils::createSlug($countryBO->name); $set .= " " . TB_POST_COL_POST_NAME . " = :post_name,"; $para_array[":post_name"] = $postBO->post_name; } if (isset($postBO->image_weather_ids)) { $image_weather_ids = json_decode($postBO->image_weather_ids); } else { $image_weather_ids = array(); } Model::autoloadModel("image"); $imageModel = new ImageModel($this->db); if (isset($countryBO->image_weathers_upload)) { $imageModel->is_create_thumb = true; $imageModel->is_slider_thumb = true; $imageModel->is_medium_large = true; // $imageModel->slider_thumb_crop = true; $image_array_id = $imageModel->uploadImages("image_weathers"); if (!is_null($image_array_id) && is_array($image_array_id) && sizeof($image_array_id) != 0) { $image_weather_ids = array_merge($image_weather_ids, $image_array_id); } else { return FALSE; } } if (isset($countryBO->image_weather_delete_list) && $countryBO->image_weather_delete_list != "" && $countryBO->image_weather_delete_list != NULL) { $image_weather_delete_array = explode(",", $countryBO->image_weather_delete_list); if (count($image_weather_delete_array) > 0) { foreach ($image_weather_delete_array as $image_delete_id) { $image_weather_ids = array_diff($image_weather_ids, [$image_delete_id]); // array_slice($image_weather_ids, $image_delete_id, 1); // array_slice($image_weather_ids, $image_delete_id); } } } if (count($para_array) != 0) { $set = substr($set, 0, strlen($set) - 1); $sql .= $set . $where; $sth = $this->db->prepare($sql); $sth->execute($para_array); Model::autoloadModel("post"); $postModel = new PostModel($this->db); $image_weather_ids = json_encode($image_weather_ids); if (isset($image_weather_ids) && $image_weather_ids != "") { if (isset($postBO->image_weather_ids)) { if (!$postModel->updateMetaInfoToDatabase($postBO->ID, "image_weather_ids", $image_weather_ids)) { if (isset($imageModel) && isset($image_array_id)) { foreach ($image_array_id as $image_weather_id) { $imageModel->delete($image_weather_id); } } return FALSE; } else { //thanh cong xoa image bi tich bo if (isset($imageModel) && isset($image_weather_delete_array)) { foreach ($image_weather_delete_array as $image_weather_id) { $imageModel->delete($image_weather_id); } } } } else { if (!$postModel->addMetaInfoToDatabase($postBO->ID, "image_weather_ids", $image_weather_ids)) { if (isset($imageModel) && isset($image_array_id)) { foreach ($image_array_id as $image_weather_id) { $imageModel->delete($image_weather_id); } } return FALSE; } else { //thanh cong xoa image bi tich bo if (isset($imageModel) && isset($image_weather_delete_array)) { foreach ($image_weather_delete_array as $image_weather_id) { $imageModel->delete($image_weather_id); } } } } } return TRUE; } } catch (Exception $e) { } } }