Ejemplo n.º 1
0
 /**
  * Metodo que obtiene todos los posts que coinciden su titulo.
  * @param string $value Titulo.
  * @return Posts|bool Si es FALSE, no hay datos.
  */
 public static function selectByTitle($value)
 {
     $val = "%{$value}%";
     $parameter = ':' . Post::POST_TITLE;
     $where = Post::POST_TITLE . " LIKE {$parameter}";
     $prepare[] = DBController::prepareStatement($parameter, $val, \PDO::PARAM_STR);
     $select = self::select(Post::getTableName(), $where, $prepare);
     return self::getInstanceData($select);
 }
Ejemplo n.º 2
0
 /**
  * Metodo que obtiene todos los usuarios que coinciden con su nombre real.
  * @param string $val
  * @return Users
  */
 public static function selectByName($val)
 {
     $value = "%{$val}%";
     $parameter = ':' . User::USER_NAME;
     $where = User::USER_NAME . " LIKE {$parameter}";
     $prepare[] = DBController::prepareStatement($parameter, $value, \PDO::PARAM_STR);
     $select = self::select(User::getTableName(), $where, $prepare);
     return self::getInstanceData($select);
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * Metodo que guarda los datos establecidos.
  * @param string $parameter Indice a buscar. EJ: ":ID"
  * @param string $value Valor del indice.
  * @param int $dataType Tipo de dato. EJ: \PDO::PARAM_*
  */
 private function addPrepare($parameter, $value, $dataType)
 {
     $this->prepareStatement[] = DBController::prepareStatement($parameter, $value, $dataType);
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }
Ejemplo n.º 6
0
 /**
  * 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'];
 }