<?php
// wcf imports
require_once(WCF_DIR.'lib/action/AbstractAction.class.php');

/**
 * ajax tagging
 *
 * @author	Torben Brodt
 * @copyright	2009 TBR Solutions
 * @license	commercial
 * @package	de.easy-coding.wcf.taggingreloaded
 */
class TaggingReloadedSaveAction extends AbstractAction {
	protected $taggableID = 0;
	protected $className = '';
	protected $entryKey = 'entryID';
	protected $entryID = 0;
	protected $languageID = 0;

	/**
	 * @see Action::readParameters()
	 */
	public function readParameters() {
		parent::readParameters();
		
		$this->taggableID = intval($_REQUEST['taggableID']);
		$this->className = $_REQUEST['className'];
		$this->entryID = intval($_REQUEST['entryID']);
		
		if(isset($_REQUEST['entryKey']) $this->entryKey = $_REQUEST['entryKey'];
		if(isset($_REQUEST['languageID']) $this->languageID = intval($_REQUEST['languageID']);
	}
	
	/**
	 * @see Action::execute()
	 */
	public function execute() {
		parent::execute();
		
		$tagged = new $this->className(array(
			$this->entryKey => $this->entryID,
			'taggable' => TagEngine::getInstance()->getTaggable($this->taggable)
		));
		
		if(!($tagged instanceof Tagged)) {
			throw new PermissionDeniedException();
		}
		
		TaggingUtil::save($userid. $tags, $tagged, $this->languageID);
		
		$this->executed();
	}
}
?>
