Smarty Help

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Smarty Help

Post by Nullig »

I've not worked with smarty before, so I would appreciate some guidance.

I was trying to write a mod to display my video collection, which is in a MySQL db, and thought I should give it more options to appeal to a wider community. In working on the action.defaultadmin.php I used the company directory mod as a guideline, but I'm kinda stuck and I'm hoping that someone could point me in the right direction to code this properly.

As it stands now, the format of the admin page is wrong, with the tabs appearing below their content. I'm trying to get 3 tabs, the main one, where the data is listed, and two template edit tabs (summary and detail).

Also, how do I paginate the results? The database has 2000 entries and I would like to show only 20 at a time on the admin data list.

Here's the code from action.defaultadmin.php

Code: Select all

<?php
if (!isset($gCms)) exit;

if (! $this->CheckAccess())
	{
	return $this->DisplayErrorPage($id, $params, $returnid,$this->Lang('accessdenied'));
	}

echo $this->StartTabContent();
if ($this->CheckPermission('Add Video'))
{	
	
	echo $this->StartTab('videocollection', $params);
	
	$entryarray = array();
	
	$query = "SELECT * FROM ".cms_db_prefix()."module_video_collector ORDER BY movie_title";
	$dbresult = $db->Execute($query);
	
	$rowclass = 'row1';
	
	while ($dbresult && $row = $dbresult->FetchRow())
	{
		$onerow = new stdClass();
		
		$onerow->id = $row['id'];
		$onerow->movie_title = $row['movie_title'];
		$onerow->movie_year = $row['movie_year'];
		$onerow->IMDB_no = $row['IMDB_no'];
		$onerow->album_no = $row['album_no'];
		$onerow->page_no = $row['page_no'];
		$onerow->no_discs = $row['no_discs'];
		$onerow->scr = $row['scr'];
		
		$onerow->editlink = $this->CreateLink($id, 'editmovie', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/edit.gif', $this->Lang('edit'),'','','systemicon'), array('movieid'=>$row['id']));
		
		$onerow->deletelink = $this->CreateLink($id, 'deletemovie', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/delete.gif', $this->Lang('delete'),'','','systemicon'), array('movieid'=>$row['id']), $this->Lang('areyousure'));
		
		$entryarray[] = $onerow;

		($rowclass=="row1"?$rowclass="row2":$rowclass="row1");
	}
	
	$this->smarty->assign_by_ref('items', $entryarray);
	$this->smarty->assign('itemcount', count($entryarray));
	
	$this->smarty->assign('addlink', $this->CreateLink($id, 'addmovie', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/newfolder.gif', $this->Lang('addmovie'),'','','systemicon'), array(), '', false, false, '') .' '. $this->CreateLink($id, 'addmovie', $returnid, $this->Lang('addmovie'), array(), '', false, false, 'class="pageoptions"'));

	$this->smarty->assign('exportcsv', $this->CreateLink($id, 'exportcsv', $returnid, $this->Lang('exportcsv')));
	$this->smarty->assign('importcsv', $this->CreateLink($id, 'importcsv', $returnid, $this->Lang('importcsv')));
	
	$this->smarty->assign('movietext', $this->Lang('movie'));
	
	#Display template
	echo $this->ProcessTemplate('movielist.tpl');
	
	echo $this->EndTab();
	

	echo $this->StartTab('summarytemplate', $params);
	
	echo $this->CreateFormStart($id, 'updatesummarytemplate');
	
	echo '<p>'.$this->CreateTextArea(false, $id, $this->GetTemplate('displaysummary'), 'templatecontent', 'pagebigtextarea').'</p>';
	
	echo $this->CreateInputSubmit($id, 'submitbutton', $this->Lang('submit'));
	echo $this->CreateInputSubmit($id, 'defaultsbutton', $this->Lang('sysdefaults'), '', '', $this->Lang('restoretodefaultsmsg'));
	
	echo $this->CreateFormEnd();
	
	echo $this->EndTab();

	
	echo $this->StartTab('detailtemplate', $params);
	
	echo $this->CreateFormStart($id, 'updatedetailtemplate');
	
	echo '<p>'.$this->CreateTextArea(false, $id, $this->GetTemplate('displaydetail'), 'templatecontent2', 'pagebigtextarea').'</p>';
	
	echo $this->CreateInputSubmit($id, 'rsssubmitbutton', $this->Lang('submit'));
	echo $this->CreateInputSubmit($id, 'defaultsbutton', $this->Lang('sysdefaults'), '', '', $this->Lang('restoretodefaultsmsg'));
	
	echo $this->CreateFormEnd();
	
	echo $this->EndTab();
}

echo $this->EndTabContent();


$this->smarty->assign('tab_headers',$this->StartTabHeaders().
	$this->SetTabHeader('videocollection',$this->Lang('title_videocollection')).
	$this->SetTabHeader('summarytemplate',$this->Lang('title_summarytemplate')).
	$this->SetTabHeader('detailtemplate',$this->Lang('title_detailtemplate')).
	$this->EndTabHeaders().$this->StartTabContent());

$this->smarty->assign('end_tab',$this->EndTab());

$this->smarty->assign('start_videocollection_tab',$this->StartTab('videocollection'));
$this->smarty->assign('start_summarytemplate_tab',$this->StartTab('summarytemplate'));
$this->smarty->assign('start_detailtemplate_tab',$this->StartTab('detailtemplate'));

echo $this->ProcessTemplate('adminpanel.tpl');

?>
Thanks for any help.

Nullig
cyberman

Re: Smarty Help

Post by cyberman »

Have you made a look at SmartyPaginate?

http://www.phpinsider.com/php/code/SmartyPaginate/
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Smarty Help

Post by calguy1000 »

a) Normally, I create the tab headers first, then the tab contents.
usually, if the tab contents show up before the tabs, it means that something isn't closed correctly.

b) The FLVPlayer module does exactly what you want, you may want to check it out (warning, it requires CGExtensions to be installed first).  It has examples of back end pagination, tabs with permissions, and...  of how to split stuff out to separate files for increased performance.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Re: Smarty Help

Post by Nullig »

Thanks for the link, cyberman,  but I don't see SmartyPaginate.class.php included with CMSMS.

Nullig
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Re: Smarty Help

Post by Nullig »

Thanks, calguy. I'll have a look at it.

Nullig
cyberman

Re: Smarty Help

Post by cyberman »

Nullig wrote: but I don't see SmartyPaginate.class.php included with CMSMS.
SmartyPaginate is a Smarty plugin so you can / should use it like you want. You can use it with or without CMSms - why do you want to reinvent the wheel?

IMHO you are thinking to short if you only wanna use parts they comes with CMSms ...
Post Reply

Return to “Developers Discussion”