Beispiel #1
0
 public function test_pick()
 {
     $arr = array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3');
     $this->assertEquals(Core_Arrays::pick($arr, 'key2'), 'value2');
     $this->assertEquals($arr, array('key1' => 'value1', 'key3' => 'value3'));
 }
Beispiel #2
0
 /**
  * Формитуеи таг form
  * 
  * @param Templates_HTML_Template $t
  * @param string $action
  * @param string $method
  * @param array $attributes
  * @return string
  */
 public function begin_form_tag(Templates_HTML_Template $t, $action, $method, array $attributes = array())
 {
     $add_method_field = Core_Arrays::pick($attributes, 'add_method_field', false);
     $result = $t->tag('form', Core_Arrays::merge(array('action' => $action, 'method' => $method == 'post' || $method == 'get' ? $method : 'post'), $attributes), false) . "\n";
     if ($method == 'put' || $method == 'delete' || $add_method_field) {
         $result .= $t->tag('input', array('type' => 'hidden', 'name' => '_method', 'value' => $method)) . "\n";
     }
     return $result;
 }
Beispiel #3
0
 public function __construct($url, $title, array $options = array())
 {
     $this->url = $url;
     $this->title = $title;
     $this->is_disabled = (bool) Core_Arrays::pick($options, 'disabled', false);
     $this->is_selected = (bool) Core_Arrays::pick($options, 'selected', false);
     $this->options = Data::Hash($options);
 }
Beispiel #4
0
 public function datetime_select($t, $name, $attributes = array())
 {
     $value = $this->form[$name];
     $show_time = Core_Arrays::pick($attributes, 'show_time', false);
     $this->add_error_class($name, $attributes);
     return (($label = Core_Arrays::pick($attributes, 'label', false)) ? $this->label_tag($this->field_id_for($name) . '_day', $label) . ' ' : '') . $this->select_tag($this->field_name_for($name) . '[day]', $this->days, $value ? $value->day : null, Core_Arrays::merge(array('id' => $this->field_id_for($name) . '_day'), isset($attributes['day']) ? Core_Arrays::merge($attributes, (array) $attributes['day']) : $attributes)) . ' ' . $this->select_tag($this->field_name_for($name) . '[month]', $this->months, $value ? $value->month : null, Core_Arrays::merge(array('id' => $this->field_id_for($name) . '_month'), isset($attributes['month']) ? Core_Arrays::merge($attributes, (array) $attributes['month']) : $attributes)) . ' ' . $this->input_tag($this->field_name_for($name) . '[year]', $value && $value->year > 0 ? $value->year : '', Core_Arrays::merge(array('id' => $this->field_id_for($name) . '_year', 'size' => 4), isset($attributes['year']) ? Core_Arrays::merge($attributes, (array) $attributes['year']) : $attributes)) . ' ' . ($show_time ? $this->select_tag($this->field_name_for($name) . '[hour]', $this->hours, $value ? $value->hour : null, Core_Arrays::merge(array('id' => $this->field_id_for($name) . '_hour'), isset($attributes['hour']) ? Core_Arrays::merge($attributes, (array) $attributes['hour']) : $attributes)) . ' ' . $this->select_tag($this->field_name_for($name) . '[minute]', $this->minutes, $value ? $value->minute : null, Core_Arrays::merge(array('id' => $this->field_id_for($name) . '_minute'), isset($attributes['minute']) ? Core_Arrays::merge($attributes, (array) $attributes['minute']) : $attributes)) : '');
 }
Beispiel #5
0
 /**
  * Формирует кнопку, отправляющую запрос по указанному адресу
  *
  * @param string $url
  * @param string $text
  * @param string $method
  * @param array  $attributes
  *
  * @return string
  */
 public function form_button_to($url, $text, $method = 'get', array $attributes = array())
 {
     $confirmation = Core_Arrays::pick($attributes, 'confirm');
     return $this->tag('input', array('value' => $text, 'type' => 'submit', 'onclick' => "this.form.action='{$url}';" . 'this.form.method=\'' . ($method == 'get' || $method == 'post' ? $method : 'post') . '\';' . "this.form.elements._method.value='{$method}';" . 'return ' . $this->make_confirmation($confirmation) . ';') + $attributes);
 }