------------------------------------------------------------ revno: 796 committer: Roger Martin <rg1...@gmail.com> branch nick: aikiframework timestamp: Tue 2011-06-07 22:52:37 +0200 message: added set,get,show, order,last, first to message class modified: src/system/libraries/message.php
-- lp:aikiframework https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk Your team Aiki Framework Developers is subscribed to branch lp:aikiframework. To unsubscribe from this branch go to https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk/+edit-subscription
=== modified file 'src/system/libraries/message.php' --- src/system/libraries/message.php 2011-06-07 03:10:07 +0000 +++ src/system/libraries/message.php 2011-06-07 20:52:37 +0000 @@ -50,10 +50,10 @@ /* * function message * - * draft horse of module. Show o return a message. + * draft horse of module. Show or return a message. * * @param $text : text to show. Will be translated if there is a - * t (translate) function or is workin $aiki->languages + * t (translate) function or is working $aiki->languages * @param $attribs (optional=NULL): array of html atributes (id,class, style,onmouse).. * @param echo ($option=false) true, echo the result, and false return it. */ @@ -98,23 +98,32 @@ function store($message, $key="", $add=true){ if ( $key==""){ - $this->stored[]= $message; - } else { - $previuos = ( $add && isset($this->stored[$key])? $this->stored[$key] :""); - $this->stored[$key] = $previuos . $message; - } + $this->stored[]= array($message); + return end($this->stored); + } elseif ( $add===false ) { + $this->stored[$key]= array($message); + return $key; + } elseif ( $add===true ) { + $this->stored[$key][]= $message; + return $key; + } else { + $this->stored[$key][$add]= $message; + } } - function unstore( $key="*", $echo = false, $clear= true){ + function unstore( $key="*", $echo = false, $clear= true, $glue="\n"){ $ret=""; if ( $key=="*" ) { - $ret= implode("\n",$this->stored); + $ret=""; + foreach ( $this->stored as $k=>$v){ + $ret.= implode($glue,$v); + } if ( $clear) { $this->stored= array(); } } else { if ( isset($this->stored[$key]) ) { - $ret= $this->stored[$key]; + $ret= implode($glue,$this->stored[$key]); if ( $clear ){ unset($this->stored[$key]); } @@ -126,6 +135,78 @@ return $ret; } + + function order($key, $order="asc"){ + if ( !isset($this->stored[$key]) ) { + return false; + } + switch ( strtolower($order) ){ + case "asc" : ksort($this->stored[$key]) ; break; + case "desc" : krsort($this->stored[$key]) ; break; + case "asc-values" : asort($this->stored[$key]) ; break; + case "desc-values" : arsort($this->stored[$key]) ; break; + case "natural" : natsort($this->stored[$key]); break; + default : return false; + } + return true; + } + + function set($key,$message){ + return $this->store($message,$key, false); + } + + function add($key,$message,$order=false){ + return $this->store($message,$key, ( $order===false ? true: $order) ); + } + + function get($key, $glue="ul" ){ + if ( !isset($this->stored[$key]) ){ + return ( $glue=="as array"? array() : "" ); + } + + $tag= array();; + if ( preg_match('#^<([^ />]*) ?[^>]*>$#s',$glue,$tag) ){ + // it's a HTML tag + $tag= $tag[1]; + echo "*** $tag ***"; + switch ( $tag ){ + case "ul": + case "ol": return "$glue<li>". implode("</li><li>", $this->stored[$key]) ."</li></$tag>"; + case "br": return implode($glue, $this->stored[$key]); + default : return "$glue". implode("</$tag>$glue", $this->stored[$key]) ."</$tag>"; + } + } + + switch ($glue){ + case "as array": return $this->stored[$key]; + case "comented-list": return "<!-- ". implode(", ", $this->stored[$key]) ."-->"; + case "li": return "<li>". implode("</li><li>", $this->stored[$key]) ."</li>"; + case "ol": + case "ul": return "<$glue><li>". implode("</li><li>", $this->stored[$key]) ."</li></$glue>"; + default : return implode($glue, $this->stored[$key]); + } + return ""; + } + + function show($key, $glue){ + echo $this->get($key,$glue); + } + + function last($key){ + if ( isset($this->stored[$key]) ){ + return end($this->stored[$key]); + } + return false; + } + + function first($key){ + if ( isset($this->stored[$key]) ){ + return reset($this->stored[$key]); + } + return false; + } + + //shortcuts for login error function set_login_error($error){ $this->store( $this->error($error, array("id"=>"login-wrong-username"),false),"error-in-login"); @@ -135,7 +216,6 @@ return $this->unstore( "error-in-login",false,false); } - private function Addclass ( $default, &$attribs ){ return $default . (isset($attribs['class']) ? " ". $attribs['class'] : "" ); }
_______________________________________________ Mailing list: https://launchpad.net/~aikiframework-devel Post to : aikiframework-devel@lists.launchpad.net Unsubscribe : https://launchpad.net/~aikiframework-devel More help : https://help.launchpad.net/ListHelp