Hi,
We have a business website I'm trying to migrate to Drupal 7 We have a custom download system that was implemented as a custom page in native PHP - wich is terrible and I want to convert it to a Drupal module.
I've searched, but haven't fount any modules that would satisfy all of my needs. That's why I want to build a custom module (either from scratch or modifying a contrib module). I just need some starting points.
What I need:
- I upload all files via FTP, I don't want to use Drupal for that as there are large files and they are problematic to upload via HTTP
- I want to create document entities, each with multiple files for each language (i.e. "Terms and conditions" in several languages - one file for each language but only one document entity)
- I need to have lists (views?) of those document entities and I need to change the order manualy (like the order of Drupal menu items)
For example: I have 3 documents: "Terms and conditions", "Registration form" and "Company Presentation" - all three have English, German and Spanish translations. In the admin section I create the three document entities and select the different language files (from the files uploaded via FTP) for each document. Then I create two lists - one has all three documents in all languages, the other only has "Company Presentation" and without the English version. I create a node for each list.
When the visitor opens the node for list 1, they will see all three documents and can select (for each document) wich language version they'd like to download - 3 entries, each with selectable language. When they visit list 2 they only see "Company Presentation" and only with Spanish and German available.
The goal is to have a system of files where if I update a file, every list that contains that file is also updated and if I add or delete a file it is also reflected in all lists that contains that particular document I have added/deleted the file from. This way I only need to add a file once.
It's pretty complex but we have 13 languages (and growing) and it would be impossible to maintain all files separately.
Unfortunately I'm not a guru when it comes to Drupal modules. I have two ideas, but both have a fault at some point.
One idea is to create a custom content type for documents that can have multiple items for the files and then my module would handle storing and displaying. But this way, each document would have it's own node and I don't know how could I manage the list of them (i need to make custom lists, placing them individually)
My other idea is to create a vocabulary for the documents and each term would have custom fields for the files. But then how can I add a term to multiple lists?
I want to make it compatible with Drupal's standards and I'm lacking in such experience.
Can you please recommend any module I can use as a base or some directions on how to store or handle this type of datas? Like - do I pull and insert data directly from my module or should I use another Drupal module for this? I just need to get started, I can probably figure things out.
Thanks in advance.
Comments
Sadly, i don't know any
Sadly, i don't know any modules to tell you for your problem. But i did some kind of similar thing recently. I had allot of files and wanted to get them into Drupal. I don't really know all conditions of your projects.
Your first idea is definitely better then the second one.
So, here is how i would do it:
I would create a Taxonomy for the files to keep them together. One term per file in that Taxonomy. But same term for same files in different language.
I would suggest some pattern for the files like: NAME_TERM_LANG.EXT. That way you could simply parse for whats displayed later on. Then i would create a content type for the documents. You could call it "documents" since its for documents and documents are a type of content. The content type could be really simple. Just Title, File, the term and a maybe term for the language if you don't wan't to use the i18n system of drupal.
Then i would write a custom module to read the ftp folder and automatically copy the files over into the drupal file system. You could even create custom folder structure that way to keep your file folder clean. Its pretty easy. If the files are copied, you let the module create a node for each document.
I don't know what you want to do with this list and how many files you have. But instead of creating a node with a list by hand (would need to be updated by hand), you could create a term based view (with views module) with a contextual filter. This way you would could create an url like domain.com/docs/TERM and list all the documents for that term. You could also create a second view to list by language if you have the language terms. Don't know if thats needed.
Good thing is, you could create a view with a list of your terms from the main taxonomy and list all files (based on the terms) you have.
Since you're a starter, this must sound pretty heavy. I would suggest to take a look into the Views module. It definitely perfect for your problem. I use this module in almost every install. At least i don't know of a project where its been missing.
If you're eager to learn to write modules this should be a good start.
Let me paste you some example code for the module:
function file_reader_menu() {
$items['structure/file_reader'] = array(
'title' => 'File reader',
'description' => 'Read files from FTP',
'page callback' => 'drupal_get_form',
'page arguments' => array('file_reader_callback'),
'access arguments' => array('administer site settings'),
);
}
function file_reader_callback() {
$path = 'YOUR FTP PATH';
$dir = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
foreach ($dir as $file) {
// save file to drupal db
$new_file = file_get_contents($file);
$new_file = file_save_data($new_file, $file, FILE_EXISTS_REPLACE);
$tid = 'VOCABULARY ID';
$term_id = add_taxonomy_term($tid, 'TAXONOMY TERM');
// create a node for file
$node = new StdClass();
$node->type = 'document';
$node->title = 'YOUR FILE TITLE';
$node->field_term[LANGUAGE_NONE][]['tid'] = $term_id;
$node->language = 'und';
$node->uid = 1;
$node->status = 1;
$node->field_file = array(
'und' => array(
0 => array(
'fid' => $new_file->fid,
'filename' => $new_file->filename,
'filemime' => $new_file->filemime,
'uid' => 1,
'uri' => $new_file->uri,
'status' => 1,
'display' => 1
)
)
);
node_save($node);
}
}
function add_taxonomy_term($vid, $name) {
$term = new stdClass();
$term->name = $name;
$term->vid = $vid;
taxonomy_term_save($term);
return $term->tid;
}
I haven't tested the code. I doubt its working out of the box but it should give you an idea how it works. Title parsing is missing as well.
Thank you very much! You gave
Thank you very much! You gave me a great idea to start with. I now see more clearly how could I solve this.
I'll definitely try your code too.