filtering pdf file attachments

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
justluvgod's picture

I have a Drupal 7 question that I can't seem to find a clear solution. I have a lot of pdf files that I want to add to our website. I want to be able to query/filter the pdf files based on year and department. I would want something like a drop down menu or radio buttons to accomplish this so the user can select to sort by year and/or department. I can't figure out how to add any taxonomy or association to the file to do so.

Do you know if this can be done or not? If you know of any books or tutorials that will help me, I would greatly appreciate any assistance.

Comments

A good start would be to

snlnz's picture

A good start would be to study views thoroughly.

You can achieve this by exposing the sort criteria in views.

The basic steps are:
CCK / Custom Content Type
1) create a content type with file uploads of type pdf.
2) remove any unnecessary fields you probably won't need perhaps fields such as body as an example.
Views
1) Then create a new view perhaps as a page (sitename.com/pdf-page) in your case with fields content > "PDF file" for example.
sort criteria by date and expose the sort criteria so visitors are able to click the column headers to sort by the criteria you specify in views.

I'm no expert in this area by any means, but have had to do this many times on drupal 7 sites so thought I'd add my 5 cents worth.
I think this process is what makes Drupal so special from other CMS's and should be at the heart of your box of tricks when building sites.

Hope this is helpful.

CCK / Custom Content Type

cithukyaw's picture

--- CCK / Custom Content Type
Most fields from CCK have been moved to Druapl 7 core and File module is enabled by default.

--- 2) remove any unnecessary fields you probably won't need perhaps fields such as body as an example.
I think you need to write a custom module to hide/remove unnecessary fields from node form.
I would do something like

function mymodule_form_alter(&$form, &$form_states, $form_id){
      if($form_id == 'yourcontenttype_node_form'){
            $form['title']['#required'] = FALSE;
            $form['title']['#type'] = 'hidden';

            $form['body']['#required'] = FALSE;
            $form['body']['#type'] = 'hidden';
      }
}

It can be done by installing Formfilter module in Drupal 6, but there is no Drupal 7 update for that module.

With Regards,
Sithu

Followup - Work in progress

justluvgod's picture

Thank you both for the suggestion. I am still unable to perform a filter on the files. I can create a new page and upload the files in addition to providing a description name for each file; they all appear on the page just fine. The main problem is I can't do anything else with the list now. I want the end user to filter the list based on year (the years will be in dropdown or radio button).

Although I have created a year field in the content type, it has no effect on the list.

Have I overcomplicated this or will I have to create a custom module? If the latter is the case, is there a good tutorial to help me get started?

Thanks again for the help thus far.

BTW, I did incorporate the suggestion when I created my employee directory. The end user can perform different types of filters and sorts without any problems.

1) You need to create a

cithukyaw's picture

1) You need to create a content type "PDF" with three fields - field_file, field_year, field_department
2) Create a view and expose sort criteria for field_year and field_department as snlnz's suggestion.

With Regards,
Sithu