All pastes #765829 Raw Edit

Stuff

public text v1 · immutable
·published 2007-11-08 11:53 UTC
rendered paste body
<?php

class AccountAddNewsPrincipalPage extends ActionPerformed
{
	function initialize()
	{
		$template = & new Template( "Account/Templates/newsPrincipalPage.shtml" );
		$this->renderer->addTemplate( $template );
	}

	function run( & $action )
	{
		
		if($action->arguments['send']==1)  $this->renderer->assign("send",true);	
		if($action->arguments['error']==1) $this->renderer->assign("error",true);
		
		$news = array();
		
		if(isset($action->arguments['idnews'])) {
			$res = $this->env->db->query(sprintf("SELECT * FROM news WHERE id_news = %d",
							$action->arguments['idnews']));
			$news = $res->fetch();
			$this->renderer->assign("news",$news);				
		}
		
		$res = $this->env->db->query(sprintf("SELECT * FROM news"));
		 
		while($row = $res->fetch()) {
		 	
			$arrTmp['id_news'] = $row['id_news'];
			$arrTmp['title'] = $row['title'];
		 	$arrTmp['msg'] = $this->str_quebra($row['msg']."...",40);
		 	$arrNews[] = $arrTmp;
		}
		 
		$this->renderer->assign("arrNews",$arrNews);	

	}
	
	function str_quebra($string, $max_length){

    	if (strlen($string) > $max_length){
        	$string = substr($string, 0, $max_length);

       		$pos = strrpos($string, " ");
       		if($pos === false) {
               return substr($string, 0, $max_length)."...";
            }
       		return substr($string, 0, $pos)."...";
   		}
   		else{
       		return $string;
   		}
	}
}


?>