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