2009-12-04 18:52:19 +00:00
< ? php
/*
* e107 website system
*
* Copyright ( c ) 2008 - 2009 e107 Inc ( e107 . org )
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Featurebox Category model
*
* $Source : / cvs_backup / e107_0 . 8 / e107_plugins / featurebox / includes / category . php , v $
2010-02-10 18:18:01 +00:00
* $Revision $
* $Date $
* $Author $
2009-12-04 18:52:19 +00:00
*
*/
2009-12-08 17:21:36 +00:00
if ( ! defined ( 'e107_INIT' )) { exit ; }
2009-12-04 18:52:19 +00:00
class plugin_featurebox_category extends e_model
{
/**
* @ var plugin_featurebox_tree
*/
protected $_tree = null ;
2009-12-08 17:21:36 +00:00
/**
* Data loaded check
* @ var boolean
*/
protected $_loaded_data = null ;
/**
* @ see e_model :: _field_id
* @ var string
*/
protected $_field_id = 'fb_category_id' ;
/**
* @ see e_model :: _db_table
* @ var string
*/
protected $_db_table = 'featurebox_category' ;
/**
* Parameter ( single string format ) :
* - alt : return title as tag attribute text
* @ param string $parm
* @ return string
*/
public function sc_featurebox_category_title ( $parm )
{
return ( $parm == 'alt' ? e107 :: getParser () -> toAttribute ( $this -> get ( 'fb_category_title' )) : e107 :: getParser () -> toHTML ( $this -> get ( 'fb_category_title' ), false , 'TITLE' ));
}
/**
* Parameter ( single string format ) :
* - src : return image src URL only
*
* @ param string $parm
* @ return string
*/
public function sc_featurebox_category_icon ( $parm )
{
if ( ! $this -> get ( 'fb_category_icon' ))
{
return '' ;
}
$tp = e107 :: getParser ();
$src = $tp -> replaceConstants ( $this -> get ( 'fb_category_icon' ), 'full' );
if ( $parm == 'src' )
{
return $src ;
}
2009-12-09 18:36:33 +00:00
return '<img src="' . $src . '" alt="' . $tp -> toAttribute ( $this -> get ( 'fb_category_title' )) . '" class="icon featurebox" />' ;
2009-12-08 17:21:36 +00:00
}
2009-12-09 18:36:33 +00:00
public function sc_featurebox_category_template ()
2009-12-08 17:21:36 +00:00
{
2009-12-10 22:46:46 +00:00
return $this -> get ( 'fb_category_template' );
2009-12-08 17:21:36 +00:00
}
2009-12-10 22:46:46 +00:00
public function sc_featurebox_category_limit ()
{
return $this -> get ( 'fb_category_limit' );
}
public function sc_featurebox_category_total ()
{
return $this -> getParam ( 'total' , 0 );
}
public function sc_featurebox_category_all ()
{
return $this -> getItemTree () -> getTotal ();
}
public function sc_featurebox_category_cols ()
{
return $this -> getParam ( 'cols' , 1 );
}
public function sc_featurebox_nav_counter ()
{
return $this -> getParam ( 'counter' , 1 );
}
public function sc_featurebox_nav_active ()
{
return $this -> getParam ( 'active' ) ? ' active' : '' ;
}
public function sc_featurebox_category_emptyfill ()
{
return $this -> getParam ( 'no_fill_empty' , 0 );
}
2009-12-04 18:52:19 +00:00
/**
* Load category data by layout
2009-12-08 17:21:36 +00:00
* TODO - system cache
2009-12-04 18:52:19 +00:00
*
2009-12-09 18:36:33 +00:00
* @ param string $template
2009-12-04 18:52:19 +00:00
* @ param boolean $force
2009-12-08 17:21:36 +00:00
* @ return plugin_featurebox_category
2009-12-04 18:52:19 +00:00
*/
2009-12-09 18:36:33 +00:00
public function loadByTemplate ( $template , $force = false )
2009-12-04 18:52:19 +00:00
{
2009-12-08 17:21:36 +00:00
if ( $force || null === $this -> _loaded_data )
{
2020-12-14 16:21:48 -08:00
if ( e107 :: getDb () -> select ( 'featurebox_category' , '*' , 'fb_category_class IN (' . USERCLASS_LIST . ') AND fb_category_template=\'' . e107 :: getParser () -> toDB ( $template ) . '\'' ))
2009-12-08 17:21:36 +00:00
{
2020-12-14 16:21:48 -08:00
$this -> setData ( e107 :: getDb () -> fetch ());
2009-12-08 17:21:36 +00:00
$this -> _loaded_data = true ;
}
}
$this -> _loaded_data = false ;
return $this ;
2009-12-04 18:52:19 +00:00
}
/**
* Get items model tree for the current category
* TODO - system cache
*
* @ param boolean $force
* @ return plugin_featurebox_tree
*/
2009-12-08 17:21:36 +00:00
public function getItemTree ( $force = false )
2009-12-04 18:52:19 +00:00
{
if ( $force || null === $this -> _tree )
{
$this -> _tree = new plugin_featurebox_tree ();
2009-12-08 17:21:36 +00:00
$options = array (
'limit' => $this -> getParam ( 'limit' , $this -> get ( 'fb_category_limit' )),
2009-12-10 22:46:46 +00:00
'from' => $this -> getParam ( 'from' , 0 ),
2010-11-20 15:43:02 +00:00
'random' => $this -> getParam ( 'random' , $this -> get ( 'fb_category_random' )),
'ids' => $this -> getParam ( 'ids' , '' )
2009-12-08 17:21:36 +00:00
);
2021-01-14 10:31:51 -08:00
$this -> _tree -> load ( $this -> getId (), $force , $options );
2009-12-04 18:52:19 +00:00
}
return $this -> _tree ;
}
/**
* Set item tree
*
2009-12-08 17:21:36 +00:00
* @ param plugin_featurebox_tree $item_tree
2009-12-04 18:52:19 +00:00
* @ return plugin_featurebox_category
*/
2009-12-08 17:21:36 +00:00
public function setItemTree ( $item_tree )
2009-12-04 18:52:19 +00:00
{
2009-12-08 17:21:36 +00:00
$this -> _tree = $item_tree ;
2009-12-04 18:52:19 +00:00
return $this ;
}
}