<?php

require_once XOOPS_TRUST_PATH . '/libs/xoonips/class/core/ViewTypeText.class.php';
require_once XOOPS_TRUST_PATH . '/libs/xoonips/class/core/BeanFactory.class.php';

class User_ViewTypeAvatar extends Xoonips_ViewTypeText {

	public function setTemplate() {
	    $this->template = $this->dirname . '_viewtype_avatar.html';
	}
	
	public function getInputView($field, $value, $groupLoopId) {
		$avatarBean = Xoonips_BeanFactory::getBean('AvatarBean',$this->dirname,$this->trustDirname);
		$avatarArr = $avatarBean->getAvatarFile();
    	$url = XOOPS_UPLOAD_URL.'/';
	    $url2 = '';
     	foreach ($avatarArr as $key => $listName) {
    		if ($value !== '') {
		    	if ($key == $value) {
			    	$url2 = $url . $value;
		    	}
    		}
    	}
		$fieldName = $this->getFieldName($field, $groupLoopId);
		$this->getXoopsTpl()->assign('viewType', 'input');
		$this->getXoopsTpl()->assign('list', $avatarArr);
		$this->getXoopsTpl()->assign('fieldName', $fieldName);
		$this->getXoopsTpl()->assign('value', $value);
		$this->getXoopsTpl()->assign('url', $url2);
		return $this->getXoopsTpl()->fetch('db:'. $this->template);;
	}
	
	public function getSearchInputView($field, $value, $groupLoopId) {
		$avatarBean = Xoonips_BeanFactory::getBean('AvatarBean', $this->dirname, $this->trustDirname);
		$avatarArr = $avatarBean->getAvatarFile();
		$fieldName = $this->getFieldName($field, $groupLoopId);
		$this->getXoopsTpl()->assign('viewType', 'search');
		$this->getXoopsTpl()->assign('list', $avatarArr);
		$this->getXoopsTpl()->assign('fieldName', $fieldName);
		$this->getXoopsTpl()->assign('value', $value);
		return $this->getXoopsTpl()->fetch('db:'. $this->template);
	}

	public function getDisplayView($field, $value, $groupLoopId) {
   		$fieldName = $this->getFieldName($field, $groupLoopId);
		$this->getXoopsTpl()->assign('viewType', 'confirm');
		$this->getXoopsTpl()->assign('fieldName', $fieldName);
		$this->getXoopsTpl()->assign('value', $value);
		return $this->getXoopsTpl()->fetch('db:'. $this->template);
	}
	
	public function getDetailDisplayView($field, $value, $display) {
   		$this->getXoopsTpl()->assign('viewType', 'detail');
		$this->getXoopsTpl()->assign('value', $value);
		return $this->getXoopsTpl()->fetch('db:'. $this->template);
	}
}

