Example #1
0
 /**
  * Prepare the input.
  *
  * @param array $arguments Contains the passed arguments
  *                         [0]  string    $name   Field's name, to be used by the form as a key.
  *                         [1]  string[]  $opts   Contains the option="value" key-value pairs to be added to the field
  *                         [2]  string    $default  Contains the field's default value
  */
 public function prepare($arguments)
 {
     $name = $arguments[0];
     $opts = $arguments[1];
     $default = $arguments[2];
     $start = Arr::get($opts, 'start', 1);
     $end = Arr::get($opts, 'end', 10);
     $step = Arr::get($opts, 'step', 1);
     $inverted = Arr::get($opts, 'inverted', false);
     Arr::remove('start', $opts);
     Arr::remove('end', $opts);
     Arr::remove('step', $opts);
     Arr::remove('inverted', $opts);
     $opts['value'] = 0;
     $opts['key'] = 0;
     $values = [];
     if ($inverted) {
         for ($i = $end; $i >= $start; $i -= $step) {
             $values[] = [$i];
         }
     } else {
         for ($i = $start; $i <= $end; $i += $step) {
             $values[] = [$i];
         }
     }
     $select = new Select();
     return $select->prepare([$name, $values, $opts, [$default], '']);
 }
Example #2
0
 /**
  * Prepare the input.
  *
  * @param array $arguments Contains the passed arguments
  *                         [0]  string    $name     Radio's name. Can be not unique, but will bind it to a group if not.
  *                         [1]  string[]  $opts     Contains the option="value" key-value pairs to be added to the field
  *                         [2]  boolean   $yes      If the yes Radio is checked as default
  */
 public function prepare($arguments)
 {
     $name = $arguments[0];
     $opts = $arguments[1];
     $yes = $arguments[2];
     $yesLang = Arr::get($opts, 'yes', 'Yes');
     $noLang = Arr::get($opts, 'no', 'No');
     Arr::remove('yes', $opts);
     Arr::remove('no', $opts);
     $html = '<div class="radio"><label>' . $yesLang;
     $radio = new Radio();
     $html .= $radio->prepare([$name, '1', $opts, $yes]);
     $html .= '</label></div>';
     $html .= '<div class="radio"><label>' . $noLang;
     $radio = new Radio();
     $html .= $radio->prepare([$name, '0', $opts, !$yes]);
     $html .= '</label></div>';
     return $html;
 }
Example #3
0
 /**
  * Prepare the input.
  *
  * @param array $arguments Contains the passed arguments
  *                         [0]  string    $name   Field's name, to be used by the form as a key.
  *                         [1]  string[]  $opts   Contains the option="value" key-value pairs to be added to the field
  *                         [2]  string    $value  Contains the field's default value.
  *                         [3]  string    $legend Text to put in the legend
  */
 public function prepare($arguments)
 {
     $name = $arguments[0];
     $opts = $arguments[1];
     $value = $arguments[2];
     $legend = $arguments[3];
     $positionRight = Arr::get($opts, 'position', 'left') == 'right';
     Arr::remove('position', $opts);
     $html = '<div class="input-group">';
     if (!$positionRight) {
         $html .= '<span class="input-group-addon">' . $legend . '</span>';
     }
     $html .= '<input type="text" name="' . $name . '" value="' . $value . '"';
     $html .= $this->getOpts($opts);
     $html .= '/>';
     if ($positionRight) {
         $html .= '<span class="input-group-addon">' . $legend . '</span>';
     }
     $html .= '</div>';
     return $html;
 }
Example #4
0
 /**
  * Prepare the input.
  *
  * @param array $arguments Contains the passed arguments
  *                         [0]  string    $name      Checkbox group's name.
  *                         [1]  Array[]   $elements  Array of checkbox elements. These must be PHP Arrays which all contain the ["id"] and ["name"] attributes (unless either "key" or "value" are redefined in the opts)
  *                         [2]  string[]  $opts      Contains the option="value" key-value pairs to be added to the field
  *                         [3]  Array[]   $values    Contains the elements that need to be checked (an is in array comparison is made)
  */
 public function prepare($arguments)
 {
     $name = $arguments[0];
     $elements = $arguments[1];
     $opts = $arguments[2];
     $values = $arguments[3];
     $values = (array) $values;
     $hKey = Arr::get($opts, 'key', 'id');
     $hValue = Arr::get($opts, 'value', 'name');
     Arr::remove('key', $opts);
     Arr::remove('value', $opts);
     $html = '';
     foreach ($elements as $element) {
         $html .= '<div class="checkbox">';
         $html .= '<label>';
         $html .= $element[$hValue];
         $checkbox = new Checkbox();
         $html .= $checkbox->prepare([$name, $element[$hKey], $opts, in_array($element[$hKey], $values)]);
         $html .= '</div>';
         $html .= '</label>';
     }
     return $html;
 }
Example #5
0
 /**
  * Prepare the input.
  *
  * @param array $arguments Contains the passed arguments
  *                         [0]  string    $name         Checkbox group's name.
  *                         [1]  Array[]   $elements     Array of checkbox elements. These must be PHP Arrays which all contain the ["id"] and ["name"] attributes (unless either "key" or "value" are redefined in the opts)
  *                         [2]  string[]  $opts         Contains the option="value" key-value pairs to be added to the field
  *                         [3]  integer   $values       Contains the default selected element
  *                         [4]  string    $placeholder  Contains a string representing the Placeholder value at the top of the select. '' if none
  */
 public function prepare($arguments)
 {
     $name = $arguments[0];
     $elements = $arguments[1];
     $opts = $arguments[2];
     $values = $arguments[3];
     $placeholder = $arguments[4];
     $values = (array) $values;
     $hKey = Arr::get($opts, 'key', 'id');
     $hValue = Arr::get($opts, 'value', 'name');
     Arr::remove('key', $opts);
     Arr::remove('value', $opts);
     $html = '<select name="' . $name . '" ' . $this->getOpts($opts) . '>';
     if ($placeholder != '') {
         $option = new Option();
         $html .= $option->prepare([$placeholder, '', ['class' => 'form-option'], false]);
     }
     foreach ($elements as $element) {
         $option = new Option();
         $html .= $option->prepare([$element[$hValue], $element[$hKey], ['class' => 'form-option'], in_array($element[$hKey], $values)]);
     }
     $html .= '</select>';
     return $html;
 }
Example #6
0
 public function testShuffle()
 {
     $expected = [['id' => 4], ['id' => 1], ['id' => 3], ['id' => 2], ['id' => 5]];
     Arr::seedShuffle($this->dummies3, 123);
     $this->assertEquals($expected, $this->dummies3);
 }