/** * addToDatabase * * Adds new attachment to database * * @param AttachmentBO $attachmentInfo new attachment */ public function addToDatabase($attachmentInfo) { try { $image_id = parent::addToDatabase($attachmentInfo); if (!is_null($image_id)) { if (isset($attachmentInfo->attachment_metadata)) { $attachment_metadata = json_encode($attachmentInfo->attachment_metadata); $this->addMetaInfoToDatabase($image_id, 'attachment_metadata', $attachment_metadata); } if (isset($attachmentInfo->attached_file)) { $this->addMetaInfoToDatabase($image_id, 'attached_file', $attachmentInfo->attached_file); } } return $image_id; } catch (Exception $e) { } return NULL; }
/** * addToDatabase * * Add new internalflight * * @param stdClass $para para for add new internalflight */ public function addToDatabase($para) { try { if ($this->validateAddNew($para)) { BO::autoloadBO("internalflight"); $internalflightBO = new InternalflightBO(); if (isset($para->post_title)) { $internalflightBO->post_title = $para->post_title; } if (isset($para->current_rating)) { $internalflightBO->current_rating = $para->current_rating; } if (isset($para->vote_times)) { $internalflightBO->vote_times = $para->vote_times; } if (isset($para->tag_list)) { $internalflightBO->tag_list = $para->tag_list; } if (isset($para->post_content)) { $internalflightBO->post_content = $para->post_content; } if (isset($para->post_name)) { $internalflightBO->post_name = $para->post_name; } if (isset($para->city_id)) { $internalflightBO->city_id = $para->city_id; } if (isset($para->country_id)) { $internalflightBO->country_id = $para->country_id; } $internalflightBO->post_author = Session::get("user_id"); $internalflightBO->post_date = date("Y-m-d H:i:s"); $internalflightBO->post_date_gmt = gmdate("Y-m-d H:i:s"); $internalflightBO->post_modified = $internalflightBO->post_date; $internalflightBO->post_modified_gmt = $internalflightBO->post_date_gmt; $internalflightBO->post_parent = 0; $internalflightBO->post_status = "publish"; $internalflightBO->comment_status = "closed"; $internalflightBO->ping_status = "open"; $internalflightBO->guid = ""; $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]; $internalflightBO->image_id = $image_id; } else { $_SESSION["fb_error"][] = ERROR_UPLOAD_IMAGE_FAILED; $this->db->rollBack(); return FALSE; } } $post_id = parent::addToDatabase($internalflightBO); if ($post_id != NULL) { $guid = CONTEXT_PATH_INTERNALFLIGHT_VIEW . $post_id . "/" . $internalflightBO->post_name . "/"; if (!$this->updateGuid($post_id, $guid)) { if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } $this->db->rollBack(); $_SESSION["fb_error"][] = ERROR_ADD_NEW_INTERNALFLIGHT; return FALSE; } if (isset($internalflightBO->image_id) && $internalflightBO->image_id != "") { if ($this->addMetaInfoToDatabase($post_id, "image_id", $internalflightBO->image_id) == NULL) { if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } $this->db->rollBack(); $_SESSION["fb_error"][] = ERROR_ADD_NEW_INTERNALFLIGHT; return FALSE; } } if (isset($internalflightBO->current_rating) && $internalflightBO->current_rating != "") { if ($this->addMetaInfoToDatabase($post_id, "current_rating", $internalflightBO->current_rating) == NULL) { if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } $this->db->rollBack(); $_SESSION["fb_error"][] = ERROR_ADD_NEW_INTERNALFLIGHT; return FALSE; } } if (isset($internalflightBO->vote_times) && $internalflightBO->vote_times != "") { if ($this->addMetaInfoToDatabase($post_id, "vote_times", $internalflightBO->vote_times) == NULL) { if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } $this->db->rollBack(); $_SESSION["fb_error"][] = ERROR_ADD_NEW_INTERNALFLIGHT; return FALSE; } } Model::autoloadModel('taxonomy'); $taxonomyModel = new TaxonomyModel($this->db); if ($taxonomyModel->addRelationshipToDatabase($post_id, $internalflightBO->city_id, 0) == NULL) { if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } $this->db->rollBack(); $_SESSION["fb_error"][] = ERROR_ADD_NEW_INTERNALFLIGHT; return FALSE; } if ($taxonomyModel->addRelationshipToDatabase($post_id, $internalflightBO->country_id, 0) == NULL) { if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } $this->db->rollBack(); $_SESSION["fb_error"][] = ERROR_ADD_NEW_INTERNALFLIGHT; return FALSE; } if (isset($para->tag_array) && count($para->tag_array) > 0) { Model::autoloadModel('tag'); $tagModel = new TagModel($this->db); $tag_id_array = $tagModel->addTagArray($para->tag_array); for ($i = 0; $i < count($tag_id_array); $i++) { $taxonomyModel->addRelationshipToDatabase($post_id, $tag_id_array[$i]); } } $this->db->commit(); $_SESSION["fb_success"][] = ADD_INTERNALFLIGHT_SUCCESS; return TRUE; } else { $this->db->rollBack(); $_SESSION["fb_error"][] = ERROR_ADD_NEW_INTERNALFLIGHT; if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } } } } catch (Exception $e) { $_SESSION["fb_error"][] = ERROR_ADD_NEW_INTERNALFLIGHT; } return FALSE; }
/** * addContent * * Add new attraction * * @param stdClass $attractionBO para for add new attraction */ public function addContent($attractionBO) { try { BO::autoloadBO("post"); $postBO = new PostBO(); if (isset($attractionBO->name)) { $postBO->post_title = $attractionBO->name; } 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); } if (isset($attractionBO->name)) { $postBO->post_name = Utils::createSlug($attractionBO->name); } if (isset($para->current_rating)) { $attractionBO->current_rating = $para->current_rating; } if (isset($para->vote_times)) { $attractionBO->vote_times = $para->vote_times; } $postBO->post_author = Session::get("user_id"); $postBO->post_date = date("Y-m-d H:i:s"); $postBO->post_date_gmt = gmdate("Y-m-d H:i:s"); $postBO->post_modified = $postBO->post_date; $postBO->post_modified_gmt = $postBO->post_date_gmt; $postBO->post_parent = 0; $postBO->post_status = "publish"; $postBO->comment_status = "closed"; $postBO->ping_status = "open"; $postBO->guid = ""; $postBO->post_type = "attraction"; if (isset($attractionBO->images)) { Model::autoloadModel("image"); $imageModel = new ImageModel($this->db); $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) { $postBO->image_ids = json_encode($image_array_id); } else { return FALSE; } } Model::autoloadModel("post"); $postModel = new PostModel($this->db); $post_id = $postModel->addToDatabase($postBO); if ($post_id != NULL) { if (isset($postBO->image_ids) && $postBO->image_ids != "") { if ($postModel->addMetaInfoToDatabase($post_id, "image_ids", $postBO->image_ids) == NULL) { if (isset($imageModel) && isset($image_array_id)) { foreach ($image_array_id as $image_id) { $imageModel->delete($image_id); } } return FALSE; } } Model::autoloadModel('taxonomy'); $taxonomyModel = new TaxonomyModel($this->db); if ($taxonomyModel->addRelationshipToDatabase($post_id, $attractionBO->term_taxonomy_id, 0) == NULL) { if (isset($imageModel) && isset($image_array_id)) { foreach ($image_array_id as $image_id) { $imageModel->delete($image_id); } } return FALSE; } if (isset($attractionBO->tag_array) && count($attractionBO->tag_array) > 0) { Model::autoloadModel('tag'); $tagModel = new TagModel($this->db); $tag_id_array = $tagModel->addTagArray($attractionBO->tag_array); for ($i = 0; $i < count($tag_id_array); $i++) { $taxonomyModel->addRelationshipToDatabase($post_id, $tag_id_array[$i]); } } return TRUE; } else { if (isset($imageModel) && isset($image_id)) { $imageModel->delete($image_id); } } } catch (Exception $e) { } return FALSE; }
/** * addToDatabase * * Add new country * * @param stdClass $para para for add new country */ public function addContent($countryBO) { try { BO::autoloadBO("post"); $postBO = new PostBO(); if (isset($countryBO->name)) { $postBO->post_title = $countryBO->name; } 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); } if (isset($countryBO->name)) { $postBO->post_name = Utils::createSlug($countryBO->name); } $postBO->post_author = Session::get("user_id"); $postBO->post_date = date("Y-m-d H:i:s"); $postBO->post_date_gmt = gmdate("Y-m-d H:i:s"); $postBO->post_modified = $postBO->post_date; $postBO->post_modified_gmt = $postBO->post_date_gmt; $postBO->post_parent = 0; $postBO->post_status = "publish"; $postBO->comment_status = "closed"; $postBO->ping_status = "open"; $postBO->guid = ""; $postBO->post_type = "country"; if (isset($countryBO->image_weathers)) { Model::autoloadModel("image"); $imageModel = new ImageModel($this->db); $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) { $postBO->image_weather_ids = json_encode($image_array_id); } else { return FALSE; } } Model::autoloadModel("post"); $postModel = new PostModel($this->db); $post_id = $postModel->addToDatabase($postBO); if ($post_id != NULL) { if (isset($postBO->image_weather_ids) && $postBO->image_weather_ids != "") { if ($postModel->addMetaInfoToDatabase($post_id, "image_weather_ids", $postBO->image_weather_ids) == NULL) { if (isset($imageModel) && isset($image_array_id)) { foreach ($image_array_id as $image_weather_id) { $imageModel->delete($image_weather_id); } } return FALSE; } } Model::autoloadModel('taxonomy'); $taxonomyModel = new TaxonomyModel($this->db); if ($taxonomyModel->addRelationshipToDatabase($post_id, $countryBO->term_taxonomy_id, 0) == NULL) { if (isset($imageModel) && isset($image_array_id)) { foreach ($image_array_id as $image_weather_id) { $imageModel->delete($image_weather_id); } } return FALSE; } if (isset($countryBO->tag_array) && count($countryBO->tag_array) > 0) { Model::autoloadModel('tag'); $tagModel = new TagModel($this->db); $tag_id_array = $tagModel->addTagArray($countryBO->tag_array); for ($i = 0; $i < count($tag_id_array); $i++) { $taxonomyModel->addRelationshipToDatabase($post_id, $tag_id_array[$i]); } } return TRUE; } else { if (isset($imageModel) && isset($image_weather_id)) { $imageModel->delete($image_weather_id); } } } catch (Exception $e) { } return FALSE; }