示例#1
0
 public function delete($post_id)
 {
     try {
         $internalflightBO = $this->get($post_id);
         if ($internalflightBO != NULL) {
             if (parent::delete($post_id)) {
                 if (isset($internalflightBO->city_id)) {
                     $this->deleteRelationship($post_id, $internalflightBO->city_id);
                 }
                 if (isset($internalflightBO->country_id)) {
                     $this->deleteRelationship($post_id, $internalflightBO->country_id);
                 }
                 if (isset($internalflightBO->image_id)) {
                     Model::autoloadModel("image");
                     $imageModel = new ImageModel($this->db);
                     $imageModel->delete($internalflightBO->image_id);
                 }
                 return TRUE;
             }
         }
     } catch (Exception $e) {
     }
     return FALSE;
 }
示例#2
0
 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) {
         }
     }
 }
示例#3
0
 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) {
         }
     }
 }
示例#4
0
 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;
 }