return true;
}
- public function rows(&$opt=array(),$opt_by_val=null) {
+ public function rows(&$opt=[],$opt_by_val=null) {
$this->create_temporary();
# Use the module out when format unknow
$out_conf = null;
if ($this->p('out') or !preg_match('/^('.join('|',
- array( 'table','sql','div','wp','_csv','_xml','_json','_yaml' ) # local
+ [ 'table','sql','div','wp','_csv','_xml','_json','_yaml' ] # local
).')$/',$format))
{
if (!($out_conf = out::type($format))) $this->bye("Unknow format `$format`");
self::$params += array_values(out::$types);
- if (empty($out_conf['enclose'])) $out_conf['enclose'] = array('','');
+ if (empty($out_conf['enclose'])) $out_conf['enclose'] = ['',''];
debug('Using out module!',3);
}
-----------------------------------------------------------------*/
public function rows_begin_yaml() { return "---\n"; }
#public function rows_rec_yaml(&$row) { return $this->yaml_encode($row); }
- public function rows_rec_yaml(&$row) { out::row(array("function"=>"out_yaml"),$row); }
+ public function rows_rec_yaml(&$row) { $o=["function"=>"out_yaml"];out::row($o,$row); }
public function rows_end_yaml() { return ''; }
/*-----------------------------------------------------------------
#bye($o);
- #if (self::p('header')==="0") return;
if (isset($o['enclose'])) echo $o['enclose'][0];
if (!isset($o['head'])) return;
if (self::p('header') === '0' ) return;
if ($head === false) return;
- $o['data'] = $data;
echo $o['head']($head,$o) . empty($o['eol']) ? '' : $o['eol'];
return $head;
}
- public static function row($o,&$row) {
+ public static function row(&$o,&$row) {
# Defined function
if (isset($o['function'])) {
// Human
//
function out_human_head(&$head,&$o) {
- $o['return'] = true;
- $o['sep.human'] = $o['sep'];
- $o['sep'] = "\t";
- $GLOBALS['_human_len'] = [];
- $o['tmpfile'] = tmpfile();
#$line = "a\tb\tc\t\t\tg"; bye(explode("\t",$line));
+ if (out::p('header')==='0') return '';
+ $o['_human'] = [
+ 'head' => 1,
+ ];
if (out::is_hash($head)) $head = array_keys($head);
return out_human($head,$o);
}
function out_human(&$row,&$o) {
+ if (empty($GLOBALS['_human_len'])) {
+ $GLOBALS['_human_len'] = [];
+ if (empty($o['_human'])) $o['_human'] = [];
+ $o['sep.human'] = $o['sep'];
+ $o['sep'] = "\t";
+ $o['return'] = true;
+ $o['tmpfile'] = tmpfile();
+ }
$line = out_csv($row,$o);
$i = 0;
$sep_line .= '+'."\n";
}
+ $header = empty($o['_human']['head']) ? 0 : 1;
$count = 0;
while (($line = fgets($o['tmpfile'])) !== false) {
$values = [];
$values[] = sprintf("%".'-'.$len[$i]."s",$v);
$i++;
}
- if (!$count) echo $sep_line;
- echo ''
+ # header
+ if (!$count) {
+ echo $sep_line;
+ }
+
+ #debug($count);
+ if ($header or $count>0)echo ''
. ltrim($o['sep.human'])
. join($o['sep.human'],$values)
. rtrim($o['sep.human'])
."\n";
- if (!$count) echo $sep_line;
+ if ($header and !$count) echo $sep_line;
$count++;
}
fclose($o['tmpfile']);
+ unset($GLOBALS['_human_len']);
+ unset($o['_human']);
+
+ if ($header) $count--;
if (!$count) return;
+
echo $sep_line;
- print "$count Records\n";
+ echo "$count Records\n";
+
}
# < Functions
/****************************************************************************/