MANY (to MANY) THANKS!!!

Your informations really helped me out!
I ended up with a control including a repeater that manage pager using SQLMap...
I think this is interessant as it took me a while to get everything working well, so here's some part of my code.
In protected/application.xml
<module id="sqlmap" class="System.Data.SqlMap.TSqlMapConfig" EnableCache="false" ConfigFile="Application.database.sqlmap" ConnectionID="dbVod" />
In protected/database/sqlmap.xml
<?xml version="1.0" encoding="UTF-8" ?>
<sqlMapConfig>
<sqlMap resource="maps/VideoRecord.xml" />
</sqlMapConfig>
Note: 3 different queries are used: one to get all rows, one for a certain "page" of rows, and the last one to count the rows.In protected/database/maps/VideoRecord.xml
<sqlMapConfig>
<select id="SelectVideosByCategoryAndStatus" resultClass="VideoRecord" parameterClass="SelectVideosByCategoryAndStatus_Param_Item">
select v.*
from video as v
inner join categorie_video as c on v.id = c.id_video
where c.id_categorie = #idCategorie#
and v.id_status = #idStatus#
order by #orderBy# #order#
</select>
<select id="SelectVideosByCategoryAndStatus_Pager" resultClass="VideoRecord" parameterClass="SelectVideosByCategoryAndStatus_Param_Item">
select v.*
from video as v
inner join categorie_video as c on v.id = c.id_video
where c.id_categorie = #idCategorie#
and v.id_status = #idStatus#
order by #orderBy# #order#
limit #limit# offset #offset#
</select>
<select id="SelectVideosByCategoryAndStatus_Counter" resultClass="int" parameterClass="SelectVideosByCategoryAndStatus_Param_Item">
select count(v.id)
from video as v
inner join categorie_video as c on v.id = c.id_video
where c.id_categorie = #idCategorie#
and v.id_status = #idStatus#
</select>
</sqlMapConfig>
In protected/database/VideoRecord.php
<?php
class VideoRecord extends TActiveRecord
{
const TABLE='video';
public $id;
public $title;
public $description;
public $date_added;
public $duration_sec;
public $views;
public $id_publisher;
public $id_status;
public $status;
public $publisher;
public $files=array();
public $categories=array();
public $tags=array();
public $videos=array();
public static $RELATIONS=array
(
'status' => array(self::BELONGS_TO, 'VideoStatusRecord'),
'publisher' => array(self::BELONGS_TO, 'UserRecord'),
'files' => array(self::HAS_MANY, 'VideoFileRecord', 'id_video'),
'categories' => array(self::MANY_TO_MANY, 'CategorieRecord', 'categorie_video'),
'tags' => array(self::MANY_TO_MANY, 'TagRecord', 'tag_video')
);
public static function finder($className=__CLASS__)
{
return parent::finder($className);
}
}
/* sqlMap classes, see ./maps/VideoRecord.xml */
class SelectVideosByCategoryAndStatus_Param_Item
{
public $idCategorie;
public $idStatus;
public $orderBy = 'views';
public $order = 'asc';
public $offset = 0;
public $limit = 0;
}
?>
In protected/pages/controls/CategoriesListVideo.tpl
<ul class="videoList">
<com:TRepeater ID="rpVideos"
ItemRenderer="Application.pages.videos.CategoriesListVideoRenderer"
AllowPaging="true"
AllowCustomPaging="true"
/>
</ul>
<com:TPager ControlToPaginate="rpVideos" OnPageIndexChanged="pageChanged" />
Note: this is where the repeater pager is managed.In protected/pages/controls/CategoriesListVideo.php
<?php
class CategoriesListVideo extends TTemplateControl {
protected $ID_Category = 0;
protected $sqlmap;
protected $sqlmap_param;
protected $PageSize = 30;
protected $NbVideos = 0;
public function onInit($param)
{
parent::onInit($param);
$this->ID_Category = (int)$this->Request['id'];
$this->sqlmap = $this->Application->Modules['sqlmap']->Client;
$this->sqlmap_param = new SelectVideosByCategoryAndStatus_Param_Item;
$this->sqlmap_param->idCategorie = $this->ID_Category;
$this->sqlmap_param->idStatus = 2;
$this->NbVideos = $this->sqlmap->queryForObject("SelectVideosByCategoryAndStatus_Counter", $this->sqlmap_param);
$this->rpVideos->PageSize=$this->PageSize;
$this->rpVideos->VirtualItemCount = $this->NbVideos;
$this->populateData();
}
public function pageChanged($sender,$param)
{
$this->rpVideos->CurrentPageIndex=$param->NewPageIndex;
$this->populateData();
}
protected function populateData()
{
$offset=$this->rpVideos->CurrentPageIndex*$this->rpVideos->PageSize;
$limit=$this->rpVideos->PageSize;
if($offset+$limit > $this->rpVideos->VirtualItemCount)
$limit=$this->rpVideos->VirtualItemCount-$offset;
$this->rpVideos->DataSource=$this->getVideos($offset,$limit);
$this->rpVideos->DataBind();
}
protected function getVideos($offset, $limit)
{
$this->sqlmap_param->limit=$limit;
$this->sqlmap_param->offset=$offset;
if (($offset > 0) && ($limit > 0))
{
$query_name = 'SelectVideosByCategoryAndStatus_Pager';
}
else
{
$query_name = 'SelectVideosByCategoryAndStatus';
}
return $this->sqlmap->queryForList($query_name, $this->sqlmap_param);
}
}
?>
This works fine with TRepeater and TPager.
Thanks again for the help.
Bye.
PS: I added an article in FRENCH to my blog covering this subject
http://support.oxegena.ch/blog/prado-sqlmap-trepeater-et-tpager-requetes-sql-personnalisees-avec-pagination/26