Update many sub documents where match using PHP - php

I have a document of photos and on those photos I have sub array of arrComments. Each of the sub documents as a commenters profile picture (naturally there could be multiple comments on a single photo by the same user...)
When the user updates their profile picture, I want to update all of their profile picture references in all of the nested document comments for every picture.
I'm using PHP Mongodb driver for this btw.
I tried this:
...etc...updateMany(
array("arrComments.userOID"=>$userID),
array('$set'=>array('arrComments.$.userProfileImage'=>$arrFileName))
);
but that only updates the first found comment within each picture... I need ALL comments by a user on ALL images to be updated.

Related

Linking an entity to have several images and videos

I'll try to explain my problem as much as I can.
Let's say I have an entity called Profile. This entity has a few fields (name (string), description (text), birthdate (date))... etc. And I want to add to this entity images and videos, so these would be shown in the user's profile. If it was just one image and one video to upload I would've used a field image (string) and video (text) or something like that. But knowing that I want the user to upload several of each, it won't work.
The images will be uploaded by the user in the form. And for the videos, he needs to paste an embeded tag from any major website.
How to do this please? I thought about creating a junction table for both an image entity and videos entity. But I'm not sure at all if that's the right way to do it either in general or in Symfony specifically.
You should consider the following approach:
- create tables for photos and videos (create entities Photo and Video if you are using Doctrine);
- add column userId to the corresponding tables (add this link property User to the corresponding entities);
- insert/update the corresponding tables (via entities) when a user uploads/edits a new photo or video.
Remember, you have many (in general) photos/videos for one user but only one user (owner) for each photo/video.
If you are using Doctrine this short tutorial about associations mapping will be useful for you:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html

handling images, videos, docs for custom cms

I am in the process of building a CMS using php, however I am struggling on how to handle the various different assets that a dynamic page could serve, typically an average page will contain pictures of various sizes(thumb, body, main, etc), inline images and various different assets(pdf, flv, mp4, doc, etc).
At the moment a user can upload assets and create a folder on the server, I just wanted some techniques and concepts on how to manage this in terms of deleting, editing and linking to my dynamic pages within the cms? I already have a content table which contains all the content(meta_stuff, title, friendly_url, content_text, etc).
On upload should a reference be stored somewhere in say a asset table?
Should all paths to assets(images, docs, videos,etc) be stored in one table? or separate for each asset?
Should multiple image sizes(small, medium, large, etc) be stored in different fields e.g(assetid, smallpath, mediumpath, largepath?
What technique to use to link assets to the dynamic page? should this be a joined table or single? how do I go about retrieving the different assets for a page several pdfs and several images?
How to handle deleting of assets as this could be referenced to another dynamic page?
and anything else you think would be beneficial?
Thanks for all your help
Here are some basic things to keep in mind when dealing with resources (videos, images, documents..) in a scenario similar to what you're describing.
You'd want is to know what's being uploaded, what kind of stuff are being uploaded and who's uploading. To do that, it's good to have the following tables:
Edit: Sorry about the mistake, asset_types.asset_type_id should be linked to assets.asset_type_id and NOT assesst.asset_id
(Note: This is just an outline, of course you'll have more fields)
This model makes it easy to do the following tasks
Upload: When something is uploaded, you store it somewhere (with the correct
.htaccess configurations) then store that path in the table.
Delete: When the user is trying to delete something, you check if he's the owner.
When you want to add a new type, you don't need to create a new table.
Hopefully this will put you in the right direction.
Update: Answering your comment, when a user wants to add an image to an article for example, you have two options here:
The user is presented with a button/select menu/whatever to choose the desired image, once clicked it will add <img src=LINK_TO_RESOURCE" /> to the body of the content (Make sure you protect yourself from XSS).
OR
You use your own simple markup, when the user clicks on an image this [[PREFIX_IMG:IMG_ID]] will be added to the body of the content, when the content is viewed you'll replace that "tag" with <img src="LINK_TO_RESOURCE" /> which you've acquired using IMG_ID.
2nd Update: Well you have a couple of options to handle resources that aren't directly embedded in the "articles" themselves.
You can have a field in the "articles" table you can call summary for example, and one more column to the assets table which you can call asset_sub_type and have different types like summary. Then when you want to view the summary you fetch the summary text/title from database and you add the resource to it.
(This is the technique I use) When fetching the summary from the database I see which image is the database that is related to that article and the resize it on the fly with PHP and append it to the summary.

Showing user-specific 'Limited' albums in Picasa Web Albums on my own site

I need help finding out how to list my albums from Picasa Web Albums on my WordPress site.
My Album Feed shows all my albums when I am logged in, and only the 'Public' ones, when not. And, more importantly, when one of my allowed viewers are logged in, they can see only what I have allowed them to. (Album visibility)
There exists several fancy solutions. Ie. PWA+PHP for WordPress. But common for the ones I have been able to find, are that they option only to show the 'Public' (default) or all the albums. Thus disregarding my 'Limited' list. (ie. email-addresses / Google+ Circles)
Creating a WebApp with access to my albums is thus not a solution, since I wish to give users individual access. Just like if they visited my Picasa site.
Are there suggestions to ways to achieve something like this?
I would like to suggest the Pimax plugin in this case. It will get you very close to your requirement.
What it does -
First of all it will show all you public photos in a Tab. All your public albums in another Tab. (Since you do not want to display all public stuff, you can hide these two Tabs)
How it will address your requirement -
Next if you want to display some specific albums or any featured albums, you can specify the link to those albums. Photos from each of those Albums will be displayed in a separate Tab.
Now, if you want to display all you public Albums except few albums, you can specify those exceptions. Your Albums Tab will now display all public albums except the ones that you wanted to exclude!
Hope this solves the problem of anyone with similar requirement :)

Grouping photos with application machine tags vs. security

I am wondering how should I group my photos inside Flick to be able to read later by API and assign them to a event. So an event should have X photos assigned.
Initially thought that I will organize in Galleries but that has a limit of photos. Next was to organize in Sets, but I couldn't locate if a Set has a limit.
Then I've read about namespace:predicate=value functionality. This is something which could come handy as I can define unique value for each event.
But I have a questions relative to security?
1. Can I define a unique tag per user/application? Can we subscribe to a unique tag per app?
2. Are my tags publicly viewable by the user?
3. Can in the future someone else attach my specific tags to different photos and so SPAM my photo gallery read out by API?
4. Can I exclude some 3rd party photos from the tagging mechanism?
Yes, the easiest way to do this would be the use the app name as the namespace, e.g. app1:predicate=value, app2:predicate=value
Yes, if the photo is public then you can also see the machine tags associated with it.
Anyone can apply a particular tag to their photos. However, you can restrict the API query for all photos with a particular tag so that only photos by a given user are returned, which would stop people spamming your gallery.
If you want to exclude photos from other users from the tagging mechanism, you can either only request photos with a given tag from a given user (this is possible with the API call), or you could moderate each photo so that it only shows up in your gallery once you've checked it (e.g. keep a database table with the photo ID and an approved flag for each photo).

How to store multile images full path into a database so that I can display them in a user home page like Orkut

I am making an application in which every user has to sign in first and then he can access his home page. Now on the home page, I have given an option of uploading an image. Now if the user is uploading one image I am storing the full path of the uploaded image into a database and from there I can display the image easily by an img tag...
But what should I do when the user want to upload many images? Then how should I store their full paths in a database for the same user. Give me an idea just like Orkut or Facebook. Should I make a different table with named images and should I store images in different rows with the same username. What should I do?
I don't know the logic. What should I do? How can I upload many images and how can I store their path and what will be the wisest method and how do I display many images on one page (I can display one)?
You can make a folder, named after user name and id and put all their images there.
To display many images on one page, just add more <img> tags to the page.
This seems to be more of a design question than a PHP question. I would create a separate table to store all paths, this is more normalized.
You still need to handle the UI, but if you are doing a sort of gallery then that is fairly simple with some jQuery sideshows or something like that.
Yes, you want to use a separate table to store the image paths. You'll most likely want a record ID, the User ID, and the path to the image. You could also add a field to contain the sorting order for the images.
Having the sorting order field will allow you to page through the photos if there is more than one page of photos.
Your thinking is correct where you suggest creating a separate table with rows containing the image path and the username. The concept that you are dealing with is called cardinality. I'd recommend that you take a few minutes to read about this concept, since it is so important to database design.
In this case, you're talking about a one-to-many relationship between the user and the images.

Categories