/** * updateInfo * * Update info of internalflight * * @param stdClass $para para for update info of internalflight */ public function updateInfo($para) { try { if ($this->validateUpdateInfo($para)) { $internalflightBO = $this->get($para->post_id); if ($internalflightBO != NULL) { if (isset($para->post_title) && $internalflightBO->post_title != $para->post_title) { $internalflightBO->post_title = $para->post_title; } if (isset($para->post_content) && $internalflightBO->post_content != $para->post_content) { $internalflightBO->post_content = $para->post_content; } if (isset($para->post_name) && $internalflightBO->post_name != $para->post_name) { $internalflightBO->post_name = $para->post_name; } $internalflightBO->post_modified = date("Y-m-d H:i:s"); $internalflightBO->post_modified_gmt = gmdate("Y-m-d H:i:s"); $this->db->beginTransaction(); if (isset($para->image)) { Model::autoloadModel("image"); $imageModel = new ImageModel($this->db); $imageModel->is_create_thumb = true; $imageModel->is_medium = true; $image_array_id = $imageModel->uploadImages("image"); if (!is_null($image_array_id) && is_array($image_array_id) && sizeof($image_array_id) != 0) { $image_id = $image_array_id[0]; $image_id_old = $internalflightBO->image_id; } else { $_SESSION["fb_error"][] = ERROR_UPLOAD_IMAGE_FAILED; $this->db->rollBack(); return FALSE; } } if ($this->update($internalflightBO)) { $guid = CONTEXT_PATH_INTERNALFLIGHT_VIEW . $para->post_id . "/" . $internalflightBO->post_name . "/"; if (isset($internalflightBO->guid) && $internalflightBO->guid != $guid || !isset($internalflightBO->guid)) { $internalflightBO->guid = $guid; if (!$this->updateGuid($para->post_id, $guid)) { $this->db->rollBack(); if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } if (isset($image_id)) { if (!isset($internalflightBO->image_id)) { $internalflightBO->image_id = $image_id; if ($this->addMetaInfoToDatabase($para->post_id, "image_id", $internalflightBO->image_id) == NULL) { $this->db->rollBack(); if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } else { if ($internalflightBO->image_id != $image_id) { $internalflightBO->image_id = $image_id; if (!$this->updateMetaInfoToDatabase($para->post_id, "image_id", $internalflightBO->image_id)) { $this->db->rollBack(); if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } } } if (isset($para->current_rating)) { if (!isset($internalflightBO->current_rating)) { $internalflightBO->current_rating = $para->current_rating; if ($this->addMetaInfoToDatabase($para->post_id, "current_rating", $internalflightBO->current_rating) == NULL) { $this->db->rollBack(); if (isset($imageModel) && isset($current_rating)) { $imageModel->delete($current_rating); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } else { if ($internalflightBO->current_rating != $para->current_rating) { $internalflightBO->current_rating = $para->current_rating; if (!$this->updateMetaInfoToDatabase($para->post_id, "current_rating", $internalflightBO->current_rating)) { $this->db->rollBack(); if (isset($imageModel) && isset($current_rating)) { $imageModel->delete($current_rating); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } } } if (isset($para->vote_times)) { if (!isset($internalflightBO->vote_times)) { $internalflightBO->vote_times = $para->vote_times; if ($this->addMetaInfoToDatabase($para->post_id, "vote_times", $internalflightBO->vote_times) == NULL) { $this->db->rollBack(); if (isset($imageModel) && isset($vote_times)) { $imageModel->delete($vote_times); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } else { if ($internalflightBO->vote_times != $para->vote_times) { $internalflightBO->vote_times = $para->vote_times; if (!$this->updateMetaInfoToDatabase($para->post_id, "vote_times", $internalflightBO->vote_times)) { $this->db->rollBack(); if (isset($imageModel) && isset($vote_times)) { $imageModel->delete($vote_times); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } } } if (isset($para->city_id)) { if (!isset($internalflightBO->city_id)) { $internalflightBO->city_id = $para->city_id; if ($this->addMetaInfoToDatabase($para->post_id, "city_id", $internalflightBO->city_id) == NULL) { $this->db->rollBack(); if (isset($imageModel) && isset($city_id)) { $imageModel->delete($city_id); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } else { if ($internalflightBO->city_id != $para->city_id) { $internalflightBO->city_id = $para->city_id; if (!$this->updateMetaInfoToDatabase($para->post_id, "city_id", $internalflightBO->city_id)) { $this->db->rollBack(); if (isset($imageModel) && isset($city_id)) { $imageModel->delete($city_id); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } } } if (isset($para->country_id)) { if (!isset($internalflightBO->country_id)) { $internalflightBO->country_id = $para->country_id; if ($this->addMetaInfoToDatabase($para->post_id, "country_id", $internalflightBO->country_id) == NULL) { $this->db->rollBack(); if (isset($imageModel) && isset($country_id)) { $imageModel->delete($country_id); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } else { if ($internalflightBO->country_id != $para->country_id) { $internalflightBO->country_id = $para->country_id; if (!$this->updateMetaInfoToDatabase($para->post_id, "country_id", $internalflightBO->country_id)) { $this->db->rollBack(); if (isset($imageModel) && isset($country_id)) { $imageModel->delete($country_id); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; return FALSE; } } } } if (isset($para->tag_array) || isset($internalflightBO->tag_list)) { Model::autoloadModel('tag'); $tagModel = new TagModel($this->db); Model::autoloadModel('taxonomy'); $taxonomyModel = new TaxonomyModel($this->db); if (!isset($para->tag_array) || count($para->tag_array) == 0) { foreach ($internalflightBO->tag_list as $tag) { $tagModel->deleteRelationship($para->post_id, $tag->term_taxonomy_id); } } elseif (!isset($internalflightBO->tag_list) || count($internalflightBO->tag_list) == 0) { if (count($para->tag_array) > 0) { $tag_id_array = $tagModel->addTagArray($para->tag_array); for ($i = 0; $i < count($tag_id_array); $i++) { $taxonomyModel->addRelationshipToDatabase($para->post_id, $tag_id_array[$i]); } } } elseif (isset($para->tag_array) && isset($internalflightBO->tag_list) && count($para->tag_array) > 0 && count($internalflightBO->tag_list) > 0) { $tags_old_array = array(); foreach ($internalflightBO->tag_list as $tag_old) { $tags_old_array[] = $tag_old->name; } $tags_new_array = array(); for ($i = 0; $i < count($para->tag_array); $i++) { if (!in_array($para->tag_array[$i], $tags_old_array)) { $tags_new_array[] = $para->tag_array[$i]; } } if (count($tags_new_array) > 0) { $tag_id_new_array = $tagModel->addTagArray($tags_new_array); for ($i = 0; $i < count($tag_id_new_array); $i++) { $taxonomyModel->addRelationshipToDatabase($para->post_id, $tag_id_new_array[$i]); } } $tags_delete_array = array(); for ($i = 0; $i < count($internalflightBO->tag_list); $i++) { if (!in_array($internalflightBO->tag_list[$i]->name, $para->tag_array)) { $tags_delete_array[] = $internalflightBO->tag_list[$i]; } } if (count($tags_delete_array) > 0) { foreach ($tags_delete_array as $tag) { $tagModel->deleteRelationship($para->post_id, $tag->term_taxonomy_id); } } } } $this->db->commit(); if (isset($imageModel) && isset($image_id) && isset($image_id_old)) { $imageModel->delete($image_id_old); } $_SESSION["fb_success"][] = UPDATE_INTERNALFLIGHT_SUCCESS; return TRUE; } else { $this->db->rollBack(); if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; } } } } catch (Exception $e) { $_SESSION["fb_error"][] = ERROR_UPDATE_INFO_INTERNALFLIGHT; } return FALSE; }
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) { } } }
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 addNew($para) { try { if ($this->validateAddNew($para)) { BO::autoloadBO("user"); $userBO = new UserBO(); if (isset($para->user_login)) { $userBO->user_login = $para->user_login; } if (isset($para->role)) { $userBO->wp_capabilities = $para->role; } if (isset($para->first_name)) { $userBO->first_name = $para->first_name; } if (isset($para->last_name)) { $userBO->last_name = $para->last_name; } if (isset($para->nickname)) { $userBO->nickname = $para->nickname; } if (isset($para->display_name)) { $userBO->display_name = $para->display_name; } if (isset($para->email)) { $userBO->user_email = $para->email; } if (isset($para->url)) { $userBO->user_url = $para->url; } if (isset($para->description)) { $userBO->description = $para->description; } if (isset($para->pass1_text)) { $userBO->user_pass = $para->pass1_text; } $this->db->beginTransaction(); if (isset($para->avatar)) { Model::autoloadModel("image"); $imageModel = new ImageModel($this->db); $imageModel->is_create_thumb = true; $imageModel->is_slider_thumb = true; $avatar_array_id = $imageModel->uploadImages("avatar"); if (!is_null($avatar_array_id) && is_array($avatar_array_id) && sizeof($avatar_array_id) != 0) { $avatar_id = $avatar_array_id[0]; $userBO->avatar = $avatar_id; } else { $_SESSION["fb_error"][] = ERROR_UPLOAD_AVATAR_FAILED; } } if ($this->addToDatabase($userBO)) { $this->db->commit(); $_SESSION["fb_success"][] = ADD_USER_SUCCESS; return TRUE; } else { $this->db->rollBack(); $_SESSION["fb_error"][] = ADD_USER_SUCCESS; if (isset($is_change_avatar) && $is_change_avatar && isset($imageModel) && isset($avatar_id)) { $imageModel->delete($avatar_id); } } } } catch (Exception $e) { $_SESSION["fb_error"][] = ERROR_ADD_NEW_USER; } return FALSE; }