📜 ⬆️ ⬇️

Making a repository for Evo on Ditto

Hello! Today I would like to talk about a painful problem - the organization of repositories (they are the same: file storages, file galleries, file archives).

I have already talked about the FileDownload snippet, which is quite acceptable for some tasks, but also for people who understand. As practice has shown, even the plugin that I did under FileDownload does not save people who are not dedicated and they have serious difficulties.

Well, on reflection, I thought that the easiest way to organize a file archive in the way almost everything is implemented on MODx is through the resource tree.

For this, it was decided to use Ditto.
So, the version of MODx Evo 1.0.4, Ditto standard, from the distribution kit.


To enable simple staff to easily and easily add files, write descriptions to them, make folders.


In that, to use Ditto is about the same as, for example, with the output of news, only instead of pages - files.


In general, I think, you need to skip thinking and dead-end attempts and go directly to the final version.

File archive structure:

--Start archive page
| --- Folder 1
| | ------ File 1
| | ------ File 2
| --- File 1
| --- File 2
| --- File 3

Those. like that:

So, in order to distinguish documents-files from documents-folders, it was decided to make two additional templates: one for files, the other for folders.

The file template is empty (do not be surprised, you will later understand what it is for)
Template for a folder - contains a call to Ditto.

In the start page, File Archive , add the Ditto call:
 <h2> :</h2> [!Ditto? &id=`archiv` &parents=`[*id*]` &noResults=` ` &filter=`template,15,8` &tpl=`repository` &sortBy=`createdon` &summarize=`30` &dateFormat=`%d.%m.%Y` &paginate=1 !] [!Ditto? &id=`archiv` &parents=`[*id*]` &filter=`template,16,8` &tpl=`repository` &sortBy=`createdon` &summarize=`30` &dateFormat=`%d.%m.%Y` &paginate=1 !] </div> <div id="pagination"> [+archiv_previous+] - .: [+archiv_pages+] - [+archiv_next+] </div> 

1. Why two calls?
There are two calls here because with the help of one call it’s impossible to sort the folders and files separately (and we want the folders to always be first in the list).
2. Why & id = `archiv`?
This is done just in case, because there may be other Diito calls on the page, for example, News.
3. Why & noResults = ``?
And this is to ensure that instead of the message “Records are not found.” Nothing is displayed. Why in one call? We just don’t want this page to be missing on this page if there are no folders in the subdirectory, but if there are no files, this is quite appropriate.
4. & filter = `template, 15.8` and & filter =` template, 16.8`
Here we display only what we need: in the first file, we output only those documents that are with the id = 15 template (Folder template), in the second one only with the id = 16 template (File template).

Everything else, I think, is understandable.

Now those templates : as I said, the template files can be completely empty, but the folder template should contain a call to Ditto:
 <h2> :</h2> <div class="fd-example4"> <img src="assets/images/filetype/arrow_up.png"><a href="javascript:history.back()"></a><hr> [!Ditto? &id=`archiv` &parents=`[*id*]` &noResults=` ` &filter=`template,15,8` &tpl=`repository` &sortBy=`createdon` &summarize=`30` &dateFormat=`%d.%m.%Y` &paginate=1 !] [!Ditto? &id=`archiv` &parents=`[*id*]` &filter=`template,16,8` &tpl=`repository` &sortBy=`createdon` &summarize=`30` &dateFormat=`%d.%m.%Y` &paginate=1 !] </div> <div id="pagination"> [+archiv_previous+] - .: [+archiv_pages+] - [+archiv_next+] </div> 

As you can see, the only difference is that we added the Back link. And another thing: the Folder template needs to make a TV parameter, I called it tvfile , and the input type was File .

Next, what we have contains the chunk & tpl = `repository`:
 [[repome? &docId=`[+id+]` ]] 

Those. in the chunk, we only have a call to a simple handwritten snippet repome .
What the snippet does:
1. Associates various file extensions with their icons.
2. The file size is calculated, the file name is highlighted.
3. Pattern recognition and output generation

Snippet RepoMe
I will explain the main parameters:
 $idTemplateFolder - ID    $folderTitle -         $folderDescription -       $idTemplateFile - ID    $fileTitle -         $fileDescription -       $fileFile -        $fileDate -         $imgset -      $imgPath -    

I will not give the snippet code itself, I tried to comment on it as much as possible and put it in the archive at the end of the article.

And, finally, by styles: those who use FileDowload, probably noticed that I used his example styles here - it was too lazy to redo it (I attached them in the archive).

What should happen:

And if you enter the Vortex Generators folder:

Oh, and I almost forgot: you can use the ManagerManager. By removing the extra fields (remember, this is done by adding the mm_hideFields instruction ('field_list_of_section_frame', 'user_id_roli', 'template_id') into the mm_rules chunk if you keep the rules there or in the same file in the managermanager directory).

Then, for the manager, the administrative part will look like this:


+ Colossal ease of use, you can once explain the principle of adding news - and then use it when explaining how to work with a file archive
+ Implemented on Ditto, which means, theoretically, you can fasten all sorts of ditto gadgets, such as rating
+ Implemented in the form of documents - which means you can, having a fantasy, make a bunch of bells and whistles
+ Independence of file and folder names from their names
+ Independence from the physical location of files
+ Icon support
+ Basically, versatility
+ Simple code: the ability to finish as you like

- Inconvenient output setting (no templates and placeholders for them)
- For maximum adaptation for your resource, you may have to finish a lot
- Still, far from a professional tool

What you need to pay attention to:
Do not forget about
 <base href='[(site_url)]'> 

Do not forget to allow managers to use FCKeditor and download various types of files.

Archive with snippet and everything you need

That's all. Perhaps, if this version is in progress, we will improve it by adding templates and other usefulness.

Source: https://habr.com/ru/post/106185/

All Articles