<?php
namespace app\components;

use Yii;
use app\models\Schoolclass;

class SchoolclassHelper{

	//班级按首字母分组
	public static function ShowXzclassGroups($condition=""){
		$msg = [];
		$letterarr = explode(",", Yii::$app->params["en_letters"]);
		if(empty($condition)){
			$condition = "1=1";
		}
		foreach ($letterarr as $oneletter) {
			$msg[$oneletter] = Schoolclass::find()->select("id,name,firstletter,spelling")->where($condition ." and firstletter='". $oneletter ."'")->orderby("spelling asc")->all();
		}
		$msg["--"] = Schoolclass::find()->select("id,name,firstletter,spelling")->where($condition ." and firstletter=''")->orderby("spelling asc")->all();
		return $msg;
	}

	//显示班级名称
	public static function showClassname($classid){
		$msg = "";
		if(empty($classid) || !is_numeric($classid)){
			return $msg;
		}
		$xzclass = Schoolclass::find()->where("id=". $classid)->one();
		if(!empty($xzclass)){
			$msg = $xzclass->name;
		}
		return $msg;
	}
		
}
?>