Example #1
0
 public function test_unshift()
 {
     $array = array('two' => 'bar');
     // The "one" key should be prepended to the array
     $expect = array('one' => 'foo') + $array;
     $this->assert_equal(Arr::unshift($array, 'one', 'foo'), $expect);
 }
Example #2
0
 public function input($name, $value, array $attr = NULL)
 {
     $model = Sprig::factory($this->model);
     $choices = $model->select_list($model->pk());
     if ($this->empty) {
         Arr::unshift($choices, '', '-- ' . __('None'));
     }
     return Form::select($name, $choices, $this->verbose($value), $attr);
 }
Example #3
0
 public function __construct(array $options = NULL)
 {
     parent::__construct($options);
     if ($this->empty or $this->prompt) {
         Arr::unshift($this->codes, '', $this->prompt);
     }
     if (!$this->choices) {
         $this->choices = $this->codes;
     }
 }
Example #4
0
 /**
  * Load the default column names
  *
  * @param   mixed  $id  Parameter for find or object to load [Optional]
  * @uses    Arr::unshift
  */
 public function __construct($id = NULL)
 {
     if (empty($this->_sorting)) {
         $this->_sorting = array($this->scope_column => 'ASC', $this->left_column => 'ASC');
     } else {
         $this->_sorting = Arr::unshift($this->_sorting, $this->left_column, 'ASC');
         $this->_sorting = Arr::unshift($this->_sorting, $this->scope_column, 'ASC');
     }
     parent::__construct($id);
 }
Example #5
0
 /**
  * Input for create item
  * @return string Form::input
  */
 public function input_create($value)
 {
     $id = $value->id;
     $field = isset($this->item['field']) ? $this->item['field'] : 'name';
     $values_model = $value->clear()->find_all()->as_array($field);
     $values = array();
     foreach ($values_model as $value) {
         $values[$value->id] = $value->{$field};
     }
     if (!$this->item['notnull']) {
         Arr::unshift($values, 0, '');
     }
     return Form::select($this->item['name'], $values, $id);
 }
Example #6
0
 /**
  * Create input for options
  * @param mixed $value
  * @return string html 
  */
 protected function input($value)
 {
     $options = array();
     // if values is exists use like key value pair (for int type item in db)
     if (isset($this->item['values']) and $this->item['values'] != null) {
         foreach ($this->item['values'] as $option) {
             $options[$option] = $option;
         }
     } else {
         $columns = $this->model->table_columns();
         $options_temp = $columns[$this->get_name()]['options'];
         foreach ($options_temp as $option) {
             $options[$option] = $option;
         }
     }
     if (!isset($this->item['notnull']) or !$this->item['notnull']) {
         Arr::unshift($options, '', '');
     }
     return Form::select($this->get_name(), $options, $value);
 }
Example #7
0
 /**
  * Radios select, bootstrap style
  * @param  string $name
  * @param  array  $options
  * @param  array  $attributes
  * @return string
  */
 public function radios($name, array $options = array(), array $attributes = array())
 {
     $attributes = $this->default_attributes($name, $attributes);
     if (!isset($options['choices'])) {
         throw new Kohana_Exception('Radios tag widget requires a \'choices\' option');
     }
     $choices = Jam_Form::list_choices($options['choices']);
     if ($blank = Arr::get($options, 'include_blank')) {
         Arr::unshift($choices, '', $blank === TRUE ? __(" -- Select -- ") : $blank);
     }
     $radios = array();
     foreach ($choices as $key => $title) {
         $radio = $this->radio($name, array('value' => $key), array('id' => $attributes['id'] . '_' . $key));
         $radios[] = new Builder_Html('label', array('class' => 'radio'), $radio . $title);
     }
     return '<div ' . HTML::attributes($attributes) . '>' . join("\n", $radios) . '</div>';
 }
Example #8
0
 /**
  * Tests Arr::unshift()
  *
  * @test
  * @dataProvider provider_unshift
  * @param array $array
  * @param string $key
  * @param mixed $value
  */
 public function test_unshift(array $array, $key, $value)
 {
     $original = $array;
     Arr::unshift($array, $key, $value);
     $this->assertNotSame($original, $array);
     $this->assertSame(count($original) + 1, count($array));
     $this->assertArrayHasKey($key, $array);
     $this->assertSame($value, reset($array));
     $this->assertSame(key($array), $key);
 }
Example #9
0
 /**
  * input for filter
  * @param string $value
  * @return string form::select 
  */
 public function input_filter($value)
 {
     if (!is_object($value)) {
         $object = ORM::factory($this->item['name']);
         $field_value = $value;
     } else {
         $object = $value;
         $field_value = 0;
     }
     $field = isset($this->item['field']) ? $this->item['field'] : 'name';
     $values_model = $object->find_all()->as_array($field);
     $values = array();
     foreach ($values_model as $value) {
         $values[$value->id] = $value->{$field};
     }
     if (!$this->item['notnull']) {
         Arr::unshift($values, 0, '');
     }
     return Form::select($this->item['name'], $values, $field_value);
 }
Example #10
0
if (!empty($errors['name'])) {
    echo '<span class="help-inline">' . $errors['name'] . '</span>';
}
?>
				</div>
			</div>
			<div class="clearfix<?php 
if (!empty($errors['cat'])) {
    echo ' error';
}
?>
">
				<label>Category: </label>
				<div class="input">
					<?php 
Arr::unshift($categories, '', 'Please select&hellip;');
echo Form::select('category_id', $categories);
?>
					<?php 
if (!empty($errors['cat'])) {
    echo '<span class="help-inline">' . $errors['cat'] . '</span>';
}
?>
				</div>
			</div>
			<div class="clearfix">
				<label>&pound;Guide: </label>
				<div class="input">
					<div class="input-prepend">
						<span class="add-on">&pound;</span>
						<input name="price" value="<?php 
Example #11
0
 /**
  * Return array for html <select> element
  *
  * Example:
  *
  *     $arr_options = ORM::factory('Model_Name')
  *         ->order_by('title');
  *         ->find_for_select('id', 'title', array('none', 'Select a value'));
  *
  *     echo Form::select('id', $arr_options);
  *
  * @param $key value      for option tag
  * @param $val body       for option tag
  * @param array $unshift add an empty value to the start of a select list
  *                        first element of $unshift - value for first option tag
  *                        second element of $unshift - body for first option tag
  * @return array
  */
 public function find_for_select($key, $val, array $unshift = [])
 {
     $array = $this->find_all()->as_array($key, $val);
     if (isset($unshift[0]) and isset($unshift[1])) {
         Arr::unshift($array, $unshift[0], $unshift[1]);
     }
     return $array;
 }
Example #12
0
 /**
  * Create marker object using geocoding
  *
  * @todo   Add $options processing
  * @param  array $info
  * @param  array $options
  * @return void
  */
 private function add_geo_marker($info, $options)
 {
     $id = Arr::get($info, 'id', substr(md5(rand(0, 1000)), 0, 4));
     $info = Arr::unshift($info, 'id', $id);
     $this->geo_markers[] = $info;
 }
Example #13
0
 /**
  * HTML input select field
  * available options
  * 	- choices - this can be Jam_Query_Builder_Collection or a simple array
  * 	- include_blank - bool|string - include an empty option
  *
  * @param string $name       the name of the Jam_Model attribute
  * @param array  $options    set the options of the select with 'choices' and 'include_blank'
  * @param array  $attributes HTML attributes for the field
  * @return string
  */
 public function select($name, array $options = array(), array $attributes = array())
 {
     $attributes = $this->default_attributes($name, $attributes);
     if (!isset($options['choices'])) {
         throw new Kohana_Exception("Select tag widget requires a 'choices' option");
     }
     $choices = Jam_Form::list_choices($options['choices']);
     if ($blank = Arr::get($options, 'include_blank')) {
         Arr::unshift($choices, '', $blank === TRUE ? " -- Select -- " : $blank);
     }
     $selected = Jam_Form::list_id($this->object()->{$name});
     return Form::select($attributes['name'], $choices, $selected, $attributes);
 }
Example #14
0
<h1>ACL Debugger</h1>

<p>Something seem off? Check the <?php 
echo HTML::anchor($matrix, 'full matrix');
?>
.</p>

<?php 
echo Form::open();
?>
<p>
	Is <?php 
echo Form::select('role', Arr::unshift($roles, '', '-- any'), $role);
?>
	allowed to <?php 
echo Form::select('action', Arr::unshift($actions, '', '-- any'), $action);
?>
	a <?php 
echo Form::select('resource', Arr::unshift($resources, '', '-- any'), $resource);
?>
	?
	<button type="submit">Test It!</button>
</p>
<?php 
echo Form::close();
?>

<?php 
if (is_bool($allowed)) {
    include Kohana::find_file('views/demo', 'bonafide/acl/check');
}
Example #15
0
 /**
  * Add first element for select
  * @param $items
  * @param array $unshift
  * @return mixed
  */
 private function _get_unshift($items, array $unshift)
 {
     if (isset($unshift[0]) and isset($unshift[1])) {
         $std_class = new stdClass();
         $std_class->id = $unshift[0];
         $std_class->{$this->_display_field} = $unshift[1];
         $std_class->level = 0;
         Arr::unshift($items, $unshift[0], $std_class);
     }
     return $items;
 }