<?php

/**
 *--------------------------------------
 * loga:ar_list
 *--------------------------------------
 * @project		: loga
 * @author		: cblee
 * @created		: 2016-07-11
 * @copyright	: (c)2016 AsThis
 *--------------------------------------
 */
defined('PFA_PATH') or exit('Access Denied');

class TagLogaArList {
	public function get_tagStr($a) {
		$aid = 'aid';
		$orderby = 'orderby';
		$offset = 0;
		$row = 10;
		$key = 'k';
		$as = 'item';

		$where = "	\$where = array();\r\n";
		$where .= "	\$where['__ARTICLE_REVIEW__.ar_status'] = array('EQ', 1);\r\n";

		/* article id */
		if(isset($a['aid']) and !empty($a['aid'])) {
			if(strpos($a['aid'], '$')) {
				$where .= "	if(!empty(".substr($a['aid'], 2, -2).")) {\r\n";
				$where .= "		\$where['__ARTICLE_REVIEW__.article_id'] = array('IN', '{$a['aid']}');\r\n";
				$where .= "	}\r\n";
			}
			else {
				$where .= "	\$where['__ARTICLE_REVIEW__.article_id'] = array('IN', '{$a['aid']}');\r\n";
			}
			$aid = $a['aid'];
		}

		/* order by */
		if(isset($a['orderby']) and !empty($a['orderby'])) {
			if(strpos($a['orderby'], '$')) {
				$order = "'.(!empty(".substr($a['orderby'], 2, -2).") ? '`{$a['orderby']}`' : '`ar_add_time`').'";
			}
			else {
				$order = "`{$a['orderby']}`";
			}
			if(isset($a['order']) and !empty($a['order'])) {
				$order .= " {$a['order']}";
				$orderby = $a['orderby'].'_'.$a['order'];
			}
			else {
				$orderby = $a['orderby'].'_order';
			}
		}
		if(empty($order)) {
			$order = '`ar_add_time` DESC';
		}

		/* limit start row */
		if(isset($a['offset']) and !empty($a['offset'])) {
			if(strpos($a['offset'], '$')) {
				$offset = "'.(!empty(".substr($a['offset'], 2, -2).") ? '{$a['offset']}' : '{$offset}').'";
			}
			else {
				$offset = $a['offset'];
			}
		}

		/* row */
		if(isset($a['row']) and !empty($a['row'])) {
			if(strpos($a['row'], '$')) {
				$row = "'.(!empty(".substr($a['row'], 2, -2).") ? '{$a['row']}' : '{$row}').'";
			}
			else {
				$row = $a['row'];
			}
		}

		/* key */
		if(isset($a['key']) and !empty($a['key'])) {
			if(strpos($a['key'], '$')) {
				$key = "'.(!empty(".substr($a['key'], 2, -2).") ? '{$a['key']}' : '{$key}').'";
			}
			else {
				$key = $a['key'];
			}
		}

		/* as */
		if(isset($a['as']) and !empty($a['as'])) {
			if(strpos($a['as'], '$')) {
				$as = "'.(!empty(".substr($a['as'], 2, -2).") ? '{$a['as']}' : '{$as}').'";
			}
			else {
				$as = $a['as'];
			}
		}

		$str = "<?php\r\n";
		$str .= "\$var_arl = LANG_NAME.'_article_review_list_{$aid}_{$orderby}_{$offset}_{$row}';\r\n";
		$str .= "\$\$var_arl = S('_list/_'.ltrim(\$var_arl, '_'), '', null, array('temp' => TEMP_PATH.D_S.'home'));\r\n";
		$str .= "if(empty(\$\$var_arl)) {\r\n";
		$str .= $where;
		$str .= "	\$\$var_arl = M('ArticleReview')->get_reviewList(\$where, '{$order}', '{$offset},{$row}');\r\n";
		/* expire */
		if(isset($a['expire']) and !empty($a['expire'])) {
			if(strpos($a['expire'], '$')) {
				$expire = "'.(!empty(".substr($a['expire'], 2, -2).") ? '{$a['expire']}' : '{$expire}').'";
			}
			else {
				$expire = $a['expire'];
			}
			$str .= "	S('_list/_'.ltrim(\$var_arl, '_'), \$\$var_arl, '{$expire}', array('temp' => TEMP_PATH.D_S.'home'));\r\n";
		}
		else {
			$str .= "	S('_list/_'.ltrim(\$var_arl, '_'), \$\$var_arl, null, array('temp' => TEMP_PATH.D_S.'home'));\r\n";
		}
		$str .= "}\r\n";
		$str .= "if(\$\$var_arl) : foreach(\$\$var_arl as \${$key} => \${$as}): \r\n";
		$str .= "?>\r\n";
		return $str;
	}

	public function get_tagEndStr() {
		$str = "<?php endforeach; endif; ?>\r\n";
		return $str;
	}
}

?>