/** * Metodo que borra el post de la base de datos. * @return bool Si es TRUE, todo se realizo correctamente. */ public function delete() { $db = DBController::getConnection(); $parameter = Model::ID; $where = "{$parameter} = :{$parameter}"; $this->prepare(); return $db->delete($this->table, $where, $this->prepareStatement); }
/** * Metodo que realiza una consulta a la base de datos. * @param string $table Nombre de la tabla. * @param string $where [Opcional] Condiciones. * @param array $prepare [Opcional] Lista de indices a reemplazar en la consulta. * @param string $columns [Opcional] Por defecto "*". Columnas. * @param int $limit [Opcional] Número de datos a retornar. * @param string $orderBy [Opcional] Por defecto "ID DESC". Ordenar por. * @return array|bool Si es FALSE, no hay datos. */ protected static function select($table, $where = '', $prepare = [], $columns = '*', $limit = '', $orderBy = 'ID DESC') { $db = DBController::getConnection(); $fetch = 'fetchAll'; $select = $db->select($table, $fetch, $where, $prepare, $columns, $orderBy, $limit); if (empty($select)) { return \FALSE; } return $select; }
/** * Metodo que realiza el proceso de insertar los datos. * @return bool Si es TRUE, todo se realizo correctamente. */ public function insert() { $db = DBController::getConnection(); $this->prepare(); //En caso de error if ($db->insert($this->table, $this->columns, $this->values, $this->prepareStatement)) { $this->lastInsertId = $db->lastInsertId(); return \TRUE; } return \FALSE; }
/** * 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 actualiza los datos del objeto en la base de datos. * @return bool Si es TRUE, todo se realizo correctamente. */ public function update() { $db = DBController::getConnection(); $parameter = Model::ID; $where = "{$parameter} = :{$parameter}"; /* * Si no hay datos, no se ejecuta la consulta. * Se retorna TRUE para evitar un error. */ if ($this->prepare()) { return \TRUE; } return $db->update($this->table, $this->dataColumns, $where, $this->prepareStatement); }
/** * Metodo que borra los datos. * @return bool Si es TRUE, todo se realizo correctamente. */ public function delete() { $db = DBController::getConnection(); $table = PostTerm::getTableName(); $parameterTermID = PostTerm::RELATIONSHIPS_TERM_ID; $parameterPostID = PostTerm::RELATIONSHIPS_POST_ID; $where = "{$parameterTermID} = :{$parameterTermID} AND {$parameterPostID} = :{$parameterPostID}"; $count = \count($this->termsID); $error = \FALSE; for ($i = 0; $i < $count && !$error; ++$i) { $termID = $this->termsID[$i]; $this->prepareStatement = []; $this->prepare($termID); $error = !$db->delete($table, $where, $this->prepareStatement); } return !$error; }
/** * Metodo que realiza una consulta a la base de datos. * @param string $where [Opcional] Condiciones. * @param array $prepare [Opcional] Lista de indices a reemplazar en la consulta. * @param string $columns [Opcional] Por defecto "*". Columnas. * @param int $limit [Opcional] Numero de datos a retornar. * @return PostsCategories */ private static function select($where = '', $prepare = [], $columns = '*', $limit = '') { $db = DBController::getConnection(); $table = PostCategory::getTableName(); $fetch = 'fetchAll'; $select = $db->select($table, $fetch, $where, $prepare, $columns, '', $limit); $postsCategories = new PostsCategories(); $postsCategories->addPostsCategories($select); return $postsCategories; }
/** * Metodo que obtiene el número de POST realializados. * @return int */ public function getCountPosts() { $db = DBController::getConnection(); $table = Post::getTableName(); $fetch = 'fetchAll'; $userIDPost = Post::USER_ID; $where = "{$userIDPost} = :{$userIDPost}"; $prepare = [DBController::prepareStatement(":{$userIDPost}", $this->getID(), \PDO::PARAM_INT)]; $columns = 'COUNT(*) AS count'; $select = $db->select($table, $fetch, $where, $prepare, $columns); return $select[0]['count']; }