Details of the advertiser permissions flow can be found on the Use Cases - RocReadaR Portal page.
You should understand the schema (Available here Database Schema Diagram), particularly the structure of Publisher, Publication, PublicationIssue, PublicationIssuePage, PublicationIssuePageMedia, Advertiser, and AdvertiserPublicationPermission.
So there's a couple basic ideas for this at the business level:
First, before publishers and advertisers can associate, they need to have a record in the PublisherAdvertiser table. So on the page where they can associate, the advertisers with a record for the current publisher should be shown, and all the others should be shown to be added. This table should then be what you can use to load the advertisers that a publisher can choose to give permission to a page.
Second, when a publisher edits the media for a page (PublicationIssuePage) they can give permission to an advertiser by creating a new record in the AdvertiserPublicationPermission. This record links a publication page (PublicationIssuePage) to an Advertiser. The record should have the PublicationIssuePageID and Advertiser being linked. It should also have the UserID of the user it was created by, and the time of creation.
The record created as the AdvertiserPublicationPermission then grants the advertiser permissions to work on that page. However, when READING media (for the RocReadaR App by image recognition), this should be ignored. Details of how this is taken care of is described below. When an advertiser is logged in, the AdvertiserPublicationPermission lets you know which pages the advertiser can work on.
Assuming the AdvertiserPublicationPermission is in place, the advertiser can now create PublicationIssuePageMedia for the PublicationIssuePages available. When they are created, the AdvertiserUserID_CreatedBy is marked with the UserID of the currently logged in user (who is an advertiser). The PublisherUserID_CreatedBy should be null. On the other side, when a publisher creates PublicationIssuePageMedia, the AdvertiserUserID_CreatedBy should be null. When the PublicationIssuePageMedia is created by an any user, the PublisherUserID_AdApprovedBy and DateApproved fields should be null.
Now that the PublicationIssuePageMedia is in place with a AdvertiserUserID_CreatedBy record, users of the publisher that own the PublicationIssuePage should be able to see the media. You can find these for a publisher by getting the PublicationIssuePageMedia with a AdvertiserUserID_CreatedBy and null PublisherUserID_AdApprovedBy. The publisher can then view the media. If the publisher approves the media, PublisherUserID_AdApprovedBy should be set to the current user, and the DateApproved should be set to the current time.
When recognition of an image occurs and media is to be sent to the RocReadaR App, only PublicationIssuePageMedia with a PublisherUserID_CreatedBy not null OR both AdvertiserUserID_CreatedBy is not null AND PublisherUserID_AdApprovedBy is not null. To reiterate, to find valid media it should be: media where (media.PublisherUserID_CreatedBy != NULL OR (AdvertiserUserID_CreatedBy != NULL AND PublisherUserID_AdApprovedBy != NULL))