Here is a detail summary view using UDTs. It will show a single detail record and a summary from ListIt, without making any modifications to the source code. I've never used the CGblog (I use NEWS on Studio-Owens.com as a Blog) so I have no idea if this would be similar. The ListIt Module is based upon the
EAV datamodel so it isn't going to be suited for large amounts of records.
I am presenting two methods here. Method one just filters the existing data. Method two queries the DB to find the single record data. Both use the same concept to build URLs and create summary pages.
Method One Filter The Existing Data
Create a UDT called
listit_details_check
Put this code in the UDT...
Code: Select all
if ($params['thisid'] == (int)$_GET['cntnt01itemid']) {
echo True;
} else {
echo False;
}
Next modify the ListIt template named "
default"
Add a {capture} and {if} inside the {foreach}. This is what the stock "
default" template will look like when modified (new code is on lines 2,3, and 19)...
Code: Select all
{foreach from=$items item=item}
{capture assign="idCheck"}{listit_details_check thisid=$item.item_id}{/capture}
{if $idCheck == True}
<div class="item">
<h2 class="item-title">{$item.title|cms_escape}</h2>
<div class="item-category">Category: {$item.category_name|cms_escape}</div>
{if !empty($item.fielddefs)}
<div class="item-properties">
{foreach from=$item.fielddefs item=fielddef}
{if $fielddef.type == 'upload_file' || $fielddef.type == 'select_file'}
{$fielddef.name|cms_escape}: <a href="{$fielddef.dir|cms_escape}/{$fielddef.value|cms_escape}">{$fielddef.value|cms_escape}</a><br />
{else}
{$fielddef.name|cms_escape}: {$fielddef.value|cms_escape}<br />
{/if}
{/foreach}
</div>
{/if}
</div><!-- item -->
{/if}
{/foreach}
Method Two Query The Database For The Record
Create a UDT called
listit_get_record
Put this code in the UDT...
Code: Select all
$db_prefix = $params['db_prefix'];
$listit_name = $params['listit_name'];
$itemid = (int)$_GET['cntnt01itemid'];
if (is_int($itemid)) {
$gCms = cmsms(); //global $gCms;
$smarty = &$gCms->GetSmarty();
$db =& $gCms->GetDB();
$r = $db->Execute("SELECT category_id, title, active FROM ".$db_prefix."module_".$listit_name."_item AS i
WHERE i.item_id=".$db->qstr($itemid)." LIMIT 1");
if ($r) {
$data= array();
$row = $r->FetchRow();
$data['title'] = $row['title'];
$data['active'] = $row['active'];
$r1 = $db->Execute("SELECT category_name FROM ".$db_prefix."module_".$listit_name."_category AS c
WHERE c.category_id=".$db->qstr($row['category_id'])." LIMIT 1");
if ($r1) {
$rowC = $r1->FetchRow();
$data['category_name'] = $rowC['category_name'];
}
$r2 = $db->Execute("SELECT fielddef_id, value FROM ".$db_prefix."module_".$listit_name."_fieldval AS fv
WHERE fv.item_id=".$db->qstr($itemid));
if ($r2) {
while($r2 && $rowFv = $r2->FetchRow()) {
$r3 = $db->Execute("SELECT alias FROM ".$db_prefix."module_".$listit_name."_fielddef AS fd
WHERE fd.fielddef_id=".$db->qstr($rowFv['fielddef_id'])." LIMIT 1");
if ($r3) {
$rowFd = $r3->FetchRow();
$data[$rowFd['alias']] = $rowFv['value'];
}
}
}
$smarty->assign('itemDetail', $data);
}
}
The UDT is used like this; inserting your own database table prefix and change the listit_name if you cloned this as a new module.
Code: Select all
{listit_get_record db_prefix='cms_' listit_name='listit'}
The {$itemDetail} array being returned by this UDT always contains these keys:
Code: Select all
{$itemDetail.title|cms_escape}
{$itemDetail.category_name|cms_escape}
{$itemDetail.active|cms_escape}
The {$itemDetail} array will also contain the alias and value of your custom defined Field Definitions. It can be used like the following; replace alias with the alias you defined:
Next modify the ListIt template named "
default" constructing your own custom template. An example would be:
Code: Select all
{listit_get_record db_prefix='cms_' listit_name='listit'}
{if $itemDetail.active == 1}
<div class="item" style="margin-top:50px;">
<h2 class="item-title">{$itemDetail.title|cms_escape}</h2>
<div class="item-category">Category: {$itemDetail.category_name|cms_escape}</div>
<div class="item-properties">
Something: {$itemDetail.alias|cms_escape}<br/>
Something Link: <a href="{$itemDetail.alias|cms_escape}">Something</a><br />
</div>
</div><!-- item -->
{/if}
URL construction for the Details Page
Then construct a URL to call your new the ListIt Module detail page:
&cntnt01itemid=1 : is the ListIt item_id that is to be displayed
&cntnt01returnid=58 : is the page template to use for displaying your single record.
Code: Select all
http://www.yoursite.com/index.php?mact=ListIt,cntnt01,default,0&cntnt01itemid=1&cntnt01returnid=58
Pretty URLs
If using Mod Rewrite you could clean up the URL by doing the method found in the CMSMS handbook on this page under "For News module":
http://wiki.cmsmadesimple.org/index.php ... stallation
Basically create a subfolder called /listit and add an .htaccess file to it with the following code (change the .htm if you are using a different extension or no extension at all)...
Code: Select all
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]*)(.htm)$ index.php?mact=ListIt,cntnt01,default,0&cntnt01itemid=$1&cntnt01returnid=62 [NC,L]
If you didn't want to hard code the page to use as the template you could use a rewrite rule with something like this...
Code: Select all
RewriteRule ^([0-9]*)/([0-9]*)(.htm)$ index.php?mact=ListIt,cntnt01,default,0&cntnt01itemid=$1&cntnt01returnid=$2 [NC,L]
the first INT passed would be used for the ListIt item_id and the second one passed would be used for the page content_id.
What I actually did here was to just add one line to the existing .htaccess file in my ROOT directory. I don't like having a bunch of extra folders on my server. Right before this line:
Code: Select all
RewriteRule ^(.+)(.htm)$ index.php?page=$1 [QSA]
I added my rewrite rule like this:
Code: Select all
RewriteRule ^listit/([0-9]*)(.htm)$ index.php?mact=ListIt,cntnt01,default,0&cntnt01itemid=$1&cntnt01returnid=62 [NC,L]
Summary Index
For this just add some <a href=""> tags to a new summary template, maybe something like...
Code: Select all
{foreach from=$items item=item}
<div class="item">
<a href="weeklyspecials/{$item.item_id}.htm">{$item.title|cms_escape}</a>
</div><!-- item -->
{/foreach}