userfrosting / UserFrosting

Modern PHP user login and management framework
https://www.userfrosting.com
Other
1.64k stars 366 forks source link

UFGallery #87

Closed assafv closed 9 years ago

assafv commented 10 years ago

Does anyone know a preferered ( cloud based ) way allowing users to upload a photo to a photo gallery in UF?

I am thinking of creating one. I need to combine a gallery per user and each user will have a profile picture. What DB changes should I apply? Should I save the photos in a blob or as files? Lot's of questions... :| I'd love to hear a best practice if someone knows one.

A

alexweissman commented 10 years ago

Yes, this sounds awesome! To answer your questions:

Storing images

It seems that the general consensus is to store them in files, and then store the file paths in the database. See https://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay. We've run into some developers having permissions-related trouble with letting PHP create files; be sure you provide instructions for this in your plugin/installer. I'd also recommend some kind of file system structure for images. Perhaps something like: <user_id>/<gallery_id>/image1.whatever

Database structure

You'll need table(s) to store the image paths. A simple strategy would be to put all the images in one big photos table, with the following columns:

id user_id gallery_id filename

To implement the profile picture, simply add an extra column profile_photo_id to the users table.
You'd also want a galleries table:

id user_id

Do you also want to allow users to share/collaborate on galleries? If not, and every gallery has exactly one user associated with it, you could drop the user_id column from the photos table. Otherwise, you'll have a many-to-many relationship, and so you'd need an additional user_gallery_matches table.

Once you get that working, you'd need to create the database CRUD functions, secure functions (to control which users can access which photos), and a frontend interface.

assafv commented 10 years ago

In light of latest developments in UF ( i.e templating system etc'.. ), should I hold this feature progress? Should I wait for a stable version? What do you think guys?

alexweissman commented 10 years ago

I'd probably hold off, since it seems like your feature is heavily DB-driven. I'm hoping we can get started with an ORM soon that would make CRUD operations a lot easier to implement for new tables/columns/etc.

alexweissman commented 10 years ago

Actually, would you want to play around with RedBean and see if it would be a good ORM solution for UF?

lilfade commented 10 years ago

I was wondering if we looked at any other ORM's i was messing with medoo (http://medoo.in/) lastnight and it seems to work pretty snappy and is pretty simple to learn. I did check out redbeans but im still unsure of how to use it properly and i think people might have a slight problem with that. Although i do like how it can create tables and modify schemas on the fly without knowing to much sql.

I'd like it as a orm but like i said i have no idea of how to use it properly.

Medoo on the other hand works pretty good even on joins -> https://github.com/lilfade/UserFrosting/blob/dev/blog/class.blog.php

alexweissman commented 10 years ago

medoo looks promising; it's zero-config and seems to have a fairly active community. However, it works at a pretty low level, and seems to be little more than a shorthand notation for building SQL queries.

I'm a little worried about how easy it would be to implement complex joins and filtering. For example, it should make it easier to execute a query like "Find all users who are members of group 'Hydralisks' whose names begin with the letter 'm'".

With medoo, we'd still have to figure out all the inner and outer joins for this kind of query. The thing I kind of liked about redbean is that it automatically handles one-to-many and many-to-many relationships.

lilfade commented 10 years ago

Yea i have a butt load of work to do tonight at work oddly enough, but if i get a bit ill mess with it and see if i can get it all figured out and see how it works. The thing im worried about with redbean is this command if someone were able to execute there own code ...

//To destroy the entire database simply invoke the nuclear method (be careful!):
R::nuke();
lilfade commented 10 years ago

Have a bit of free time at work so far and i start messing with it seems easy to use now that i take a look at the small tutorials they have up on the site. I think this would be a huge saver of time, i really like the way you can load and create on the fly ... medoo didnt have nothing like this unless you wrote the query on your own. I think this would be a great addition to UF ill mess with it some more and learn a bit more and start doing a test to transition a few functions over to use this and see how it goes ... update may be tonight or in the am after i get off ^_^

lilfade commented 10 years ago

Upon further checking we will need to do a massive rename of all the tables in the db as well and while were doing that the field names as well to make it more uniform although it's not needed. But the table names must not include _'s in the name so for instance uf_group_action_permits becomes ufGroupActionPermits ... hopefully this wont become to confusing but in the long run i think this will be better. Like i said ill mess with this tomorrow and do some tests to ensure we can use this easily ^_^

Kind of amazing how far we've come from UserCake what a major change haha.

assafv commented 10 years ago

I`ll just put that here... http://emberjs.com/

alexweissman commented 10 years ago

@lilfade I wouldn't worry too much about nuke. If someone can execute their own code on the server, they can just as easily execute DROP DATABASE userfrosting.

Thanks for looking into RedBean. If we need to rename a few tables to follow their convention, I think that'd be fine. We can do another major release with instructions for porting.