Ejemplo n.º 1
0
 /**
  * @return an array of the values to be used in the target field of the target form
  */
 function getValues(&$data)
 {
     $from = SPSUtils::fromArray($data, 'from', 1);
     $to = SPSUtils::fromArray($data, 'to', $from);
     $step = SPSUtils::fromArray($data, 'step', 1);
     $digits = SPSUtils::fromArray($data, 'digits', 1);
     $errors = '';
     if (!is_numeric($from)) {
         $errors .= SPSUtils::buildMessage('spserror-count-startvaluemalformed') . "\n";
     }
     if (!is_numeric($to)) {
         $errors .= SPSUtils::buildMessage('spserror-count-endvaluemalformed') . "\n";
     }
     if (!is_numeric($step)) {
         $errors .= SPSUtils::buildMessage('spserror-count-stepvaluemalformed') . "\n";
     }
     if (!is_numeric($digits)) {
         $errors .= SPSUtils::buildMessage('spserror-count-digitsvaluemalformed') . "\n";
     }
     if ($errors !== '') {
         throw new SPSException($errors);
     }
     $values = array();
     for ($index = $from; $index <= $to; $index += $step) {
         $values[] = sprintf('%0' . $digits . 'd', $index);
     }
     return $values;
 }
Ejemplo n.º 2
0
 /**
  * @return an array of the values to be used in the target field of the target form
  */
 function getValues(&$data)
 {
     $start = SPSUtils::fromArray($data, 'start');
     $end = SPSUtils::fromArray($data, 'end', $start);
     $period = SPSUtils::fromArray($data, 'period', 1);
     $unit = SPSUtils::fromArray($data, 'unit', 'day');
     if ($start === null || $start === '') {
         throw new SPSException(SPSUtils::buildMessage('spserror-date-startdatemissing'));
     }
     //prepare params for getDatesForRecurringEvent
     $params = array('property=SomeDummyProperty', 'start=' . $start, 'end=' . $end, 'period=' . $period, 'unit=' . $unit);
     $values = SMWSetRecurringEvent::getDatesForRecurringEvent($params);
     if ($values === null) {
         throw new SPSException(SPSUtils::buildMessage('spserror-date-internalerror'));
     }
     // if the first date did not contain a time, remove the time from all
     // generated dates
     if (preg_match('/.:../', $values[1][0]) === 0) {
         foreach ($values[1] as $key => $value) {
             $values[1][$key] = trim(preg_replace('/..:..:../', '', $value));
         }
     }
     return $values[1];
 }
Ejemplo n.º 3
0
 /**
  * Builds a JSON blob of the data required to use the iterator.
  * @param WebRequest $request
  * @return type 
  */
 private function buildIteratorParameters(WebRequest &$request)
 {
     global $spsgIterators;
     // iteratorName
     $iteratorName = $request->getVal('iterator');
     if (is_null($iteratorName)) {
         throw new SPSException(SPSUtils::buildMessage('spserror-noiteratorname'));
     }
     if (!array_key_exists($iteratorName, $spsgIterators)) {
         throw new SPSException(SPSUtils::buildMessage('spserror-iteratorunknown', $iteratorName));
     }
     // iterator
     $iterator = new $spsgIterators[$iteratorName]();
     // targetFormName
     $targetFormName = $request->getVal('target_form');
     if (is_null($targetFormName)) {
         throw new SPSException(SPSUtils::buildMessage('spserror-notargetformname'));
     }
     // targetFormTitle is not really needed at this stage,
     // but we throw an error early if it does not exist
     $targetFormTitle = Title::makeTitleSafe(SF_NS_FORM, $targetFormName);
     if (!$targetFormTitle->exists()) {
         throw new SPSException(SPSUtils::buildMessage('spserror-formunknown', $targetFormName));
     }
     // targetFieldName
     $targetFieldName = $request->getVal('target_field');
     if (is_null($targetFieldName)) {
         throw new SPSException(SPSUtils::buildMessage('spserror-notargetfieldname'));
     }
     $params = array('iterator' => $iteratorName, 'target_form' => $targetFormName, 'target_field' => $targetFieldName, 'origin' => $request->getVal('origin'));
     // add the iterator-specific values
     $paramNames = $iterator->getParameterNames();
     $errors = '';
     foreach ($paramNames as $paramName => $paramOptional) {
         $param = $request->getVal($paramName);
         if (is_null($param)) {
             if ($paramOptional === SPS_MANDATORY) {
                 // mandatory parameter missing
                 $errors .= "* {$paramName}\n";
             }
         } else {
             $params[$paramName] = $param;
         }
     }
     if ($errors !== '') {
         throw new SPSException(SPSUtils::buildMessage('spserror-iteratorparammissing', $errors));
     }
     return FormatJson::encode($params);
 }