Created
December 18, 2012 03:22
-
-
Save taylorlapeyre/4324728 to your computer and use it in GitHub Desktop.
Example Gallery class in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gallery class. | |
* A Gallery holds images which can be formatted to html | |
* and displayed onto the a web page | |
*/ | |
class Gallery | |
{ | |
public $id; | |
public $name; | |
public $description; | |
public $defaultImageId; | |
public $images = array(); | |
public function __construct($id, $name, $description) | |
{ | |
$this->id = $id; | |
$this->name = $name; | |
$this->description = $description; | |
} | |
public function addImage(GalleryImage $image) | |
{ | |
$this->images[] = $image; | |
} | |
public function removeImage($imageId) | |
{ | |
unset($this->images[$imageId]); | |
} | |
public function setDefaultImage($imageId) | |
{ | |
this->defaultImageId = $imageId; | |
} | |
public function showImages() | |
{ | |
if (sizeof($this->images) == 0) | |
return "Gallery is empty"; | |
foreach($this->images as $image) | |
$image.toHtml(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment