class.comments.php 5.74 KB
<?php
/**
* @author:  Bunzia Alexander <nifus@mail.ru> <http://www.weblancer.net/users/nifus/>
* @copyright: Copyright (c) 2010, Bunzia Alexander
* @version: 1.0
* @license: http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @package poremotnu
*/

class filedsGetPoremontuCommentsQuery
{
	static function time_add($v){
		return 	date('d.m.Y h:i',$v);
	}
	
	static function profile_url($v){
		include_once(MAIN_SOURCE_PATH.'/modules/users/inc/url.php');
		return 	sys_url(URL_USER_PROFILE,$v);
	}
	
	static function avatar_url($v){
	global $MAIN_PAGE;
	  include_once(MAIN_SOURCE_PATH.'/modules/users/inc/cache.php');
		if ( !empty($v) ){
		  	return MAIN_RF_URL.'/source/modules/ajax/tmp/crop_'.$v;
		}else{
		  return MAIN_RF_URL.$MAIN_PAGE -> config('user_default_avatar');
		}
	}
	
	/*static function row_class($v){
		return !empty($v) ? 'body2' : 'body_red';
	}*/
	static function c_comment($v){
		return sys_convert_br($v);
	}
	
	/*static function comment_url($v,$row){
		
		if ( empty($row['module']) || empty($row['n_id']) || empty($v) ){
			sys_error(500);
		}
			//	подключаем класс комментариев модуля
		include_once(MAIN_SOURCE_PATH.'/modules/'.$row['module'].'/inc/class.comments.php');
		$class = $row['module'].'_comments';
	//	return $class::comment_url($v,$row['n_id']);
	}*/
	
		//	получаем общее количество комментов
	static function count_all(){
		$s = new comments_q( $this -> table ,'c' );
		$s -> get('COUNT(*)');
		list($count) = $s -> row();
		return $count;
	}
	
			//	получаем  количество комментов за сегодня
	static function count_on_day(){
		$time = mktime(0,0,0,date('m',MAIN_TIME),date('d',MAIN_TIME),date('Y',MAIN_TIME) );
		$s = new comments_q( $this -> table ,'c' );
		$s -> set_anothe_where('c.c_time_add>='.$time);
		$s -> set_anothe_where('c.c_time_add<='.MAIN_TIME);
		$s -> get('COUNT(*)');
		list($count) = $s -> row();
		return $count;
	}
		//	получаем количество комментов на модерации
	static function count_wait(){
		$s = new comments_q( $this -> table ,'c' );
		$s -> where_active(0);
		//$n -> set_debug(1);
		$s -> get('COUNT(*)',false);
		list($count) = $s -> row();
		return $count;
	}

}

class filedsSetPoremontuCommentsQuery
{

  static function c_message($v){
		if ( empty($v) ){
		  throw new Exception(E_COMMENTS_EMPTY_MESSAGE);
		}
		return $v;
	}
	
	static function u_id($v=-1){
	  if ( false===$v ){
	    $this -> set_info['u_id']=0;
	  }elseif( $v==-1 ){
	    throw new Exception( E_COMMENTS_EMPTY_ID );
	  }else{
	    return intval($v);
	  }
		return true;
	}
	
	
	public function u_login($v=-1){
	 
	  if ( false===$v ){
	    $this -> set_info['u_login']='';
	  }elseif( $v==-1 ){
	    throw new Exception( E_COMMENTS_EMPTY_LOGIN );
	  }else{
	    return $v;
	  }
		return true;
	}
	
	public function n_id($v){
		$v = intval($v);
		if ( empty($v) ){
		  throw new Exception( E_COMMENTS_EMPTY_OBJ );
		}
		return $v;
	}
	
	public function c_active($v){
		if ( !isset($v) ){
			return false;
		}
		
		if ( !empty($v) ){
			return 1;	
		}else{
			return 0;
		}
		
		return true;
	}
}

class poremontuCommentsQuery extends query
{
  var $fields_get = 'filedsGetPoremontuCommentsQuery';

	public function __construct($table,$alias)
	{
		$this -> set_table($table);
		$this -> set_alias($alias);
	}
	
		/**
  * Подключаем таблицу пользователей
  * 
  * @var: string $alias Алиас для исплользования в mysql запросе
  * @var: string $cols нужные столбцы
  */
  public function include_users($alias,$cols=false){
		$this -> include_table( MAIN_USERS_TBL ,$alias,'u_id',$cols );
	}
	
	
	public function where_id($v){
		$v = intval($v);
		if ( empty($v)  ){
			return FALSE;
		}
		return $this -> set_where( $this -> alias.'.c_id',$v);
	}
	
	public function where_obj($v){
		$v = intval($v);
		if ( empty($v)  ){
			return FALSE;
		}
		return $this -> set_where( $this -> alias.'.n_id',$v);
	}
	
	public function where_active($v){
		$v = intval($v);
		if (!empty($v)  ){
			$v = 1;
		}
		return $this -> set_where( $this -> alias.'.c_active',$v);
	}
	
	public function where_login($v){
		
		if ( false!==users::error_login($v) ){
			return false;
		}
		return $this -> set_where( $this -> alias.'.u_login',$v);
	}

  public function where_uid($v){
		$v = intval($v);
		if ( empty($v) ){
		  return false;
		}
		return $this -> set_where( $this -> alias.'.u_id',$v);
	}
	
	public function orderby_module($v,$alias=true){
		if ( $alias ){
			return 	$this -> set_orderby($this -> alias.'.module_name ',$v);
		}else{
			return 	$this -> set_orderby('module_name ',$v);
		}
	}
	public function orderby_id($v,$alias=true){
		if ( $alias ){
			return 	$this -> set_orderby($this -> alias.'.c_id',$v);
		}else{
			return 	$this -> set_orderby('c_id',$v);
		}
	}
	public function orderby_ulogin($v,$alias=true){
		if ( $alias ){
			return 	$this -> set_orderby($this -> alias.'.u_login',$v);
		}else{
			return 	$this -> set_orderby('u_login',$v);
		}
	}
	public function orderby_time_add($v,$alias=true){
		if ( $alias ){
			return 	$this -> set_orderby($this -> alias.'.c_time_add',$v);
		}else{
			return 	$this -> set_orderby('c_time_add',$v);
		}
	}

}

class poremontuComments extends objects
{
  public $table = "comments";
  public $key = "c_id";
	public $fields = 'filedsSetPoremontuCommentsQuery';
	
  static function query($table,$a){
    return new poremontuCommentsQuery($table,$a);
  }
  
  static function load_id($table,$id){
		$u = self::query($table,'u');
		
		if ( !$u -> where_id($id) ){
			return FALSE;
		}
		if ( !$u -> get('u.*') ){
			return FALSE;
		}
		if (  $u -> get_count_rows()==0 ){
			return FALSE;
		}
		$c =  new self( $id,$u -> row() );
		$c -> table = $table;
		return $c;
	}
  
  
}

	
?>