示例#1
0
 public function test_join_with()
 {
     $arr1 = array(1, 2, 3, 'color' => 'red', 'shape' => 'circle');
     $this->assertEquals(Core_Arrays::join_with(':', $arr1), '1:2:3:red:circle');
 }
示例#2
0
文件: SQL.php 项目: techart/tao
 public function run()
 {
     $binds = count($args = func_get_args()) > 1 ? $args : $args[0];
     $run_callbacks = $binds instanceof DB_SQL_Entity && $this->view && $binds instanceof $this->view->prototype;
     $sql = 'DELETE FROM ' . ($this->table ? $this->table : $this->view->table->name) . "\n";
     if (count($where = Core_Arrays::merge($this->view ? $this->view->__get('where') : array(), $this->where))) {
         $sql .= 'WHERE (' . Core_Arrays::join_with(') AND (', $where) . ')';
     }
     if ($run_callbacks ? $binds->before_delete() : true) {
         $rc = DB_SQL::db()->connection->prepare($sql)->bind($binds)->execute();
     }
     if ($run_callbacks && $rc) {
         $binds->after_delete();
     }
     return $rc;
 }
示例#3
0
文件: Forms.php 项目: techart/tao
 /**
  * Формирует таги select и option для object_select и object_multi_select полей формы
  * 
  * @param Templates_HTML_Template $t
  * @param string $name
  * @param array $attributes
  * @return string
  */
 public function object_select(Templates_HTML_Template $t, $name, array $attributes = array())
 {
     $options = array();
     $field = $this->form->fields[$name];
     $key = $field->key;
     $attribute = $field->attribute;
     $multi = array_search('multiple', $attributes, true) !== false;
     foreach ($field->items as $item) {
         $options[] = $t->content_tag('option', (string) $item->{$attribute}, array('value' => $item->{$key}, 'selected' => $multi ? isset($this->form[$name][$item->{$key}]) : $this->form[$name] && $this->form[$name]->{$key} == $item->{$key}));
     }
     return $t->content_tag('select', (($allow_null = Core_Arrays::pick($attributes, 'allow_null', false)) ? $t->content_tag('option', '') : '') . Core_Arrays::join_with('', $options), Core_Arrays::merge(array('name' => $this->field_name_for($name) . ($multi ? '[]' : ''), 'id' => $this->field_id_for($name)), $attributes));
 }
示例#4
0
文件: Message.php 项目: techart/tao
 /**
  * Приводит имя к виду соответствующему почтовому стандарту
  *
  * @param string $name
  *
  * @return string
  */
 protected function canonicalize($name)
 {
     $parts = Core_Arrays::map('return strtolower($x);', Core_Strings::split_by('-', trim($name)));
     foreach ($parts as &$part) {
         $part = isset(self::$acronyms[$part]) ? self::$acronyms[$part] : (preg_match('{[aeiouyAEIOUY]}', $part) ? ucfirst($part) : strtoupper($part));
     }
     return Core_Arrays::join_with('-', $parts);
 }
示例#5
0
文件: Forms2.php 项目: techart/tao
 public function object_select($t, $name, array $attributes = array())
 {
     $options = array();
     $field = $this->form->fields[$name];
     $key = $field->key;
     $attribute = $field->attribute;
     $this->add_error_class($name, $attributes);
     foreach ($field->items as $item) {
         $options[] = $t->tags->content_tag('option', (string) $item->{$attribute}, array('value' => $item->{$key}, 'selected' => $this->form[$name]->{$key} == $item->{$key}));
     }
     return (($label = Core_Arrays::pick($attributes, 'label', false)) ? $this->label($name, $label) . ' ' : '') . $t->tags->content_tag('select', (($allow_null = Core_Arrays::pick($attributes, 'allow_null', false)) ? $t->tags->content_tag('option', '') : '') . Core_Arrays::join_with('', $options), Core_Arrays::merge(array('name' => $this->field_name_for($name), 'id' => $this->field_id_for($name)), $attributes));
 }
示例#6
0
 /**
  * @return string
  */
 protected function make_name_and_views_path()
 {
     $parts = Core_Strings::split_by('_', Core_Strings::downcase(Core_Regexps::replace('{Controller$}', '', Core_Types::class_name_for($this))));
     array_shift($parts);
     $this->name = Core_Arrays::join_with('.', $parts);
     //$this->views_path = Core_Arrays::join_with('/', $parts);
 }
示例#7
0
文件: HTML.php 项目: techart/tao
 protected function http_to_string($name, $content)
 {
     return sprintf("<meta http-equiv=\"%s\" content=\"%s\" />\n", htmlspecialchars(Core_Arrays::join_with('-', Core_Arrays::map('return ucfirst(strtolower($x));', Core_Strings::split_by('_', $name)))), htmlspecialchars($content));
 }