Module

Archived
Forum
(read-only)


For official support, visit the official support site »

Link Vault

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5

Back to this add-on's main page
View Other Add-ons From Masuga Design

1 of 2
1
   

Getting Matrix row fields for Records tag pair

Support (Resolved)

OliverHood
OliverHood

Hi,

I’m trying to get a ‘top 5 downloads’ type thing sorted for a client’s site.

The existing site has a channel called ‘Topics’, each topic has an entry that has a Matrix field with the columns ‘Link’ and ‘File’. The topic pages are setup so they list all the files per topic entry from the Matrix field.

I’m not having an issue getting the download to actually work, but what I need is the name of the Matrix column filed ‘Link’ as the link text itself. Ideally, I need a download count in there too.

This is the code we’re using so far:

{exp:link_vault:records limit="5"}<a href="{directory}{file_name}">Download</a>{/exp:link_vault:records} 

Is using the File Vault customfields and passing the Matrix cell to that a possibility?

I’m sure I’m missing something simple, but I can’t see it.

Any help is appreciated.

OliverHood
# 1
OliverHood

Does anyone have experience with the above?

Ben Kohl
# 2
Ben Kohl

Hi, Oliver. We just released Link Vault 1.2.4 yesterday and there is a new parameter for the :records tag that will allow you to view the top downloads. If you use the group_by parameter to group the results, the census variable becomes available. As an example, I’ll try to mimic your code above. In this case, the census variable will store the count of rows in the table that have the same file_name. This loop will return the five most downloaded files.

{exp:link_vault:records group_by='file_name' order_by='census' sort='desc' limit='5' }
    
<a href='{directory}{file_name}'>Download</a>
{/exp:link_vault:records} 
OliverHood
# 3
OliverHood

Ben, implimented that, great stuff re: ‘census’ (good name for it too.)

I just need the ability to pull in content from the corresponding Matrix cell/row.

Ben Kohl
# 4
Ben Kohl

I recommend creating one or more Link Vault custom fields for storing Matrix Data. For instance, if you’d like to store your Matrix row ID or other Matrix column data with a download record, you could do this :

{matrix_field_name}
    {exp
:link_vault:download_link file_path='{your_path_variable}' 
                                                           
text='Download {file_name}' 
                                                           
cf:row_id='{row_id}'
                                                           
cf:sample_matrix_column='{matrix_column_value}' }
{
/matrix_field_name} 

That way, you could view the Matrix data or use it to retrieve more data within your :records tag.

{exp:link_vault:records group_by='file_name' order_by='census' sort='desc' limit='5' }
    {cf_row_id}
    {cf_sample_matrix_column}

    {exp
:query sql='SELECT * FROM exp_matrix_data WHERE row_id="{cf_row_id}"' }
        {col_id_
#} is some data.
    
{/exp:query}
{
/exp:link_vault:records} 

I hope this helps. Let me know if you have more questions.

 

OliverHood
# 5
OliverHood

Ben, I’m getting kind of lost here, my apologies…

My Matrix field is called ‘Download’, the cell I need to get the data out of is called ‘filename’.

So, for my Link Vault download code (which is in the Matrix ‘Download’ tag pair), I’ve got the following:

{exp:link_vault:download_link file_name="{file}" entry_id="{entry_id}" cf:filenametitle='{filename}'

And on my Top 5 page, I’ve got the following Records tag pair:

{exp:link_vault:records limit="5" orderby="census" group_by="file_name" sort="asc"}
<a href="{directory}{file_name}">{cf_filenametitle} {census} </a>
{/exp:link_vault:records} 

I know I’m missing something as it renders a link to the file correctly, but just shows {cf_filenametitle} as the link text.

Ben Kohl
# 6
Ben Kohl

Did you define the custom field in the control panel? In the Link Vault module settings, there is a page for defining those fields and that must be done in order for the data to be stored and retrieved properly.

OliverHood
# 7
OliverHood

Woops. Missed that bit. I’ve created a new Link Vault custom field called ‘filenametitle’, now the records template is no longer rendering the {cf_filenametitle}, but it’s not showing anything in there either.

Ben Kohl
# 8
Ben Kohl

If you start clicking the download links that have cf:filenametitle specified as a parameter, it should start storing data in that field. You can verify this by examining the exp_link_vault_downloads table in your database. There should be a column at the end of the table called cf_filenametitle and any new downloads that get recorded since you defined that custom field in the CP should show data there. Any records that were generated before that point won’t have data in them.

If the problem persists, then it might be a parse order issue. I’ll look over some of our code here to see how we handled that because I know we store file download data in a Matrix field as well.

Ben Kohl
# 9
Ben Kohl

You may need a parse=‘inward’ on the channel entries loop that has the Matrix field.

OliverHood
# 10
OliverHood

I’ve tried the parse=“inward” parameter, with no luck.

I’ve looked in the exp_link_vault_downloads table and it IS showing the correct field in the ‘cf_filenametitle’ column (since it was added anyway.) So it is almost there, by the look of it.

So, it looks like there may be something in this code that’s at issue?

{exp:link_vault:records limit="5" orderby="census" group_by="file_name" sort="asc" parse="inward"}
<a href="{directory}{file_name}">{cf_filenametitle} {census} </a>
{/exp:link_vault:records} 

 

 

Ben Kohl
# 11
Ben Kohl

I don’t think the :records tag needs the parse=‘inward’.  The encapsulating entries tag might. Also, the “orderby” parameter should be “order_by”.

OliverHood
# 12
OliverHood

Sorting the order_by seems to have done the trick.

One of the entries is finally displaying the download cf_filenametitle, the others aren’t. Now, is it possible that the files that hadn’t had the custom field, but DID register as downloads wouldn’t display the cf_filenametitle, even after being downloaded again after it being added?

I’ve tested a couple of other files and they hadn’t been downloaded before, so it seems to work correctly. So is there a way to reset the download count?

Ben Kohl
# 13
Ben Kohl

The problem you are experiencing is that for a particular file_name, some of the records don’t have the cf_filenametitle populated. When you do a group_by on that file_name, the grouped row may not have that column populated unless all the individual rows are populated. Depending on how many downloads there have been for that file, you might just want to manually populate those custom data fields to have the correct data. Otherwise, you can delete the rows that don’t have the custom field data populated which would basically reset your download count.

OliverHood
# 14
OliverHood

Thanks for that Ben. Looks like I need to talk to my hosts as the table is only showing five rows in PHPMyAdmin.

I know where to look now though, which is good. Cheers.

OliverHood
# 15
OliverHood

After some revisions to the site, it seems the Records list has broken something…

Using this for the download link:

{exp:link_vault:download_link file_name="{file}" entry_id="{entry_id}" text="{filename}" cf:file_name="{filename}"

And this for the records (presented in a table):

{exp:link_vault:records limit="5" order_by="census" group_by="file_name" sort="desc"}
                   
<tr class="{switch="even|odd"}">
                      <
td width="77%" valign="middle"><span class="title">{cf:file_name}</span></td>
                      <
td width="11%" valign="middle"><span class="docs">{census}</td>
                      <
td width="12%" valign="middle"><span class="link"><a href="{directory}{file_name}">Download</a></td>
                   </
tr>{/exp:link_vault:records} 

The custom field in Link Vault is called “file_name” it’s trying to grab from a Matrix field called ‘Download’ and the cell it’s trying to get is ‘filename’. ‘file’ is the cell that holds the upload itself.

1 of 2
1