View

<?php
class View_Employee_Index extends ViewModel {
	public function view()
	{
		//画面入力値の取得
// 		$per_page = Input::get('per_page', 1);
// 		$keyword  = Input::get('keyword', null);
// 		$offset   = Input::get('offset', null);
// 		$sort     = Input::get('sort', 'id');

		//画面遷移用URLを定義ファイルから取得
		Config::load('define');
		$this->base_url     = Config::get('index_url');
		$this->regist_url = Config::get('regist_url');
		$this->edit_url   = Config::get('edit_url');
		$this->delete_url = Config::get('delete_url');
		$this->js_url= array(
			'http://localhost/fuelphp-1.7.3/public/assets/js/employee/list.js',
			'http://localhost/fuelphp-1.7.3/public/assets/js/employee/detail.js',
		);

		$param = Util_Param::get_postparam();
		$param['per_page'] = 2;//configからもらってくるように変更する
		$param['p'] =Input::get('p');
		//$param['kw'] = '次郎';

		//検索条件が設定されている場合、何も条件を引継がない
// 		if (empty(array_key_exists('kw', $param))){


// 		}


		$query  = Model_Employee::query();
		$query->related('affiliation')->related('position');

		//ワードでの絞り込み
		if(Input::get('kw')){
			$query->where('content', 'LIKE', "%".Input::get('word')."%");
		}
		//ソート(並び順)が指定された場合
		if(Input::get('order_by')){
			$query->order_by(Input::get('order_by'), 'DESC');
		}


// 		//ページネーションObj生成
// 		$pagination = Pagination::forge('employee_pagination', $config);
// 		$this->pagination = $pagination;

		//クエリ実行

		$this->result = $query->where('has_been_deleted', '=', 0)
//		->and_where_open()
// 			->where('family_name','LIKE',"%".$param['kw']."%")
//			->where('given_name','LIKE',"%".$param['kw']."%")
// 			->or_where('family_kana','LIKE',"%".$param['kw']."%")
// 			->or_where('given_kana','LIKE',"%".$param['kw']."%")
//		->and_where_close()
		->rows_limit($param['per_page'])
 		->rows_offset($param['p'])
		->get();

// 		$total = $query::count();
// 		var_dump($total);

// 		// 		//ページネーションの設定
// 		//$count = Model_Employee::count();
// 		$config = array(
// 			//'pagination_url' => 'employee',
// 			'uri_segment' => 'page',//URL上のクエリパラメータの位置
// 			'num_links' => 4,
// 			'per_page' => $per_page,
// 			'total_items' => $total,
// 		);

		//paginationインスタンスの取得
		$this->pagination = Pagination::forge('pagination', [
			//'pagination_url' => Uri::base(false).'posts',
			'uri_segment'    => 'page',
			'per_page'       => $param['per_page'],
			'total_items'    => $query->count() //ここでcountメソッドを実行する
		]);

		var_dump($this->pagination);

		$this->affiliation_string = array();
		foreach($this->result as $row){
			$affiliation_string = null;
			//部
			$affiliation_string .=
			$row->affiliation['dep_name']?
			$row->affiliation['dep_name'].'' : null;
			//課
			$affiliation_string .=
			$row->affiliation['sec_name']?
			$row->affiliation['sec_name'].'' : null;
			//係
			$affiliation_string .=
			$row->affiliation['subsec_name']?
			$row->affiliation['subsec_name'].'' : null;

			$this->affiliation_string[$row->id] = $affiliation_string;
		}

		//部

// 		->where('family_name','LIKE',"%".$param['search']."%")->get();

// 		if(! empty($keyword)){
// 			$query->where('id', $keyword);
// 		}
		//->where('id', $keyword)//ここ、後であいまい検索許容するよう修正
// 		$this->result = $query->order_by($sort, 'desc')
// 		->limit($this->pagination->per_page)
// 		->offset($this->pagination->offset)
// 		->get();

		//値取得
		//$this->result = Model_Employee::query()->get();
		//->limit($this->per_page)
		//->offset($pagination->offset)
		// $this->result = Model_Employee::find('all',
		// 	array(
		// 		'related' => array(
		// 			// リレーションの設定名を指定
		// 			'affiliation',
		// 			'position',
		// 		),
		// 	)
		// );
		//var_dump($this->result);
		//役職
		//部署表示用データ
// 		$affiliation_string = array();
// 		$this->resultarray = array();
// 		foreach($this->result as $row){
// 			$this->resultarray[$row->id]['id'] = $row->id;
// 			$this->resultarray[$row->id]['family_name'] = $row->family_name;
// 			$this->resultarray[$row->id]['given_name'] = $row->given_name;
// 			$this->resultarray[$row->id]['phonetic_of_family_name'] = $row->phonetic_of_family_name;
// 			$this->resultarray[$row->id]['phonetic_of_given_name'] = $row->phonetic_of_given_name;
// 			$this->resultarray[$row->id]['assigned_name'] = $row->position->assigned_name;
// 			//各々の行ー>リレーション名ー>リレ先のカラム名
// 			//var_dump($row->position);
// 			//部
// 			//var_dump($row->affiliation->department_name);
// 			$affiliation_string[] =
// 			$row->affiliation->department_name ?
// 			$row->affiliation->department_name .'部' :
// 			null;
// 			//課
// 			$affiliation_string[] =
// 			$row->affiliation->section_name ?
// 			$row->affiliation->section_name .'課' :
// 			null;
// 			//係
// 			$affiliation_string[] =
// 			$row->affiliation->subsection_name ?
// 			$row->affiliation->subsection_name .'係' :
// 			null;
// 			//var_dump($affiliation_string);
// 			$this->resultarray[$row->id]['affiliation_result'] = implode( '', $affiliation_string);

// 			//初期化
// 			$affiliation_string = array();
// 		}
	}
}






<?php
class View_Employee_Regist extends ViewModel {
	public function view() {
		//VMforgeした際の引数を取得(編集画面用)
		if(!empty($this->emp_data)){
			$param = $this->emp_data;
		}else{
			//入力値取得
			$param = Util_Param::get_postparam();
		}

		//確認画面から戻ってきた際の画面表示
		if(!empty($param)){
			foreach($param as  $key => $value){
				$this->$key = $value;
		//		echo 'key';
		//	var_dump($key);
		//		echo 'value';
		//		var_dump($value);
			}
		}

		$aff_pulldown_list = Model_Affiliation::get_pulldown_list();
//		var_dump($pulldown_list['bu_list']);
		$this->bu_list = $aff_pulldown_list['bu_list'];
		$this->ka_list = $aff_pulldown_list['ka_list'];
		$this->kk_list = $aff_pulldown_list['kk_list'];
		var_dump($this->kk_list);

		$pos_pulldown_list = Model_Position::get_pulldown_list();
		$this->pos_list= $pos_pulldown_list['pos_list'];

		//画面遷移用URL
		Config::load('define');
		$this->mod_url  = Config::get('index_url');
		$this->done_url = Config::get('confirm_url');

		//確認画面からの入力値引継ぎ
		//$params = Util_Param::get_postparam();
		//$result = Input::post();

		//プルダウン表示用
// 		$aff_list = Model_Affiliation::get_pulldown_list();
// 		$pos_list = Model_Position::get_pulldown_list();

		//forで回してこの状態にする
// 		$this->family_name             = Input::post('family_name', null);
// 		$this->given_name              = Input::post('given_name', null);
// 		$this->phonetic_of_family_name = Input::post('phonetic_of_family_name', null);
// 		$this->phonetic_of_given_name  = Input::post('phonetic_of_given_name', null);
// 		$this->bu          			   = Input::post('bu', null);
// 		$this->ka                      = Input::post('ka', null);
// 		$this->kakari                  = Input::post('kakari', null);
// 		$this->yakushoku               = Input::post('yakushoku', null);

		//プルダウン表示用
// 		$bu_obj        = DB::select ( 'department_name' )->from ( 'affiliation' )->distinct(true)->execute();
// 		$ka_obj        = DB::select ( 'section_name' )->from ( 'affiliation' )->distinct(true)->execute();
// 		$kakari_obj    = DB::select ( 'subsection_name' )->from ( 'affiliation' )->distinct(true)->execute();
//

		//Util_Param::get_postparam()から配列で返すようにするので不要
// 		foreach ($bu_obj as $key => $value) {
// 			$bu_list[] =$value;
// 		}
// 		foreach ($ka_obj as $key => $value) {
// 			$ka_list[] =$value;
// 		}
// 		foreach ($kakari_obj as $key => $value) {
// 			$kakari_list[] =$value;
// 		}
// 		foreach ($yakushoku_obj as $key => $value) {
// 			$yakushoku_list[] =$value;
// 		}
// 		$this->bu_list       = $bu_list;
// 		$this->ka_list       = $ka_list;
// 		$this->kakari_list   = $kakari_list;
// 		$this->yakushoku_list= $yakushoku_list;

	}
}














<?php
class View_Employee_Confirm extends ViewModel {
	public function view() {
		//入力値取得
		$param = Util_Param::get_postparam();
		var_dump($param);
		//画面表示
		foreach($param as  $key => $value){
			$this->$key = $value;
		}
		//画面遷移用URLを定義ファイルから取得
		Config::load('define');
		$this->mod_url  = Config::get('regist_url');
		$this->done_url = Config::get('done_url');
	}
}








<?php
class View_Employee_Done extends ViewModel {
	public function view() {

		//画面遷移用URL
		Config::load('define');
		$this->mod_url  = Config::get('index_url');
		$this->done_url = Config::get('regist_url');

		$param = Util_Param::get_postparam();

		//DB登録用に、役職(日本語)→posidに変換
// 		var_dump('pos_name');
//		var_dump($param['pos_name']);
		$posid = Model_Position::pos_name_to_num($param['pos_name']);
		var_dump('posid');
		var_dump($posid);


		// 各部署(日本語)→affidに変換
		$affid =Model_Affiliation::each_aff_to_num($param['dep_name'], $param['sec_name'], $param['subsec_name']);
		var_dump('affid');
		var_dump($affid);
		$insert_param = array();
// 		foreach($param as $key => $value){
// 			array_merge($insert_param,array('$key'=>'$key'));
// 		}
		$insert_param = $param;
		echo 'param';
				var_dump('$param');
				var_dump($param);

		if(! empty($param['id'])){
			//編集の場合
			Util_Model_Employee::save_emp($param, $param['id']);
		}else{
			//新規登録の場合
			Util_Model_Employee::save_emp($param, null);
		}


		if(!empty($param)){
			foreach($param as  $key => $value){
				$this->$key = $value;
								echo 'key';
								var_dump($key);
								echo 'value';
								var_dump($value);
			}
		}

		//$params = Util_Param::get_postparam();
		//forで回してこの状態にする
// 		$result = Input::post();
// 		$this->family_name             = Input::post('family_name', null);
// 		$this->given_name              = Input::post('given_name', null);
// 		$this->phonetic_of_family_name = Input::post('phonetic_of_family_name', null);
// 		$this->phonetic_of_given_name  = Input::post('phonetic_of_given_name', null);
// 		$this->bu             = Input::post('bu', null);
// 		$this->ka             = Input::post('ka', null);
// 		$this->kakari         = Input::post('kakari', null);
// 		$this->yakushoku      = Input::post('yakushoku', null);
	}
}








<?php
class Extension
{
	const BUCHOU = 4;
	const KACHOU = 3;
	const KK     = 2;
	const HIRA   = 1;
	static $ja_to_num = array(
		'buchou' => self::BUCHOU,
		'kachou' => self::KACHOU,
		'KK'     => self::KK,
		'hira'   => self::HIRA,
	);
	static $each_to_affi = array(
		//1課
		'2' => array('3','4','5'),
		//2課
		'6' => array('7','8','9'),
		//3課
		'10' => array('11','12','13'),
	);

	/*
	 * 役職と所属が対応しているか
	 */
    public static function _validation_correct_yakushoku()
    {
    	$bu          			 = Input::post('bu', null);
    	$ka                      = Input::post('ka', null);
    	$kakari                  = Input::post('kakari', null);
    	$yakushoku               = Input::post('yakushoku', null);

    	//役職名(日本語)を役職(id)②変換
    	if (array_key_exists($yakushoku, self::$ja_to_num)){
    		$yakushoku_num  =  self::$ja_to_num[$yakushoku];
    	}
    	//部所属の場合、部長のみOK
    	if(empty($ka)){
    		$result =  ($yakushoku_num == self::BUCHOU) ? true: false;
    		return $result;
    	}
    	//課所属の場合、課長のみOK
    	else if(empty($kakari)){
    		$result =  ($yakushoku_num == self::KACHOU) ? true: false;
    		return $result;
    	}
    	else{
    	//係所属の場合、係長と一般OK
    		if ($yakushoku_num == self::KK or $yakushoku_num == self::HIRA){
				return true;
    		}
    		else{
    			return false;
    		}
    	}
    }

    /*
     * 部長は部に1人だけ
     */
    public static function _validation_only_one_yakushoku()
    {
    	$bu          			 = Input::post('bu', null);
    	$ka                      = Input::post('ka', null);
    	$kakari                  = Input::post('kakari', null);
    	$yakushoku               = Input::post('yakushoku', null);

    	//役職名(日本語)を役職(id)に変換
    	if (array_key_exists($yakushoku, self::$ja_to_num)){
    		$yakushoku_num  =  self::$ja_to_num[$yakushoku];
    	}
    	var_dump($yakushoku_num);
    	//$affiliation = self::$each_to_affi[$bu];
		//各々の所属から所属番号(通しid)への変換
    	$affiliation=  $ka     ? self::$each_to_affi[$bu][$ka] : self::$each_to_affi[$bu];
    	$affiliation = $kakari ? self::$each_to_affi[$bu][$ka][$kakari] : self::$each_to_affi[$bu][$ka];
    	var_dump($affiliation);

//     	$already_exists_row = get_count_column($affiliation, $yakushoku_num);
//     	if(!empty ($already_exists_row)){
// 			return false;
// 		}else {
// 			return true;
// 		}
    }
}




Config

<?php
$base_url = 'http://localhost/fuelphp-1.7.3/public/employee';
return array (
	'index_url'   => $base_url,
	'regist_url'  => $base_url. '/regist',
	'edit_url'    => $base_url. '/edit',
	'confirm_url' => $base_url. '/confirm',
	'done_url'    => $base_url. '/done',
	'delete_url'  => $base_url. '/delete',
);