Datamanager 2 download widget

As with all subclasses, the actual initialization is done in the initialize() function, not in the constructor, to allow for error handling.

This widget supports the blobs type or any subtype thereof.

All processing is done during the on_submit handlers, enforcing immediate update of the associated storage objects. No other solution is possible, since we need to transfer uploaded files somehow through multiple requests.

Note, that this widget (as opposed to the image & co widgets) uses the blobs base type directly and thus has no post-processing capabilities whatsoever.

The type will show a tabular view of all uploaded attachments. Existing attachments have an editable tile and can be deleted or replaced. A single new upload line is displayed always. There is no preview, but there is a download link.

Available configuration options:

  • none

Implementation notes:

The construction of the widget is relatively complex, it relies on a combination of static and input elements to do its work. It should be fairly customizable using CSS.

  1. Quickform Element Naming

All elements will be added in a group using the groupname[elementname] Feature of QF. Static elements are all prefixed s_, f.x. s_header. The actual elements use an e_, f.x. e_new_title. All elements in the new upload row append a new_ to this prefix as seen in the last example. Finally, elements referencing existing attachments append an exist_{$identifier}_ to the prefix, f.x. e_exist_{$identifier}_title.

  1. CSS names

The table gets the Name of the field as id and midcom_helper_datamanager2_widget_downloads as class. Each column also gets its own CSS class: filename, title, file, upload and delete. An additional class is assigned depending whether this is a row for an existing item (exist) or a new one (new). So a full class for the new filename element would be "new filename". Note, that the classes are assigned to both the td and input elements. The th elements do not have any additional class

  1. Attachment identifiers

Attachments are identified using an MD5 hash constructed from original upload time, uploaded file name and the temporary file name used during upload. Before adding the actual attachments, they are ordered by filename.

package midcom.helper.datamanager2

 Methods

_extension_to_mimetype ($extension, $mimetype)

Parameters

$extension

$mimetype

_on_initialize ()

The initialization event handler post-processes the maxlength setting.

Returns

booleanIndicating Success

add_elements_to_form ($attributes)

Constructs the upload list.

Parameters

$attributes

freeze ()

Freeze the entire group, special handling applies to skip all elements which cannot be frozen.

get_default ()

Populates the title fields with their defaults.

on_submit ($results)

The on_submit event handles all operations immediately.

This includes title updates (all are done regardless of actual updates).

Parameters

$results

sync_type_with_widget ($results)

Check if the sorted order should be returned to type

Parameters

$results

unfreeze ()

Unfreeze the entire group, special handling applies, the formgroup is replaced by a the full input widget set.

_add_attachment_row (string $identifier, array $info, boolean $frozen)

Adds a row for an existing attachment

Parameters

$identifier

stringRow identifier

$info

arrayRow data

$frozen

booleanSet this to true, if you want to skip all elements which cannot be frozen.

_add_new_upload_row (boolean $frozen)

Adds the new upload row to the bottom of the table.

Parameters

$frozen

booleanSet this to true, if you want to skip all elements which cannot be frozen.

_add_table_header (boolean $frozen)

Adds the table header to the widget.

Parameters

$frozen

booleanSet this to true, if you want to skip all elements which cannot be frozen.

_check_for_update (string $identifier, array $values)

The following checks are made, in order:
  1. If the delete button was clicked, the attachment is dropped.
  2. If a new file has been uploaded, it replaces the current one.
  3. If neither of the above is triggered, the title of the attachment is synchronized.

Calls for attachments which are not listed in the form, will be silently ignored. This may happen, for example, if two users edit the same object simultaneoulsy, or during addition of new elements.

Parameters

$identifier

stringThe attachment identifier to check for updates.

$values

arrayThe values associated with our element group (not the full submit value list).

_check_new_upload (array $values)

Checks whether a new file has been uploaded.

If yes, it is processed.

Parameters

$values

arrayThe values associated with our element group (not the full submit value list).

_compute_elements (boolean $frozen)

Computes the element list to form the widget.

It populates the _elements member, which is initialized with a new, empty array during startup.

Parameters

$frozen

booleanSet this to true, if you want to skip all elements which cannot be frozen.

 Properties

 

integer $max_count

Maximum amount of blobs allowed to be stored in the same field
 

string $progress_id

ID for upload-progress
 

bool $show_progressbar

indicates if progressbar is shown
 

Array $_elements

The list of elements added to the widget, indexed by their element name.
 

\HTML_QuickForm_Group $_group

The group of elements forming our widget.
 

integer $_sort_index

Sort index or what is the position in the list