コード例 #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;
 }
コード例 #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];
 }