Esempio n. 1
0
 /**
  * Check completion status
  *
  * @return  object
  */
 public function getStatus($manifest, $pub = NULL)
 {
     $status = new \Components\Publications\Models\Status();
     // Get requirements to check against
     $field = $manifest->params->field;
     $required = $manifest->params->required;
     $key = $manifest->params->aliasmap;
     $default = isset($manifest->params->default) ? $manifest->params->default : NULL;
     $value = isset($pub->{$key}) ? $pub->{$key} : NULL;
     $incomplete = 0;
     // Parse data in metadata field
     $data = array();
     preg_match_all("#<nb:(.*?)>(.*?)</nb:(.*?)>#s", $pub->metadata, $matches, PREG_SET_ORDER);
     if (count($matches) > 0) {
         foreach ($matches as $match) {
             $data[$match[1]] = \Components\Publications\Helpers\Html::_txtUnpee($match[2]);
         }
     }
     // Metadata field (special treatment)
     if ($field == 'metadata') {
         $value = isset($data[$key]) ? $data[$key] : NULL;
     }
     // Default value not replaced?
     if ($default && $value) {
         if ($default == $value || preg_match('/' . $default . ' (\\(.*\\))/', $value, $matches)) {
             $status->setError(Lang::txt('Default value needs to be replaced'));
         }
     }
     // Required value not filled?
     if ($required && !$value) {
         $status->setError(Lang::txt('Missing ' . $key));
     } elseif (!$required && !$value) {
         $incomplete = 1;
     }
     $status->status = $status->getError() ? 0 : 1;
     $status->status = $incomplete ? 2 : $status->status;
     return $status;
 }
Esempio n. 2
0
 /**
  * Check completion status
  *
  * @return  object
  */
 public function getStatus($element, $attachments)
 {
     $status = new \Components\Publications\Models\Status();
     // Get requirements to check against
     $max = $element->max;
     $min = $element->min;
     $role = $element->role;
     $params = $element->typeParams;
     $required = $element->required;
     $counter = count($attachments);
     if (!$required) {
         $status->status = $counter ? 1 : 2;
         return $status;
     }
     // Check for correct number of attachments
     if ($min > 0 && $counter < $min) {
         if ($counter) {
             $status->setError(Lang::txt('Need at least ' . $min . ' attachment'));
         } else {
             // No Attachments
             $status->status = 0;
             return $status;
         }
     } elseif ($max > 0 && $counter > $max) {
         $status->setError(Lang::txt('Maximum ' . $max . ' attachment(s) allowed'));
     }
     $status->status = $status->getError() ? 0 : 1;
     return $status;
 }
Esempio n. 3
0
 /**
  * Check completion status
  *
  * @return  object
  */
 public function getStatus($element, $attachments)
 {
     $status = new \Components\Publications\Models\Status();
     // Get requirements to check against
     $max = $element->max;
     $min = $element->min;
     $role = $element->role;
     $params = $element->typeParams;
     $required = $element->required;
     $counter = count($attachments);
     // Check for correct number of files
     if ($min > 0 && $counter < $min) {
         if ($counter) {
             $status->setError(Lang::txt('Need at least ' . $min . ' file(s)'));
         } else {
             // No files
             $status->status = 0;
             if ($required) {
                 return $status;
             }
         }
     } elseif ($max > 0 && $counter > $max) {
         $status->setError(Lang::txt('Maximum ' . $max . ' files allowed'));
     } elseif (!self::checkAllowed($attachments, $params->allowed_ext)) {
         if ($counter && !empty($params->allowed_ext)) {
             $error = Lang::txt('Error: wrong file type. Allowed file type(s): ');
             foreach ($params->allowed_ext as $ext) {
                 $error .= ' ' . $ext . ',';
             }
             $error = substr($error, 0, strlen($error) - 1);
             $status->setError($error);
         } else {
             $status->setError(Lang::txt('File format not allowed'));
         }
     } elseif (!self::checkRequired($attachments, $params->required_ext)) {
         $status->setError(Lang::txt('Missing a file of required format'));
     }
     if (!$required) {
         $status->status = $counter ? 1 : 2;
         return $status;
     }
     $status->status = $status->getError() ? 0 : 1;
     return $status;
 }
Esempio n. 4
0
 /**
  * Check completion status
  *
  * @param   object  $element
  * @param   array   $attachments
  * @return  object
  */
 public function getStatus($element, $attachments)
 {
     $status = new \Components\Publications\Models\Status();
     // Get requirements to check against
     $max = $element->max;
     $min = $element->min;
     $role = $element->role;
     $params = $element->typeParams;
     $required = $element->required;
     $counter = count($attachments);
     $allowed = isset($params->accept) ? $params->accept : NULL;
     if (!$required) {
         $status->status = $counter ? 1 : 2;
         return $status;
     }
     // Check for correct number of attachments
     if ($min > 0 && $counter < $min) {
         if ($counter) {
             $status->setError(Lang::txt('Need at least ' . $min . ' attachment'));
         } else {
             // No files
             $status->status = 0;
             return $status;
         }
     } elseif ($max > 0 && $counter > $max) {
         $status->setError(Lang::txt('Maximum ' . $max . ' attachment(s) allowed'));
     } elseif (!self::checkAllowed($attachments, $allowed)) {
         if ($counter && !empty($accept)) {
             $error = Lang::txt('Error: unacceptable URL. URL should start with: ');
             foreach ($params->allowed_ext as $ext) {
                 $error .= ' ' . $ext . ',';
             }
             $error = substr($error, 0, strlen($error) - 1);
             $status->setError($error);
         }
     }
     $status->status = $status->getError() ? 0 : 1;
     return $status;
 }