In a website I have four sections: Events, Locations, News and Formats
All of them have 4 type of images:
How would you design the database, the classes and the filesystem?
Below my ideas:
FILESYSTEM
img/
locations/
25(location id from db)/
big/
small/
gallery/
descripton/
events/
news/
formats/
DATABASE AND CLASSES
big and small images would go as fields in the location, events, news and formats tables
1) one big table for all the gallery images like:
gallery:
id
type_id (location, events, news and formats)
filename
and then four tables like:
locations_gallery:
location_id
gallery_id
etc....
With this approach I'd create a IGalleryDAO like:
interface IGalleryDAO
{
GetImages (typeId, id);
SaveImages (images[], typeId, id);
}
Then the four classes location, events, news and formats would append the path to the filenames and use them
2) four tables, one for each location, events, news and formats like:
locations_gallery:
location_id
filename
etc...
With this approach, I'd create this:
interface IGalleryDAO
{
GetImages (typeId, id);
SaveImages (images[], typeId, id);
}
abstract class GalleryDAO implements IGalleryDAO
{
abstract getFilePath (); // to ensure the filepath variable
abstract GetImages (id);
abstract SaveImages (id, images[]);
}
class LocationGalleryDAO extends GalleryDAO
{
function GetFilePath (){};
function GetImages (id){};
function SaveImages (id, images[]){};
}
The same would be applied to descriptions images as well
What do you suggest?
Thanks in advance for your suggestions
I would include the image path (and not the image) inside the database. Yes, a lot of databases have options for images, though there are very good reasons not to use those functionalities. One of them is that there are very good frameworks available for organizing images, and if you decide you would like use any of those in the future, your hands would be tied behind your back.
An example of a table you could have in your database for that purpose would be:
Table: images
__________________________
| id | path | type |
|------+----------+--------|
| 1 | /img/s/1 | s |
|------+----------+--------|
| 2 | /img/b/2 | b |
|------+----------+--------|
| 3 | /img/g/3 | g |
|------+----------+--------|
| 4 | /img/s/4 | s |
|------+----------+--------|
| 5 | /img/d/5 | d |
Where the path would be extracted and then used in your html: <img src='{$path}'>
. The type column is useful for when you want to query certain images, and if you have a particular need in the future for other types of queries, you could add columns accordingly.
id would be your PRIMARY KEY
, however some people prefer to use dates as a primary key, though this is completely up to you. If you were to use dates, that would serve the purpose of logging when a particular image was stored in your database.