By Tim Hunt on Monday, 19 March 2018
Posted in General Issues
Replies 7
Likes 0
Views 497
Votes 0
Hi there

I'm adding some custom field values onto a layout override for mod_easysocial_events but I'm having trouble getting the right value back for a File field type. The usual:


$event->getFieldValue("FIELDNAME")


is just returning an array, and if I look at that array there doesn't seem to be anything like a URL, just the id and filename. Is there a specific method please for generating the download url/link for a file field?

I've had a dig around in the component but can't find anything I'm afraid. On the profile page File fields have a link to a download process rather than direct to the file itself and this is what I'd like, or just the URL itself if that's not possible.

Many thanks
Tim
Hey Tim,

Currently we do not have a method to display those file download link, but you can try this following method and see how it goes.



$fileFieldData = $event->getFieldValue('FILE-SUPERMAN');
$files = array();

foreach ($fileFieldData->value as $value) {
$data = json_decode($value);

if (empty($data)) {
continue;
}

foreach ($data as $fileData) {

$table = ES::table('file');
$state = $table->load($fileData->id);

if ($state) {

$table->downloadLink = ESR::fields(array('group' => 'event', 'element' => $fileFieldData->element, 'task' => 'download', 'id' => $fileFieldData->field_id, 'uid' => $fileData->id, 'external' => true, 'clusterId' => $fileFieldData->uid, 'clusterType' => $fileFieldData->type));
$table->previewLink = ESR::fields(array('group' => 'event', 'element' => $fileFieldData->element, 'task' => 'preview', 'id' => $fileFieldData->field_id, 'uid' => $fileData->id, 'external' => true, 'clusterId' => $fileFieldData->uid, 'clusterType' => $fileFieldData->type));

$files[] = $table;
}
}
}


if (!empty($files)) {

foreach ($files as $file) {
echo $file->downloadLink;
}
}
·
Tuesday, 20 March 2018 12:53
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Tim,

Can you provide the output that you are receiving at your end?
·
Monday, 19 March 2018 23:43
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Mark

Many thanks for the reply! Here's what I've tried and what I'm getting outputted:

echo $event->getFieldValue('AGENDA');
just returns "Array" in plain text, so if I print_r this rather than just echo I get

SocialFieldValue Object
( [unique_key] => AGENDA [element] => file [field_id] => 582 [uid] => 23 [type] => event [value] => Array ( [data] => [{"id":96,"name":"Learning Event Agenda 180117.doc"}] [raw] => Learning Event Agenda 180117.doc ) [raw] => Array ( [data] => [{"id":96,"name":"Learning Event Agenda 180117.doc"}] [raw] => Learning Event Agenda 180117.doc ) [data] => Array ( [data] => [{"id":96,"name":"Learning Event Agenda 180117.doc"}] [raw] => Learning Event Agenda 180117.doc ) )


So I can see the field is there with the filename I'm expecting, but no obvious method of directly generating a hyperlink for it like there is on the event's About page.

I suppose I could manually build a url using the values from the array and knowing how the url is structured (on the event page it's /network/fields/event/file/download/582/96?clusterId=23&clusterType=event), but I'd hoped there would be a method in there somewhere that would do this for me

Many thanks
Tim
·
Tuesday, 20 March 2018 03:17
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Arlex

That works perfectly thank you so much, I really appreciate it! Added bonus that this works perfectly for fields with multiple file uploads too (which would have inevitably been my next question )

Just to make sure I follow this - does ES::table() relate directly to querying the database tables, and ESR::fields() is the routing function?

Many thanks again to both you and Mark, excellent support as always
·
Wednesday, 21 March 2018 02:28
·
0 Likes
·
0 Votes
·
0 Comments
·
You're most welcome.

does ES::table() relate directly to querying the database tables

If you saw some of the place call this like ES::table('file'); , it actually will call to this table method from this file
JoomlaFolder/administrator/components/com_easysocial/includes/easysocial.php , and based on what first argument you pass in, it will call this file -> JoomlaFolder/administrator/components/com_easysocial/tables/file.php and all the Easysocial table class will extend to Joomla JTable class as well, so you can just call load, store, delete method.

ESR::fields() is the routing function?

Yes, it will call this file to route the permalink for the field.JoomlaFolder/administrator/components/com_easysocial/includes/router/adapters/fields.php
·
Wednesday, 21 March 2018 10:12
·
0 Likes
·
0 Votes
·
0 Comments
·
Many thanks again Arlex that's fantastic I hadn't looked into the routing before so that's really useful!

Many thanks again
Tim
·
Sunday, 25 March 2018 21:53
·
0 Likes
·
0 Votes
·
0 Comments
·
You are most welcome Tim, glad that your issue is resolved now.

Just for your information, I have locked and marked this thread as resolved to avoid confusions in the future. Please start a new thread if you have any other issue in the future so it will be easier for us to manage your inquiries.

Thanks for understanding
·
Sunday, 25 March 2018 22:23
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post