Commit 2f4a9bd3742071224edf60806cd2fb757f5c8a85
1 parent
ad015526
- files should be validated when required
- if there's no metadata, don't bother asking for it. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5828 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
4 changed files
with
51 additions
and
4 deletions
plugins/ktcore/KTCorePlugin.php
| ... | ... | @@ -141,6 +141,7 @@ class KTCorePlugin extends KTPlugin { |
| 141 | 141 | $this->registerValidator('KTMembershipValidator', 'ktcore.validators.membership', 'KTValidators.php'); |
| 142 | 142 | $this->registerValidator('KTFieldsetValidator', 'ktcore.validators.fieldset', 'KTValidators.php'); |
| 143 | 143 | $this->registerValidator('KTFileValidator', 'ktcore.validators.file', 'KTValidators.php'); |
| 144 | + $this->registerValidator('KTRequiredFileValidator', 'ktcore.validators.requiredfile', 'KTValidators.php'); | |
| 144 | 145 | |
| 145 | 146 | // criterion |
| 146 | 147 | $this->registerCriterion('NameCriterion', 'ktcore.criteria.name', KT_LIB_DIR . '/browse/Criteria.inc'); | ... | ... |
plugins/ktcore/KTValidators.php
| ... | ... | @@ -147,6 +147,26 @@ class KTRequiredValidator extends KTValidator { |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | +// the required validator checks either single or multiple items | |
| 151 | +// in the data array. | |
| 152 | +class KTRequiredFileValidator extends KTValidator { | |
| 153 | + var $sNamespace = 'ktcore.validators.requiredfile'; | |
| 154 | + | |
| 155 | + function validate($data) { | |
| 156 | + $errors = array(); | |
| 157 | + | |
| 158 | + $val = KTUtil::arrayGet($_FILES, $this->sInputVariable); | |
| 159 | + if (empty($val) || empty($val['name'])) { | |
| 160 | + $errors[$this->sBasename] = _kt("You must select a file to upload."); | |
| 161 | + } | |
| 162 | + | |
| 163 | + return array( | |
| 164 | + 'errors' => $errors, | |
| 165 | + 'results' => array(), | |
| 166 | + ); | |
| 167 | + } | |
| 168 | +} | |
| 169 | + | |
| 150 | 170 | class KTEmailValidator extends KTValidator { |
| 151 | 171 | var $sNamespace = 'ktcore.validators.emailaddress'; |
| 152 | 172 | ... | ... |
plugins/ktcore/KTWidgets.php
| ... | ... | @@ -22,6 +22,18 @@ class KTCoreFileWidget extends KTWidget { |
| 22 | 22 | $tname = sprintf("_kt_attempt_unique_%s", $this->sName); |
| 23 | 23 | return array($this->sBasename => $_FILES[$tname]); |
| 24 | 24 | } |
| 25 | + | |
| 26 | + function getValidators() { | |
| 27 | + if (!$this->bAutoValidate) { | |
| 28 | + return null; | |
| 29 | + } | |
| 30 | + | |
| 31 | + $oVF =& KTValidatorFactory::getSingleton(); | |
| 32 | + return $oVF->get('ktcore.validators.requiredfile', array( | |
| 33 | + 'test' => sprintf("_kt_attempt_unique_%s", $this->sName), | |
| 34 | + 'basename' => $this->sBasename, | |
| 35 | + )); | |
| 36 | + } | |
| 25 | 37 | } |
| 26 | 38 | |
| 27 | 39 | ... | ... |
plugins/ktcore/folder/addDocument.php
| ... | ... | @@ -105,6 +105,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { |
| 105 | 105 | 'initial_string' => _kt('- Please select a document type -'), |
| 106 | 106 | 'id_method' => 'getId', |
| 107 | 107 | 'label_method' => 'getName', |
| 108 | + 'simple_select' => false, | |
| 108 | 109 | )), |
| 109 | 110 | )); |
| 110 | 111 | |
| ... | ... | @@ -127,6 +128,15 @@ class KTFolderAddDocumentAction extends KTFolderAction { |
| 127 | 128 | |
| 128 | 129 | return $oForm; |
| 129 | 130 | } |
| 131 | + | |
| 132 | + function getFieldsetsForType($iTypeId) { | |
| 133 | + $typeid = KTUtil::getId($iTypeId); | |
| 134 | + $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); | |
| 135 | + $aSpecificFieldsetIds = KTFieldset::getForDocumentType($typeid, array('ids' => false)); | |
| 136 | + | |
| 137 | + $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds); | |
| 138 | + return $fieldsets; | |
| 139 | + } | |
| 130 | 140 | |
| 131 | 141 | function do_main() { |
| 132 | 142 | $this->oPage->setBreadcrumbDetails(_kt("Add a document")); |
| ... | ... | @@ -147,6 +157,13 @@ class KTFolderAddDocumentAction extends KTFolderAction { |
| 147 | 157 | $data = $res['results']; |
| 148 | 158 | $key = KTUtil::randomString(32); |
| 149 | 159 | $_SESSION['_add_data'] = array($key => $data); |
| 160 | + | |
| 161 | + // if we don't need metadata | |
| 162 | + $fieldsets = $this->getFieldsetsForType($data['document_type']); | |
| 163 | + if (empty($fieldsets)) { | |
| 164 | + return $this->successRedirectTo('finalise', _kt("File uploaded successfully. Processing."), sprintf("fFileKey=%s", $key)); | |
| 165 | + } | |
| 166 | + | |
| 150 | 167 | // if we need metadata |
| 151 | 168 | |
| 152 | 169 | $this->successRedirectTo('metadata', _kt("File uploaded successfully. Please fill in the metadata below."), sprintf("fFileKey=%s", $key)); |
| ... | ... | @@ -171,10 +188,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { |
| 171 | 188 | |
| 172 | 189 | $widgets = array(); |
| 173 | 190 | $validators = array(); |
| 174 | - $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); | |
| 175 | - $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false)); | |
| 176 | - | |
| 177 | - $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds); | |
| 191 | + $fieldsets = $this->getFieldsetsForType($doctypeid); | |
| 178 | 192 | |
| 179 | 193 | foreach ($fieldsets as $oFieldset) { |
| 180 | 194 | $widgets = kt_array_merge($widgets, $oFReg->widgetsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument)); | ... | ... |