<?php
namespace admin\action;
use \model\tags;
use \model\pro\numidx;
class tagsAction  extends \action
{
	
	/**
	  * @method 取所有tags
	  */
    function getTags()
	{
		$req = \mvc::$req;
		$tags = new tags();
		$data = $tags->getTags();
		$this->successJson($data);
    }

	/**
	  * @method 取所有object tags
	  */
    function getObjTags()
	{
		$req = \mvc::$req;
		$tags = new tags();
		$data = $tags->getObjTags($req['tagType'], $req['mode']);
		$this->successJson($data);
    }
	
	/**
	  * @method 变更某源的标签
	  * @param  type string [必填] TAGS_TYPE 中的值s
	  * @param  tids string [必填] 1,2,3,...  替换模式
	  * @param  value_id int [选填] 数据ID
	  * @author soul
	  */
    function change()
	{
		$req = \mvc::$req;
		$tags = new tags();
		$data = $tags->changeTagsLink($req['type'], 'replace', ['t_id'=>$req['tids'], 'value_id'=>$req['value_id']]);
		$this->successJson($data);
    }


	/**
	  * @method 批量设置数据标签标签
	  * @param  type string [必填] TAGS_TYPE 中的值s
	  * @param  actType string [必填] add | del | replace
	  * @param  tids string [必填] 标签ID 1,4,...
	  * @param  valids int [选填] 数据ID 1,2,3
	  * @author soul
	  */
    function changeAnyTags()
	{
		$req = \mvc::$req;
		
		$setArr = [];
		foreach(explode(',', $req['valids']) as $valid)
		{
			$setArr[] = ['t_id'=>$req['tids'], 'value_id'=>$valid];
		}
		if($req['type'] == 'number')
		{//需要记录变更独立
			$numidx = new numidx();
			$data = $numidx->changeTagsLinkNumber($req['actType'], $setArr);
			$this->successJson($data);
		}
		else if($req['type'] == 'pic'){
			$tags = new tags();
			$data = $tags->changeObjTagsLink($req['table'],$req['type'], $req['actType'], $setArr);
			$this->successJson($data);
		}
		else
		{
			$tags = new tags();
			$data = $tags->changeTagsLink($req['type'], $req['actType'], $setArr);
			$this->successJson($data);
		}
    }
}