public function post() { $foto = new Inmuebles_Fotos(); $foto->inmueble_id = $this->inmueble->id; $foto->codigo = strtolower($this->codigo); if ($foto->queryAll()) { return ($this->unique = false) && false; } $foto->nombre = $_FILES['foto']['name']; $foto->posicion = Inmuebles_Fotos::pos($this->inmueble->id) + 1; $id = $foto->insert(); Inmuebles_Fotos::upload($_FILES['foto']['tmp_name'], $this->inmuebleCodigo, $foto->codigo); return "/admin/inmuebles/{$this->inmuebleCodigo}/fotos/{$foto->codigo}?added=1"; }
public function get() { $page = Request::getQuery('page', 1); $per = Configuration::getInstance()->per; $start = ($page - 1) * $per; $fotos = array(); $count = 0; $pos = 0; if ($this->inmueble->found()) { $fotos = Inmuebles_Fotos::all(array('inmueble_id' => $this->inmueble->id), array('posicion'), array($start, $per)); $count = Inmuebles_Fotos::count(array('inmueble_id' => $this->inmueble->id)); $pos = Inmuebles_Fotos::pos($this->inmueble->id); } return array('codigo' => $this->codigo, 'inmueble' => $this->inmueble, 'fotos' => $fotos, 'count' => $count, 'start' => $start, 'page' => $page, 'per' => $per, 'pos' => $pos); }
public function init($inmueble, $foto, $mover) { if (!Session::getInstance()->usuario) { return '/admin/ingresar'; } $this->inmuebleCodigo = $inmueble; $this->inmueble = new Inmuebles(); $this->inmueble->codigo = $this->inmuebleCodigo; $this->inmueble->queryAll(); if (!$this->inmueble->found()) { return true; } $this->fotoCodigo = $foto; $this->foto = new Inmuebles_Fotos(); $this->foto->inmueble_id = $this->inmueble->id; $this->foto->codigo = $this->fotoCodigo; $this->foto->queryAll(); if (!$this->foto->found()) { return true; } $this->pos = Inmuebles_Fotos::pos($this->inmueble->id); $this->new = false; $this->signo = substr($mover, 0, 1); $this->cantidad = intval(substr($mover, 1)); switch ($this->signo) { case '+': $pos = $this->foto->posicion + $this->cantidad; if ($pos <= $this->pos) { $this->new = $pos; } break; case '-': $pos = $this->foto->posicion - $this->cantidad; if ($pos > 0) { $this->new = $pos; } break; } return true; }