Find("category_id=? order by `".$orderBy."` ".$direction, array($this->id)); return $advertArray; } function save() { if($this->_order == null) { $category = new Category(); $categoriesArray = $category->Find('id > 0 order by _order desc limit 1'); $this->_order = $categoriesArray[0]->_order + 1; } parent::save(); return $this->id; } } ?> _order == null) { $advert = new Advert(); $advertsArray = $advert->Find('category_id = '.$this->category_id.' order by _order desc limit 1'); $this->_order = $advertsArray[0]->_order + 1; } parent::save(); return $this->id; } function delete() { $picturesArray = $this->getPictures(); foreach($picturesArray as $picture) { $picture->delete(); } return parent::delete(); } function getCategory() { if($this->category_id == null) { return false; } $category = new Category(); $category->Load('id='.$this->category_id); return $category; } function getPictures() { $picture = new Picture(); $picturesArray =& $picture->Find("advert_id=? order by `_order`", array($this->id)); return $picturesArray; } function getFirstPicture() { $picture = new Picture(); $picturesArray = $picture->Find("advert_id=? order by `_order` limit 1", array($this->id)); if(isset($picturesArray[0])) { return $picturesArray[0]; } else { return false; } } function moveDown() { $advertsArray = $this->Find('_order < '.$this->_order.' and category_id = '.$this->category_id.' order by `_order` desc limit 1'); if(isset($advertsArray[0])) { $tmp = $this->_order; $this->_order = $advertsArray[0]->_order; $advertsArray[0]->_order = $tmp; $this->save(); $advertsArray[0]->save(); return true; } else { return false; } } function moveUp() { $advertsArray = $this->Find('_order > '.$this->_order.' and category_id = '.$this->category_id.' order by `_order` limit 1'); if(isset($advertsArray[0])) { $tmp = $this->_order; $this->_order = $advertsArray[0]->_order; $advertsArray[0]->_order = $tmp; $this->save(); $advertsArray[0]->save(); return true; } else { return false; } } } ?> small = $this->createThumb($file, 50, 37); $this->medium = $this->createThumb($file, 220, 165); $this->large = $this->createThumb($file, 525, 350); } function createThumb($file, $new_w, $new_h) { $src_img = imagecreatefromjpeg($file); // determine original pic's width & height $old_x=imageSX($src_img); $old_y=imageSY($src_img); // determine thumb width & height $width = $height = 0; if ($old_x < $old_y) { $height = ($new_w / $old_x) * $old_y; } else { $width = ($new_h / $old_y) * $old_x; } //if the width is smaller than supplied thumbnail size if ($width < $new_w) { $width = $new_w; $height = ($new_w/ $old_x) * $old_y; } //if the height is smaller than supplied thumbnail size if ($height < $new_h) { $height = $new_h; $width = ($new_h / $old_y) * $old_x; } if($new_h == 0) { $width = $new_w; $height = $new_h = ($new_w/ $old_x) * $old_y; } //resize the image $thumb = imagecreatetruecolor($width , $height); imagecopyresampled($thumb, $src_img, 0, 0, 0, 0, $width, $height, $old_x, $old_y); //create the cropped thumbnail $w =($width/2) - ($new_w/2); $h = ($height/2) - ($new_h/2); $cropped = imagecreatetruecolor($new_w , $new_h); imagecopyresampled($cropped, $thumb, 0,0, $w, $h, $new_w , $new_h ,$new_w, $new_h); $thumb = $cropped; ob_start(); imagejpeg($thumb, null, 90); $data = ob_get_contents(); ob_end_clean(); imagedestroy($thumb); imagedestroy($src_img); return $data; } function save() { if($this->_order == null) { $picture = new Picture(); $picturesArray = $picture->Find('advert_id = '.$this->advert_id.' order by _order desc limit 1'); $this->_order = $picturesArray[0]->_order + 1; } parent::save(); return $this->id; } } ?>