Schema question

Permalink
I am trying to understand better how everything related to each other in C5. To that end, I tried to find the connection between a banner image and a page.

For example, I have a page called "relay", which has a banner, which holds the filename "relay.jpg". The query...

SELECT DISTINCT
CollectionVersions.cvName,
AttributeKeys.akHandle
FROM
AttributeValues
Inner Join CollectionAttributeValues ON CollectionAttributeValues.avID = AttributeValues.avID
Inner Join CollectionVersions ON CollectionVersions.cID = CollectionAttributeValues.cID
Inner Join AttributeKeys ON AttributeValues.akID = AttributeKeys.akID
WHERE
CollectionVersions.cvName LIKE  '%relay%' AND
AttributeKeys.akHandle =  'banner'


results in

+--------+----------+
| cvName | akHandle |
+--------+----------+
| Relay  | banner   |
+--------+----------+


But where is the relationship between that and this...
SELECT
FileImageThumbnailPaths.path
FROM
FileImageThumbnailPaths
WHERE
FileImageThumbnailPaths.path LIKE  '%relay.jpg'
+----------------------------------------------------------------------+
| path                                                                 |
+----------------------------------------------------------------------+
| /thumbnails/file_manager_listing/8415/0613/7514/relay.jpg    |
| /thumbnails/file_manager_listing_2x/8415/0613/7514/relay.jpg |
+----------------------------------------------------------------------+


(p.s. is /thumbnails/file_manager_listing_2x/ a mirror copy, or somthig like that?)

So, if anyone happens to know this I would be very interested in the answer.

Thanks

ntisithoj
View Replies: View Best Answer
mnakalay replied on at Permalink Reply
mnakalay
Hello,

There are actually several aspects to your question. I am going to try to explain in a way that makes sense (hopefully).

First, you have the page.

Then from what I can from your example, you have what is called a page attribute. A page attribute is basically a piece of data you can attach to your page so you can re-use it later when the page is used. Those attributes can be text strings, they can be references to other pages, they can be practically anything. In your case, the page attribute contains a reference to an image.

Typically, when your page loads, you can grab the attribute and the file it references and uses that file on your page, for instance in a banner. Or if you add a page list block on another page to list your site's pages, you can ask the page list to use that attribute to show an image alongside the page's listing.

In COncrete5, there is a very powerful system that allows you to create thumbnails with various dimension sets out of your images. Those dimension sets are called thumbnail types. You create a thumbnail type, give it a name, specify width and height and whether the image should be cropped when the thumbnail is created.
In your case you are looking at a thumbnail created by the thumbnail type File Manager Listing, hence the directory file_manager_listing. This thumbnail type is created by C5 itself and those thumbnails are the ones used in the file manager to show you a small representation of your images.

One really cool trick C5 uses is, when creating those thumbnails, it also automatically creates a second thumbnail with twice the size. So say your thumbnail type specifies dimensions of 200 x 200, 2 thumbnails are then created per image one which is 200 x 200 and the other 400 x400. The bigger thumbnail will be used on Retina screens or high-density screens.
This is why you have the other path file_manager_listing_2x this is where the bigger thumbnails are.

So to summarize:
You have a page
You have an attribute attached to that page
That attribute holds a reference to an image in your file manager
That image has several thumbnails
Those thumbnails dimensions are defined by thumbnail types
Each image gets 2 thumbnails per thumbnail type: 1 normal size and one double size.

Hope that helps.
ntisithoj replied on at Permalink Reply
ntisithoj
Thanks. This is useful when trying to access the attribute via the code, for sure. I am still confused as to the actual query one would make to show that relationship.
Gondwana replied on at Permalink Reply
Gondwana
Generally speaking, you should try to avoid directly querying the database but should use the API instead.

However, if you're like me and can't resist trying to find out what's going on under the hood, you can use a database dump/backup tool to produce a human-readable (SQL) version of your site's database. You really only need the schema (structure) and not the data itself, unless you're trying to trace a particular data item. In particular, look for foreign key (FK) relationships between tables.

It's a bit overwhelming and you don't get much helpful documentation, but some things can be gleaned.
mnakalay replied on at Permalink Best Answer Reply
mnakalay
Like Gondwana said, querying the database directly is not a good idea and Concrete5 offers all the functions you could need.

For instance, to get the Thumbnail attribute which has a handle of "thumbnail" for the current page, first you would grab the current page object like so:
$page = \Page::getCurrentPage();

Then you would grab the attribute for that page:
$myThumbnail = $page->getAttribute('thumbnail');

This code will return an image object which contains data about your image and functions to get that data.

If your attribute had a handle of "my_example_attribute" you would do
$myAttribute= $page->getAttribute('my_example_attribute');


Using the thumbnail example, now that we have our $myThumbnail variable containing our image object, we can get information like for instance the value of the title of the image and its relative path so we can display it on our page.

$title = $myThumbnail->getTitle();
$path = $myThumbnail->getRelativePath();


getTitle() and getRelativePath() are 2 functions that are made available by the image object. Other objects have other functions.
ntisithoj replied on at Permalink Reply
ntisithoj
Excelent, thanks