• REGISTRATION REQUIREMENTS:

    Your username here MUST MATCH your XenForo username (connected to your XF license).

    Once you have registered here, then you need to start a conversation at xenforo.com w/Bob and provide the following:
    1. Your XenForo License Validation Token
    2. The Domain Name associated with the License
    NOTE: Your account will be validated once ALL requirements are verified/met. Thank you for your patience.

Thumbnail in another addon?

nrep

Member
Showcase
I'm making an addon which requires the use of some showcase thumbnails. I'm a novice coder so I'm learning as I go along :).

I've managed to get things like the showcase title, username etc.. by using a MySQL query:

Code:
 $showcaseInfo = $db->fetchAll("
SELECT item_id, username, item_name, description
FROM xf_nflj_showcase_item
WHERE item_id IN (".$ShowcaseIDs.")
");

I can then construct links to the URL by using something like /showcase/$showcaseID which redirects to the correct URL.

However, I can't seem to fetch the thumbnail URL as a variable. I saw that XF has this bit of code available, but I'm not sure how I can use it to fetch the showcase thumbnail:

Code:
XenForo_Model::create('XenForo_Model_Attachment')->getAttachmentThumbnailUrl($data);

I know this is beyond normal support, but if anyone has an idea how I can access a thumbnail URL when I've got a item_ID and cover_image_ID for a showcase entry then I would be very grateful.
 
I've made a tiny bit of progress, as I can now get some further thumbnail data - just not enough to form a URL:

Code:
    $thumb1 = $showcaseInfo[1]['cover_image_id'];
    $thumb1 = $thumbModel->getAttachmentById($thumb1);
    print_r($thumb1);

This gives:

Array
(
[attachment_id] => 76590
[data_id] => 44481
[content_type] => showcase_item
[content_id] => 34
[attach_date] => 1414209514
[temp_hash] =>
[unassociated] => 0
[view_count] => 11
[filename] => _MG_4189.jpeg
[file_size] => 143310
[file_hash] => 0bef21d5cdc824f35405342bed9d1649
[width] => 1280
[height] => 854
[thumbnail_width] => 300
[thumbnail_height] => 300
)
 
Almost there! I can use this, but it only gives a tiny 100px attachment, rather than the 300px one used in the showcase:

Code:
    $thumb1 = $showcaseInfo[1]['cover_image_id'];
    $thumb1 = $thumbModel->getAttachmentById($thumb1);
    $thumb1 = $thumbModel->getAttachmentThumbnailUrl($thumb1);
 
I think I've got the answer for anyone else in the same situation, I hope this helps:

PHP:
    $scItemModel = XenForo_Model::create('NFLJ_Showcase_Model_Item');
    $scAttachmentModel = XenForo_Model::create('NFLJ_Showcase_Model_Attachment'); 
    $thumbModel = XenForo_Model::create('XenForo_Model_Attachment');
    $thumb1 = $showcaseInfo[1]['cover_image_id'];
    $thumb1 = $thumbModel->getAttachmentById($thumb1);
    $thumb1 = $scAttachmentModel->getAttachmentThumbnailUrl($thumb1);
 
Look at the prepareItems and prepareItem methods in the Item Model. That will show you how attachments are being fetched and prepared for a single item vs multiple items.
 
Back
Top