artista_imagen_id = $data["artista_imagen_id"]; if ( isset( $data["artista_id"])) $this->artista_id = $data["artista_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_imagen_id ) { $result = ConnectionFactory::getFactory()->getByArray("artista_imagen", array("artista_imagen_id"), array($artista_imagen_id), "ArtistaImagen"); return $result["object"]; } public static function getAllList($aid) { $result = ConnectionFactory::getFactory()->getList("artista_imagen", "ArtistaImagen", null, array("artista_id = $aid"), "orden" ); return (array("results" => $result["list"], "totalRows" => $result["totalRows"])); } public function delete() { $result = ConnectionFactory::getFactory()->delete("artista_imagen", "artista_imagen_id", $this->artista_imagen_id); ArtistaImagen::reorderSliders($this->orden, $this->artista_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 artista_imagen where artista_id = $this->artista_id") + 1; $fields = array("artista_id","imagen","orden","titulo"); $result = ConnectionFactory::getFactory()->insert($this, "artista_imagen", $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_imagen_id ) ) trigger_error ( "Update error", E_USER_ERROR ); $error = $this->validateBeforeInsert(); if (!$error){ $fields = array("artista_id","imagen","titulo"); $error = ConnectionFactory::getFactory()->update($this, "artista_imagen", $fields, "artista_imagen_id"); if ($error) $error = array($error); } return array("error" => $error, "id" => $this->artista_imagen_id); } public static function moveUp($order, $aid){ $mysqli = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); $sql = $mysqli->prepare("update artista_imagen set orden = 0 where orden = $order and artista_id = $aid" ); $sql->execute(); $sql = $mysqli->prepare("update artista_imagen set orden = $order where orden = $order - 1 and artista_id = $aid" ); $sql->execute(); $sql = $mysqli->prepare("update artista_imagen set orden = ($order - 1) where orden = 0 and artista_id = $aid" ); $sql->execute(); } public static function moveDown($order, $aid){ $total = getTotalRows("select count(*) c from artista_imagen"); if ($order < $total){ $mysqli = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); $sql = $mysqli->prepare("update artista_imagen set orden = 0 where orden = $order and artista_id = $aid" ); $sql->execute(); $sql = $mysqli->prepare("update artista_imagen set orden = $order where orden = $order + 1 and artista_id = $aid" ); $sql->execute(); $sql = $mysqli->prepare("update artista_imagen set orden = ($order + 1) where orden = 0 and artista_id = $aid" ); $sql->execute(); } } public static function reorderSliders($from, $aid){ $mysqli = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); $sql = "update artista_imagen set orden = (orden - 1) where orden > $from and artista_id = $aid"; $sql = $mysqli->prepare($sql ); $sql->execute(); } } ?>