propiedad_galeria_id = $data["propiedad_galeria_id"]; if ( isset( $data["propiedad_id"])) $this->propiedad_id = $data["propiedad_id"]; if ( isset( $data["imagen"])) $this->imagen = $data["imagen"]; if ( isset( $data["video"])) $this->video = $data["video"]; if ( isset( $data["orden"])) $this->orden = $data["orden"]; if ( isset( $data["titulo"])) $this->titulo = $data["titulo"]; } public static function getById( $propiedad_galeria_id ) { $result = ConnectionFactory::getFactory()->getByArray("propiedad_galeria", array("propiedad_galeria_id"), array($propiedad_galeria_id), "PropiedadGaleria"); return $result["object"]; } public static function getAllList($pid) { $result = ConnectionFactory::getFactory()->getList("propiedad_galeria", "PropiedadGaleria", null, array("propiedad_id = $pid"), "orden" ); return (array("results" => $result["list"], "totalRows" => $result["totalRows"])); } public function delete() { $result = ConnectionFactory::getFactory()->delete("propiedad_galeria", "propiedad_galeria_id", $this->propiedad_galeria_id); PropiedadGaleria::reorderSliders($this->orden, $this->propiedad_id); } public function validateBeforeInsert(){ $error = false; return $error; } public function insert() { $error = $this->validateBeforeInsert(); $id = "0"; if (!$error){ $this->orden = getTotalRows("select count(*) c from propiedad_galeria where propiedad_id = $this->propiedad_id") + 1; $fields = array("propiedad_id","imagen","video","orden","titulo"); $result = ConnectionFactory::getFactory()->insert($this, "propiedad_galeria", $fields); if ($result["error"]) $error = array($result["error"]); $id = $result["id"]; } return array("error" => $error, "id" => $id); } public function update() { if ( is_null( $this->propiedad_galeria_id ) ) trigger_error ( "Update error", E_USER_ERROR ); $error = $this->validateBeforeInsert(); if (!$error){ $fields = array("propiedad_id","imagen","video","titulo"); $error = ConnectionFactory::getFactory()->update($this, "propiedad_galeria", $fields, "propiedad_galeria_id"); if ($error) $error = array($error); } return array("error" => $error, "id" => $this->propiedad_galeria_id); } public static function moveUp($order, $pid){ $mysqli = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); $sql = $mysqli->prepare("update propiedad_galeria set orden = 0 where orden = $order and propiedad_id = $pid" ); $sql->execute(); $sql = $mysqli->prepare("update propiedad_galeria set orden = $order where orden = $order - 1 and propiedad_id = $pid" ); $sql->execute(); $sql = $mysqli->prepare("update propiedad_galeria set orden = ($order - 1) where orden = 0 and propiedad_id = $pid" ); $sql->execute(); } public static function moveDown($order, $pid){ $total = getTotalRows("select count(*) c from propiedad_galeria"); if ($order < $total){ $mysqli = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); $sql = $mysqli->prepare("update propiedad_galeria set orden = 0 where orden = $order and propiedad_id = $pid" ); $sql->execute(); $sql = $mysqli->prepare("update propiedad_galeria set orden = $order where orden = $order + 1 and propiedad_id = $pid" ); $sql->execute(); $sql = $mysqli->prepare("update propiedad_galeria set orden = ($order + 1) where orden = 0 and propiedad_id = $pid" ); $sql->execute(); } } public static function reorderSliders($from, $pid){ $mysqli = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); $sql = "update propiedad_galeria set orden = (orden - 1) where orden > $from and propiedad_id = $pid"; $sql = $mysqli->prepare($sql ); $sql->execute(); } } ?>