New Controller

megrain
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 17 Nov 2009, 15:18
Location: South Africa
Contact:

New Controller

Post by megrain »

Hi All
I have been working on a plugin to allow for easy export to virtuemart via a interface in the backend, but currently I can't get it to use the new controller file I created it allways uses the phocagallery.php controller. I created the following files & folders in administration/components/com_phocagallery/

views/phocagalleryvm[folder]/view.html.php[file]
views/phocagalleryvm[folder]/tmpl[folder]/default.php[file]
models/phocagalleryvm.php[file]
controllers/phocagalleryvm.php[file]

each of the files I copied from phocagallery to get the same layout as the file view in the backend.
Below you will find the code of each of the files I changed.

view.html.php

Code: Select all

<?php
/*
 * @package Joomla 1.5
 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * @component Phoca Gallery
 * @copyright Copyright (C) Jan Pavelka www.phoca.cz
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
defined('_JEXEC') or die();
jimport( 'joomla.application.component.view' );

class PhocaGalleryCpViewPhocaGalleryVm extends JView
{

	var $_context 	= 'com_phocagallery.phocagalleryvm';
	
	function display($tpl = null) {
		global $mainframe;
		$uri		=& JFactory::getURI();
		$document	=& JFactory::getDocument();
		$db		    =& JFactory::getDBO();
		$tmpl		= array();
		
		JHTML::stylesheet( 'phocagallery.css', 'administrator/components/com_phocagallery/assets/' );
		$document->addCustomTag("<!--[if lt IE 8]>\n<link rel=\"stylesheet\" href=\"../administrator/components/com_phocagallery/assets/phocagalleryieall.css\" type=\"text/css\" />\n<![endif]-->");
		
		$link = 'index.php?option=com_phocagallery&view=phocagalleryd&tmpl=component';
		
		JHTML::_('behavior.modal', 'a.modal-button');

		$params 				= JComponentHelper::getParams('com_phocagallery');
		$admin_modal_box_width 	= $params->get( 'admin_modal_box_width', 680 );
		$admin_modal_box_height = $params->get( 'admin_modal_box_height', 520 );
		
		$tmpl['enablethumbcreation']		= $params->get('enable_thumb_creation', 1 );
		$tmpl['enablethumbcreationstatus'] 	= PhocaGalleryRenderAdmin::renderThumbnailCreationStatus((int)$tmpl['enablethumbcreation']);
	
		// Button
		$button = new JObject();
		$button->set('modal', true);
		$button->set('link', $link);
		$button->set('text', JText::_('Image'));
		$button->set('name', 'image');
		$button->set('modalname', 'modal-button');
		$button->set('options', "{handler: 'iframe', size: {x: ".$admin_modal_box_width.", y: ".$admin_modal_box_height."}}");

		//Filter
		//$context			= 'com_phocagallery.phocagalleryvm.list.';
		
		$filter_state		= $mainframe->getUserStateFromRequest( $this->_context.'.filter_state',	'filter_state', '',	'word' );
		$filter_catid		= $mainframe->getUserStateFromRequest( $this->_context.'.filter_catid',	'filter_catid',	0, 'int' );
		$filter_order		= $mainframe->getUserStateFromRequest( $this->_context.'.filter_order',	'filter_order',	'a.ordering', 'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $this->_context.'.filter_order_Dir',	'filter_order_Dir',	'',	'word' );
		$search				= $mainframe->getUserStateFromRequest( $this->_context.'.search', 'search', '',	'string' );
		$search				= JString::strtolower( $search );

		// Get data from the model
		$items					= & $this->get( 'Data');
		$total					= & $this->get( 'Total');
		$tmpl['pagination'] 	= & $this->get( 'Pagination' );
		
		// build list of categories
		$javascript 	= 'class="inputbox" size="1" onchange="submitform( );"';
		
		$query = 'SELECT a.title AS text, a.id AS value, a.parent_id as parentid'
		. ' FROM #__phocagallery_categories AS a'
	//	. ' WHERE a.published = 1'
		. ' ORDER BY a.ordering';
		$db->setQuery( $query );
		$phocagalleryvm = $db->loadObjectList();

		$tree = array();
		$text = '';
		$tree = PhocaGalleryRenderAdmin::CategoryTreeOption($phocagallery, $tree, 0, $text, -1);
		array_unshift($tree, JHTML::_('select.option', '0', '- '.JText::_('Select Category').' -', 'value', 'text'));
		$lists['catid'] = JHTML::_( 'select.genericlist', $tree, 'filter_catid',  $javascript , 'value', 'text', $filter_catid );
		//-----------------------------------------------------------------------
	
		// state filter
		$lists['state']		= JHTML::_('grid.state',  $filter_state );

		// table ordering
		$lists['order_Dir'] = $filter_order_Dir;
		$lists['order'] 	= $filter_order;

		// search filter
		$lists['search']	= $search;
		
		$this->assignRef('tmpl',		$tmpl);
		$this->assignRef('button',		$button);
		$this->assignRef('user',		JFactory::getUser());
		$this->assignRef('lists',		$lists);
		$this->assignRef('items',		$items);
		$this->assignRef('request_url',	$uri->toString());
		
		parent::display($tpl);
		$this->_setToolbar();
	}
	
	function _setToolbar() {
		JToolBarHelper::title(   JText::_( 'Export To Virtuemart' ), 'gallery' );
		JToolBarHelper::customX('export', 'multiple.png', '', JText::_( 'export' ), true);
		JToolBarHelper::preferences('com_phocagallery', '460');
		JToolBarHelper::help( 'screen.phocagallery', true );
	}
		
}
?> 
default.php

Code: Select all

<?php
defined('_JEXEC') or die('Restricted access');
$user 	=& JFactory::getUser();

//Ordering allowed ?
$ordering = ($this->lists['order'] == 'a.ordering');

JHTML::_('behavior.tooltip');
?>

<form action="<?php echo $this->request_url; ?>" method="post" name="adminForm">
	<table>
		<tr>
			<td align="left" width="100%"><?php echo JText::_( 'Filter' ); ?>:
				<input type="text" name="search" id="search" value="<?php echo $this->lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
				<button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
				<button onclick="document.getElementById('search').value='';this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
			</td>
			<td nowrap="nowrap">
				<?php
				echo $this->tmpl['enablethumbcreationstatus'] . ' &nbsp;';
				echo $this->lists['catid'];
				echo $this->lists['state'];
				?>
			</td>
		</tr>
	</table>

	<div id="editcell">
		<table class="adminlist">
			<thead>
				<tr>
					<th width="5"><?php echo JText::_( 'NUM' ); ?></th>
					<th width="5"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" /></th>
					<th class="image" width="70" align="center"><?php echo JText::_( 'Image' ); ?></th>
					<th class="title" width="40%"><?php echo JHTML::_('grid.sort',  'Title', 'a.title', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th width="20%" nowrap="nowrap"><?php echo JHTML::_('grid.sort',  'Filename', 'a.filename', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th width="5%" nowrap="nowrap"><?php echo JHTML::_('grid.sort',  'Virtuemart ID', 'a.vmproductid', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th width="5%" nowrap="nowrap"><?php echo JHTML::_('grid.sort',  'Published', 'a.published', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					<th width="14%" nowrap="nowrap">
						<?php echo JHTML::_('grid.sort',  'Order', 'a.ordering', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						<?php echo JHTML::_('grid.order',  $this->items ); ?></th>
					<th width="15%"  class="title">
						<?php echo JHTML::_('grid.sort',  'Category', 'category', $this->lists['order_Dir'], $this->lists['order'] ); ?></th>
					<th width="5%"><?php echo JHTML::_('grid.sort',  'Rating', 'v.average', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					
					<th width="5%"><?php echo JHTML::_('grid.sort',  'Hits', 'a.hits', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
					
					<th width="1%" nowrap="nowrap"><?php echo JHTML::_('grid.sort',  'ID', 'a.id', $this->lists['order_Dir'], $this->lists['order'] ); ?>
					</th>
				</tr>
			</thead>
			
			<tbody>
				<?php
				$k = 0;
				for ($i=0, $n=count( $this->items ); $i < $n; $i++)
				{
					$row 			= &$this->items[$i];
					$checked 	= JHTML::_('grid.checkedout', $row, $i );
					$published 	= JHTML::_('grid.published', $row, $i );
					$row->cat_link 	= JRoute::_( 'index.php?option=com_phocagallery&controller=phocagalleryc&task=edit&cid[]='. $row->catid );
				?>
				<tr class="<?php echo "row$k"; ?>">
					<td><?php echo $this->tmpl['pagination']->getRowOffset( $i ); ?></td>
					<td><?php echo $checked; ?></td>
					<td align="center" valign="middle">
						<div class="phocagallery-box-file">
							<center>
								<div class="phocagallery-box-file-first">
									<div class="phocagallery-box-file-second">
										<div class="phocagallery-box-file-third">
											<center>
											<?php if (isset ($row->fileoriginalexist) && $row->fileoriginalexist == 1)
											{
											?>
												<a class="<?php echo $this->button->modalname; ?>" title="<?php echo $this->button->text; ?>" href="<?php echo $this->button->link . '&cid[]='.$row->id; ?>" rel="<?php echo $this->button->options; ?>" ><?php echo JHTML::_( 'image', $row->linkthumbnailpath.'?imagesid='.md5(uniqid(time())), ''); ?></a>
											<?php
											}
											else
											{
												echo JHTML::_( 'image.site', 'phoca_thumb_s_no_image.gif', '../administrator/components/com_phocagallery/assets/images/');
											}
											?>
											</center>
										</div>
									</div>
								</div>
							</center>
						</div>
					</td>
					<td>
						<?php
						if (  JTable::isCheckedOut($this->user->get ('id'), $row->checked_out ) ) {
							echo $row->title;
						} else {
						?>
							<!-- <a href="<?php echo $link; ?>" title="<?php echo JText::_( 'Edit Phoca gallery' ); ?>">
								<?php echo $row->title; ?></a>
						<?php
						}
						?>
					</td>
					<td><?php echo $row->filename;?></td>
					<td>
					<?php 
					if ($row->vmproductid == '0') {
						echo '';}
					else {
						echo $row->vmproductid;}
					?>
					</td>
					<td align="center"><?php echo $published;?></td>
					<td class="order">
						<span><?php echo $this->tmpl['pagination']->orderUpIcon( $i, ($row->catid == @$this->items[$i-1]->catid),'orderup', 'Move Up', $ordering ); ?></span>
						<span><?php echo $this->tmpl['pagination']->orderDownIcon( $i, $n, ($row->catid == @$this->items[$i+1]->catid), 'orderdown', 'Move Down', $ordering ); ?></span>
					<?php $disabled = $ordering ?  '' : 'disabled="disabled"'; ?>
						<input type="text" name="order[]" size="5" value="<?php echo $row->ordering;?>" <?php echo $disabled ?> class="text_area" style="text-align: center" />
					</td>
					<td><a href="<?php echo $row->cat_link; ?>" title="<?php echo JText::_( 'Edit Category' ); ?>"><?php echo $row->category; ?></a>
					</td>
					
					<td align="center"><?php
							$voteAvg 		= round(((float)$row->ratingavg / 0.5)) * 0.5;
							$voteAvgWidth	= 16 * $voteAvg;
							echo '<ul class="star-rating-small">'
							.'<li class="current-rating" style="width:'.$voteAvgWidth.'px"></li>'
							.'<li><span class="star1"></span></li>';
					
							for ($ir = 2;$ir < 6;$ir++) {
								echo '<li><span class="stars'.$ir.'"></span></li>';
							}
							echo '</ul>';
						
						?></td>

					<td align="center"><?php echo $row->hits; ?></td>
					
					<td align="center"><?php echo $row->id; ?></td>
				</tr>
				<?php
				$k = 1 - $k;
				}
			?>
			</tbody>
			
			<tfoot>
				<tr>
					<td colspan="12"><?php echo $this->tmpl['pagination']->getListFooter(); ?></td>
				</tr>
			</tfoot>
		</table>
	</div>

<input type="hidden" name="controller" value="phocagallery" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
<input type="hidden" name="filter_order_Dir" value="" />
</form> 
phocagalleryvm.php [models]

Code: Select all

<?php
/*
 * @package Joomla 1.5
 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * @component Phoca Gallery
 * @copyright Copyright (C) Jan Pavelka www.phoca.cz
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
defined('_JEXEC') or die();
jimport('joomla.application.component.model');
jimport( 'joomla.filesystem.folder' );
jimport( 'joomla.filesystem.file' );
phocagalleryimport( 'phocagallery.file.filefolder' );

class PhocaGalleryCpModelPhocaGalleryVm extends JModel
{
	function __construct() {
		parent::__construct();

		global $mainframe;
		
		// Get the pagination request variables
		$limit	= $mainframe->getUserStateFromRequest( $this->_context.'.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
		$limitstart	= $mainframe->getUserStateFromRequest( $this->_context.'.limitstart', 'limitstart',	0, 'int' );
		// In case limit has been changed, adjust limitstart accordingly
		$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
		$this->setState('limit', $limit);
		$this->setState('limitstart', $limitstart);
	}

	function getData() {
		
		//Params
		$params							= &JComponentHelper::getParams( 'com_phocagallery' );
		$pagination_thumbnail_creation 	= $params->get( 'pagination_thumbnail_creation', 0 );
		$clean_thumbnails 				= $params->get( 'clean_thumbnails', 0 );		
		
		if (empty($this->_data)) {
			$query = $this->_buildQuery();
			$this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
		}
		
		//Server doesn't have CPU power
		//we do thumbnail for all images - there is no pagination...
		//or we do thumbanil for only listed images
		if (empty($this->_data_thumbnail)) {	
			if ($pagination_thumbnail_creation == 1) {
				$this->_data_thumbnail = $this->_data;
			} else {
				$query = $this->_buildQueryThumbnail();
				$this->_data_thumbnail = $this->_getList($query);
				
			}
		}

		// - - - - - - - - - - - - - - - - - - - -
		// Check if the file stored in database is on the server. If not please refer to user
		// Get filename from every object there is stored in database	
		// file - abc.img, file_no - folder/abc.img
		// Get folder variables from Helper
		$path 				= PhocaGalleryPath::getPath();
		$origPath 			= $path->image_abs;
		$origPathServer 	= str_replace(DS, '/', $path->image_abs);
		
		//-----------------------------------------
		//Do all thumbnails no limit no pagination
		if (!empty($this->_data_thumbnail)) {
			foreach ($this->_data_thumbnail as $key => $value) {	
				$fileOriginalThumb = PhocaGalleryFile::getFileOriginal($value->filename);
				//Let the user know that the file doesn't exists and delete all thumbnails
				if (JFile::exists($fileOriginalThumb)) {
					
					$refreshUrlThumb = 'index.php?option=com_phocagallery&view=phocagalleryvm';
					$fileThumb = PhocaGalleryFileThumbnail::getOrCreateThumbnail( $value->filename, $refreshUrlThumb, 1, 1, 1);	
				}
			}
		}
		
		$this->_data_thumbnail = null; // delete data to reduce memory
		
		//Only the the site with limitation or pagination...
		if (!empty($this->_data)) {
			foreach ($this->_data as $key => $value) {	
				$fileOriginal = PhocaGalleryFile::getFileOriginal($value->filename);
				//Let the user know that the file doesn't exists and delete all thumbnails
				
				if (!JFile::exists($fileOriginal)) {
					$this->_data[$key]->filename = JText::_( 'Image Filename does not exist' );
					$this->_data[$key]->fileoriginalexist = 0;
				} else {
					//Create thumbnails small, medium, large
					$refresh_url 	= 'index.php?option=com_phocagallery&view=phocagalleryvm';
					$fileThumb 		= PhocaGalleryFileThumbnail::getOrCreateThumbnail($value->filename, $refresh_url, 1, 1, 1);
					
					$this->_data[$key]->linkthumbnailpath 	= $fileThumb['thumb_name_s_no_rel'];
					$this->_data[$key]->fileoriginalexist = 1;	
				}
			}
		}
		
		//Clean Thumbs Folder if there are thumbnail files but not original file
		if ($clean_thumbnails == 1) {
			PhocaGalleryFileFolder::cleanThumbsFolder();
		}
		
		
		return $this->_data;
	}

	function getTotal() {
		if (empty($this->_total)) {
			$query = $this->_buildQuery();
			$this->_total = $this->_getListCount($query);
		}
		return $this->_total;
	}

	function getPagination() {
		if (empty($this->_pagination)) {
			jimport('joomla.html.pagination');
			$this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
		}
		return $this->_pagination;
	}
	

	function _buildQuery() {
		$where		= $this->_buildContentWhere();
		$orderby	= $this->_buildContentOrderBy();

		$query = ' SELECT a.*, cc.title AS category, u.name AS editor, v.average AS ratingavg, vmproductid'
			. ' FROM #__phocagallery AS a '
			. ' LEFT JOIN #__phocagallery_categories AS cc ON cc.id = a.catid '
			. ' LEFT JOIN #__phocagallery_img_votes_statistics AS v ON v.imgid = a.id'
			. ' LEFT JOIN #__users AS u ON u.id = a.checked_out '
			. $where
			. $orderby;
		return $query;
	}
	
	function _buildQueryThumbnail() {
		$queryt = ' SELECT a.filename '
			. ' FROM #__phocagallery AS a ';
		return $queryt;
	}

	function _buildContentOrderBy() {
		global $mainframe;
		$filter_order		= $mainframe->getUserStateFromRequest( $this->_context.'.filter_order',	'filter_order',	'a.ordering', 'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $this->_context.'.filter_order_Dir',	'filter_order_Dir',	'',	'word' );

		if ($filter_order == 'a.ordering'){
			$orderby 	= ' ORDER BY category, a.ordering '.$filter_order_Dir;
		} else {
			$orderby 	= ' ORDER BY '.$filter_order.' '.$filter_order_Dir.' , category, a.ordering ';
		}
		return $orderby;
	}

	function _buildContentWhere() {
		global $mainframe;
		$filter_state		= $mainframe->getUserStateFromRequest( $this->_context.'.filter_state',	'filter_state',	'',	'word' );
		$filter_catid		= $mainframe->getUserStateFromRequest( $this->_context.'.filter_catid',	'filter_catid',	0,	'int' );
		$filter_order		= $mainframe->getUserStateFromRequest( $this->_context.'.filter_order',	'filter_order',	'a.ordering', 'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $this->_context.'.filter_order_Dir',	'filter_order_Dir',	'', 'word' );
		$search				= $mainframe->getUserStateFromRequest( $this->_context.'.search', 'search', '', 'string' );
		$search				= JString::strtolower( $search );

		$where = array();

		if ($filter_catid > 0) {
			$where[] = 'a.catid = '.(int) $filter_catid;
		}
		if ($search) {
			$where[] = 'LOWER(a.title) LIKE '.$this->_db->Quote('%'.$search.'%');
		}
		if ( $filter_state ) {
			if ( $filter_state == 'P' ) {
				$where[] = 'a.published = 1';
			} else if ($filter_state == 'U' ) {
				$where[] = 'a.published = 0';
			}
		}
		$where 		= ( count( $where ) ? ' WHERE '. implode( ' AND ', $where ) : '' );
		return $where;
	}
}
?> 
phocagalleryvm.php [controllers]

Code: Select all

<?php
/*
 * @package Joomla 1.5
 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * @component Phoca Gallery
 * @copyright Copyright (C) Jan Pavelka www.phoca.cz
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

class PhocaGalleryCpControllerPhocaGalleryVm extends PhocaGalleryCpController
{


	function __construct() {

	function export() {
		echo 'you selected the following title '.$record[$id];
	}

	function orderup() {
		$model = $this->getModel( 'phocagalleryvm' );
		$model->move(-1);
		$this->setRedirect( 'index.php?option=com_phocagallery&view=phocagalleryvm' );
	}

	function orderdown() {
		$model = $this->getModel( 'phocagalleryvm' );
		$model->move(1);
		$this->setRedirect( 'index.php?option=com_phocagallery&view=phocagalleryvm' );
	}

	function saveorder() {
		$cid 	= JRequest::getVar( 'cid', array(), 'post', 'array' );
		$order 	= JRequest::getVar( 'order', array(), 'post', 'array' );
		JArrayHelper::toInteger($cid);
		JArrayHelper::toInteger($order);

		$model = $this->getModel( 'phocagalleryvm' );
		$model->saveorder($cid, $order);

		$msg = JText::_( 'New ordering saved' );
		$this->setRedirect( 'index.php?option=com_phocagallery&view=phocagalleryvm', $msg );
	}
}
?>
 
I'm sure it is something small I've missed now. thanks in advance.
regards,
Megrain
megrain
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 17 Nov 2009, 15:18
Location: South Africa
Contact:

Re: New Controller

Post by megrain »

Post Reply