/** * @param mixed $value * @param mixed $by * * @return $this */ public function load($value, $by = null) { switch ($by) { case 'all': $args['hide_empty'] = false; $items = get_terms(TaxonomyModel::getTaxonomyNames(), $args); break; case 'parentId': $args['hide_empty'] = false; $args['parent'] = $value; $items = get_terms(TaxonomyModel::getTaxonomyNames(), $args); break; case 'child_of': $args['hide_empty'] = false; $args['child_of'] = $value; $items = get_terms(TaxonomyModel::getTaxonomyNames(), $args); break; case 'args': $args = $value; $items = get_terms(TaxonomyModel::getTaxonomyNames(), $args); break; } foreach ($items as $item) { $term = new TermModel($item, 'wp_object'); $this->offsetSet($term->id, $term); } return $this; }
/** * @param mixed $value * @param mixed $by * * @return $this */ public function load($value, $by = null) { switch ($by) { case 'id': $args = array(); $args['include'] = $value; $args['hide_empty'] = false; $args['number'] = 1; $taxonomies = static::TYPE ?: TaxonomyModel::getTaxonomyNames(); $items = get_terms($taxonomies, $args); $item = reset($items); break; case 'name': $args = array(); $args['slug'] = $value; $args['hide_empty'] = false; $args['number'] = 1; $taxonomies = static::TYPE ?: TaxonomyModel::getTaxonomyNames(); $items = get_terms($taxonomies, $args); $item = reset($items); break; case 'args': $args = $value; $args['number'] = 1; $items = get_terms(TaxonomyModel::getTaxonomyNames(), $args); $item = reset($items); break; case 'wp_object': $item = $value; break; } $this->fromArray($item); return $this; }
/** * 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 search($view, $para) { $styles_per_page = STYLES_PER_PAGE_DEFAULT; $taxonomy = "style"; $userLoginBO = json_decode(Session::get("userInfo")); if ($userLoginBO != NULL) { if (isset($userLoginBO->styles_per_page) && is_numeric($userLoginBO->styles_per_page)) { $styles_per_page = (int) $userLoginBO->styles_per_page; } } if (!isset($styles_per_page)) { if (!isset($_SESSION['options'])) { $_SESSION['options'] = new stdClass(); $_SESSION['options']->styles_per_page = STYLES_PER_PAGE_DEFAULT; $styles_per_page = STYLES_PER_PAGE_DEFAULT; } elseif (!isset($_SESSION['options']->styles_per_page)) { $_SESSION['options']->styles_per_page = STYLES_PER_PAGE_DEFAULT; $styles_per_page = STYLES_PER_PAGE_DEFAULT; } } $view->taxonomies_per_page = $styles_per_page; $view->taxonomy = $taxonomy; parent::search($view, $para); }
public function view($post_id = NULL) { Model::autoloadModel('internalflight'); $model = new InternalflightModel($this->db); $this->para = new stdClass(); if (isset($_POST['internalflight'])) { $this->para->post_id = $_POST['internalflight']; } elseif (isset($post_id) && !is_null($post_id)) { $this->para->post_id = $post_id; } if (isset($this->para->post_id)) { $this->view->internalflightBO = $model->get($this->para->post_id); Model::autoloadModel('taxonomy'); $taxonomyModel = new TaxonomyModel($this->db); $this->view->countryList = new SplDoublyLinkedList(); $taxonomyModel->getAllSorted($this->view->countryList, $taxonomyModel->buildTree($taxonomyModel->getAll("country")), -1); $this->view->cityList = new SplDoublyLinkedList(); if (isset($this->view->internalflightBO->country_id) && $this->view->internalflightBO->country_id != "0") { $taxonomyModel->getAllSorted($this->view->cityList, $taxonomyModel->buildTree($taxonomyModel->getByMetaData("city", "country", $this->view->internalflightBO->country_id)), -1); } if (isset($post_id) && !is_null($post_id)) { $this->view->render(RENDER_VIEW_INTERNALFLIGHT); } else { $this->view->render(RENDER_VIEW_INTERNALFLIGHT, TRUE); } } else { header('location: ' . URL); } }