/** * Metodo que inserta los datos. * @return bool Si es TRUE, todo se realizo correctamente. */ public function insert() { $db = DBController::getConnection(); $table = PostCategory::getTableName(); $count = \count($this->categoriesID); $error = \FALSE; for ($i = 0; $i < $count && !$error; ++$i) { $categoryID = $this->categoriesID[$i]; $this->prepareStatement = []; $this->prepare($categoryID); $error = !$db->insert($table, self::$COLUMNS, self::$VALUES, $this->prepareStatement); } return !$error; }
/** * Metodo que borra los datos. * @return bool Si es TRUE, todo se realizo correctamente. */ public function delete() { $db = DBController::getConnection(); $table = PostCategory::getTableName(); $parameterCategoryID = PostCategory::RELATIONSHIPS_CATEGORY_ID; $parameterPostID = PostCategory::RELATIONSHIPS_POST_ID; $where = "{$parameterCategoryID} = :{$parameterCategoryID} AND {$parameterPostID} = :{$parameterPostID}"; $count = \count($this->categoriesID); $error = \FALSE; for ($i = 0; $i < $count && !$error; ++$i) { $categoryID = $this->categoriesID[$i]; $this->prepareStatement = []; $this->prepare($categoryID); $error = !$db->delete($table, $where, $this->prepareStatement); } return !$error; }
/** * Metodo que agrega las relaciones post-categoría. * @param PostCategory $postCategory */ public function addPostCategory(PostCategory $postCategory) { $this->postsID[$postCategory->getCategoryID()][] = $postCategory->getPostID(); $this->categoriesID[$postCategory->getPostID()][] = $postCategory->getCategoryID(); }