/** * get * * Get info of attachment by id * * @param int $attachment_id ID of attachment */ public function get($attachment_id) { $attachmentBO = parent::get($attachment_id); if (isset($attachmentBO->attachment_metadata) && !is_object($attachmentBO->attachment_metadata)) { $attachmentBO->attachment_metadata = json_decode($attachmentBO->attachment_metadata); } return $attachmentBO; }
public function save() { $post = PostModel::get($this->post_id); $data = ['id' => $this->id, 'post_id' => $this->post_id, 'user_id' => $this->user_id, 'name' => $this->name, 'message' => $this->message, 'updated_at' => date(MYSQL_DATE_TIME)]; $db = DB::instance(); $this->id = $db->store($data, self::$table); $post->comment_count = self::getCommentCount($post); $post->save(); return $this->id; }
public function actionSaveComment($post_id) { $post = PostModel::get($post_id); $input = \System\Engine::getInput(); $data = $input->getArray("data"); $data = array_intersect_key($data, array_flip(["name", "message"])); $user = UserModel::isAuthorized(); $data['post_id'] = $post_id; $data['message'] = strip_tags($data['message']); if ($user) { $data['user_id'] = $user->id; } else { $data['name'] = strip_tags($data['name']); } try { $comment = new PostCommentModel(); $comment->setData($data); $comment->save(); $this->redirect("/post/show/{$post->id}#comments"); } catch (Exception $e) { $this->redirect("/post/show/{$post->id}#comments", $e->getMessage()); } }
public function get($post_id) { try { $internalflightBO = parent::get($post_id); if ($internalflightBO != NULL) { Model::autoloadModel("taxonomy"); $taxonomyModel = new TaxonomyModel($this->db); $cityList = $taxonomyModel->getTaxonomyRelationshipByObjectId($post_id, "city"); if (count($cityList) > 0) { $cityBO = $cityList[0]; $internalflightBO->city_name = $cityBO->name; $internalflightBO->city_id = $cityBO->term_taxonomy_id; } $countryList = $taxonomyModel->getTaxonomyRelationshipByObjectId($post_id, "country"); if (count($countryList) > 0) { $countryBO = $countryList[0]; $internalflightBO->country_name = $countryBO->name; $internalflightBO->country_id = $countryBO->term_taxonomy_id; } Model::autoloadModel('tag'); $tagModel = new TagModel($this->db); $tagList = $tagModel->getTaxonomyRelationshipByObjectId($post_id, 'tag'); if ($tagList != NULL && count($tagList) > 0) { $internalflightBO->tag_list = $tagList; } if (isset($internalflightBO->image_id) && $internalflightBO->image_id != "" && is_numeric($internalflightBO->image_id)) { Model::autoloadModel('image'); $imageModel = new ImageModel($this->db); $image_object = $imageModel->get($internalflightBO->image_id); if ($image_object != NULL) { if (isset($image_object->attachment_metadata) && isset($image_object->attachment_metadata->sizes)) { if (isset($image_object->attachment_metadata->sizes->slider_thumb) && isset($image_object->attachment_metadata->sizes->slider_thumb->url)) { $internalflightBO->image_url = $image_object->attachment_metadata->sizes->slider_thumb->url; } elseif (isset($image_object->attachment_metadata->sizes->thumbnail) && isset($image_object->attachment_metadata->sizes->thumbnail->url)) { $internalflightBO->image_url = $image_object->attachment_metadata->sizes->thumbnail->url; } elseif (isset($image_object->attachment_metadata->sizes->post_thumbnail) && isset($image_object->attachment_metadata->sizes->post_thumbnail->url)) { $internalflightBO->image_url = $image_object->attachment_metadata->sizes->post_thumbnail->url; } elseif (isset($image_object->attachment_metadata->sizes->medium) && isset($image_object->attachment_metadata->sizes->medium->url)) { $internalflightBO->image_url = $image_object->attachment_metadata->sizes->medium->url; } elseif (isset($image_object->attachment_metadata->sizes->medium_large) && isset($image_object->attachment_metadata->sizes->medium_large->url)) { $internalflightBO->image_url = $image_object->attachment_metadata->sizes->medium_large->url; } elseif (isset($image_object->attachment_metadata->sizes->large) && isset($image_object->attachment_metadata->sizes->large->url)) { $internalflightBO->image_url = $image_object->attachment_metadata->sizes->large->url; } else { $internalflightBO->image_url = $image_object->guid; } } else { $internalflightBO->image_url = $image_object->guid; } } } return $internalflightBO; } else { return NULL; } } catch (Exception $e) { } return NULL; }