Documentation

Below you will find documentation on how to use our software. This contains easy-to-use steps by step guides with helpful screenshots on how to configure and get the best results.
 

Categories

Chapter 3: Item Type

In the item.php file, we define our class as follows:

class ARKContextsMyCCKItem extends ARKContextsBase
{
	//Rest of the code goes here…
}

We call the class ARKContextsMyCCKItem and extend the ARKContextsBase class,  similar to what we did with the category type.

Remember the class name has to follow this rule: ARKContexts + [COMPONENT NAME/Context Name] + [Type].

So, for the Item type, for our MyCCK component the class name will be ARKContextsMyCCKItem.

So the whole code for the class, similar to the category class, is as follows:

class ARKContextsMyCCKItem extends ARKContextsBase
{
	public function __construct($id)
	{
		$this->table = 	JTable::getInstance('item','MyCCK');
		$this->table->load($id);
		parent::__construct($id);
	}	


    public function get()
	{
		if($this->id == null)
			return parent::get();	
		

		$this->table->articletext = $this->table->introtext;

		if (!empty($this->table->fulltext))
		{
			$this->table->articletext .= '<hr id="system-readmore" />' . $this->table->fulltext;
		}
	
		return parent::get();	
	}
	
	
	
	public function triggerContentPlugins($rawText)
	{
		
		$item = new stdclass;
					
		$text = '';
		
		if (isset($rawText))
		{
			$pattern = '#<hr\s+id=("|\')system-readmore("|\')\s*\/*>#i';
			$tagPos = preg_match($pattern, $rawText);
			
			if ($tagPos == 0)
			{
				
				$text = $rawText;
			}
			else
			{
				list ($text, $rawText) = preg_split($pattern, $rawText, 2);
				$text = $text.$rawText;
			}
		}

		$item->text = $text;
		$params = new JObject;
		$params->set('inline',false);
		$dispatcher	= JEventDispatcher::getInstance();
		JPluginHelper::importPlugin('content');
		$dispatcher->trigger('onContentPrepare', array ('com_mycck.item', &$item, &$params, 0));
			
		return array( 'data'=>$item->text);
	}
			
	public function save($data,$type = 'body')
	{
		if($this->id == null)
			return array( 'title'=>'','data'=>'');	
			
		if($type == 'body')
		{
			$data['articletext'] = base64_decode($data['text']);	
		}
		else	
		{
			$data['title'] = strip_tags($data['title']); 
		}
	
		
		$result = $this->table->save($data);
		//We need to process data as we are sending it back to the client
		
		JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_mycck/models');
		$model = JModelLegacy::getInstance('item','MyCCKModel');
		$item = $model->getItem($this->id);
			
	
		if ($item->params->get('show_intro', '1') == '1')
		{
			$item->text = $item->introtext.' '.$item->fulltext;
		}
		elseif ($item->fulltext)
		{
			$item->text = $item->fulltext;
		}
		else
		{
			$item->text = $item->introtext;
		}
		
		//let's detect if any plugin tags are being used 
		//if so let's inform the system to warn the user
		$message = $this->detectPluginTags($item->text);
		
		$dispatcher	= JEventDispatcher::getInstance();
		JPluginHelper::importPlugin('content');
		$item->params->set('inline',false); //set this so inline plugin does not pick this up
		$dispatcher->trigger('onContentPrepare', array ('com_mycck.item', &$item, &$item->params, 0));
		
		return array( 'title'=>html_entity_decode($item->title),'data'=>$item->text,'message'=>$message);
	}
	
	public function version($versionId,$type)
	{
				
		$historyTable = JTable::getInstance('Contenthistory');
		$historyTable->load($versionId);
		$rowArray = JArrayHelper::fromObject(json_decode($historyTable->version_data));
			
		$item = $this->table;

		$item->bind($rowArray);	
		
		if($type == 'title')
		{
			return array( 'data'=>$item->title);
		}
		$text = '';
				
		$text = $item->introtext;
		if (!empty($item->fulltext))
		{
			$text .= '<hr id="system-readmore" />' . $item->fulltext;
		}
	
	
		return array( 'data'=>$text);
		
	}
}

As you can see in this class, the implementation of the code is similar to what we do in the category one. The constructors in the two are virtually identical: We use them to load up our JTable instance to get the current record from the database for our type.

The following methods, ‘get’, ‘triggerContentPlugins’, ‘save’ are also implemented with similar code logic as in the category class.

Now, in this part, where we go into further detail, we won't go into too much detail again, but only highlight the differences in this class implementation and the category one.

 

WebxSolution Ltd and this site is not affiliated with or endorsed by The Joomla! Project™. Any products and services provided through this site are not supported or warrantied by The Joomla! Project or Open Source Matters, Inc. Use of the Joomla!® name, symbol, logo and related trademarks is permitted under a limited license granted by Open Source Matters, Inc.

Copyright © 2009 - 2018 WebxSolution Ltd
Powered by JoomlaWired

Cron Job Starts