Skip to content

Instantly share code, notes, and snippets.

@kamera25
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamera25/f3aac1fded7a3494cb04 to your computer and use it in GitHub Desktop.
Save kamera25/f3aac1fded7a3494cb04 to your computer and use it in GitHub Desktop.
regular.php の仮リファクタリング
<?php
class Helper_Shift_Regular{
// 該当時間の勤務スタッフ数を求める
public static function regular_work_staff_count($regular_shift_day_id ,$shift_type) {
if($shift_type == 0){
$result = DB::select('*')
->from('regular_user')
->where('regular_day_id', $regular_shift_day_id)
->where('edited_shift_type', 'in', array(1,2,3))
->execute();
echo count($result);
}else{
$result = DB::select('*')
->from('regular_user')
->where_open()
->where('regular_day_id', $regular_shift_day_id)
->and_where('edited_shift_type', $shift_type)
->where_close()
->or_where_open()
->where('regular_day_id', $regular_shift_day_id)
->and_where('edited_shift_type', 3)
->or_where_close()
->execute();
echo count($result);
}
}
//////////////////////////////////////////////////////////////////////
// 該当勤務日の合計勤務時間を求める
public static function regular_work_time_count($regular_shift_day_id) {
$morning = regular_work_time_count_as_type( $regular_shift_day_id, 1);
$afternoon = regular_work_time_count_as_type( $regular_shift_day_id, 2);
$full = regular_work_time_count_as_type( $regular_shift_day_id, 3);
put_shift_time( $morning, $afternoon, $full);
}
private static function regular_work_time_count_as_type($regular_shift_day_id, $shift_type){
return DB::select('*')
->from('regular_user')
->where('regular_day_id', $regular_shift_day_id)
->and_where('edited_shift_type', $shift_type)
->execute();
}
//////////////////////////////////////////////////////////////////////
// 当該レギュラーシフトの勤務形態をテーブルタグで出力する
public static function regular_work_type_for_table($regular_work_type){
if ($regular_work_type == 1) {
echo "<td>午前勤務</td><td>10:00 ~ 13:00</td><td>3:00</td><td bgcolor = 'deepskyblue'></td><td></td>";
}elseif ($regular_work_type == 2) {
echo "<td>午後勤務</td><td>13:00 ~ 17:00</td><td>4:00</td><td></td><td bgcolor = 'deepskyblue'></td>";
}elseif ($regular_work_type == 3) {
echo "<td>フル勤務</td><td>10:00 ~ 17:00</td><td>6:00</td><td colspan='2' bgcolor = 'deepskyblue'></td>";
}
}
//////////////////////////////////////////////////////////////////////
// 当該レギュラーシフトグループの特定ユーザの希望勤務日数を求める
public static function request_work_day_count($regular_id, $user_id){
get_work_day_count($regular_id, $user_id, 'request_shift_type');
}
// 当該レギュラーシフトグループの特定ユーザの確定勤務日数を求める
public static function deside_work_day_count($regular_id, $user_id){
get_work_day_count($regular_id, $user_id, 'edited_shift_type');
}
private static function get_work_day_count($regular_id, $user_id, $request_type){
$regular_day_id = DB::select('id')->from('regular_day')->where('regular_id', $regular_id);
$work_day = DB::select('*')->from('regular_user')
->where('user_id', $user_id)
->and_where($request_type, 'in', array(1,2,3))
->and_where('regular_day_id', 'in', $regular_day_id)
->execute();
echo count($work_day);
}
//////////////////////////////////////////////////////////////////////
// 当該レギュラーシフトグループの特定ユーザの希望勤務時間を求める
public static function request_work_time_count($regular_id, $user_id){
get_work_time_count($regular_id, $user_id, 'request_shift_type');
}
// 当該レギュラーシフトグループの特定ユーザの確定勤務時間を求める
public static function deside_work_time_count($regular_id, $user_id){
get_work_time_count($regular_id, $user_id, 'edited_shift_type');
}
private static function get_work_time_count($regular_id, $user_id, $request_type){
$regular_day_id = DB::select('id')->from('regular_day')->where('regular_id', $regular_id);
$morning = get_work_time_count_as_type( $regular_day_id, $user_id, $request_type, 1);
$afternoon = get_work_time_count_as_type($regular_day_id, $user_id, $request_type, 2);
$full = get_work_time_count_as_type( $regular_day_id, $user_id, $request_type, 3);
put_shift_time( $morning, $afternoon, $full);
}
private static function get_work_time_count_as_type($regular_day_id, $user_id, $request_type, $shift_type){
return DB::select('*')->from('regular_user')
->where('user_id', $user_id)
->and_where($request_type, 3)
->and_where('regular_day_id', 'in', $regular_day_id)
->execute();
}
//////////////////////////////////////////////////////////////////////
// 当該レギュラーシフトグループの希望勤務時間の合計を求める
public static function request_regular_group_total_work_time($regular_id){
get_regular_group_work_time($regular_id, 'request_shift_type');
}
// 当該レギュラーシフトグループの確定勤務時間の合計を求める
public static function deside_regular_group_total_work_time($regular_id){
get_regular_group_work_time($regular_id, 'edited_shift_type');
}
private static function get_regular_group_work_time($regular_id, $request_type){
$regular_day_id = DB::select('id')->from('regular_day')->where('regular_id', $regular_id);
$morning = get_regular_group_work_time_as_type( $regular_day_id, $request_type, 1);
$afternoon = get_regular_group_work_time_as_type( $regular_day_id, $request_type, 2);
$full = get_regular_group_work_time_as_type( $regular_day_id, $request_type, 3);
put_shift_time( $morning, $afternoon, $full);
}
private static function get_regular_group_work_time_as_type( $regular_day_id, $request_type, $shift_type){
return DB::select('*')
->from('regular_user')
->where('regular_day_id', 'in', $regular_day_id)
->and_where($request_type, $shift_type)
->execute();
}
//////////////////////////////////////////////////////////////////////
private static function put_shift_time( $morning, $afternoon, $full){
echo count($morning)*3 + count($afternoon) * 4 + count($full) * 6;
}
//////////////////////////////////////////////////////////////////////
// 当該レギュラーシフトグループにおいて特定ユーザが編集ロックされているか調べる
public static function user_shifts_lock($regular_id, $user_id){
$regular_day_id = DB::select('id')->from('regular_day')->where('regular_id', $regular_id);
$query = DB::select('*')
->from('regular_user')
->where('user_id', $user_id)
->and_where('regular_day_id', 'in', $regular_day_id)
->and_where('condition', 1)
->execute();
return count($query)>0;
}
// 特定ユーザの申請が編集ロックされているか調べる
public static function user_shift_lock($regular_user_id){
$regular_user = Model_Regular_User::find($regular_user_id);
return $regular_user->condition == "1";
}
// 当該シフトの状態を出力する
public static function shift_condition($condition) {
if ($condition == 1) {
echo "申請受付中";
}elseif ($condition == 2) {
echo "編成中";
}elseif ($condition == 3) {
echo "確定";
}
}
public static function shift_condition_color($condition) {
if ($condition == 1) {
echo "";
}elseif ($condition == 2) {
echo "uk-alert-danger";
}elseif ($condition == 3) {
echo "uk-alert-success";
}
}
public static function shift_table($regular_id, $user_id){
$regular_day_ids = DB::select('id')->from('regular_day')->where('regular_id', $regular_id)->execute();
foreach ($regular_day_ids as $regular_day_id) {
$user_shift = DB::select('edited_shift_type')
->from('regular_user')
->where('regular_day_id', $regular_day_id)
->and_where('user_id', $user_id)
->execute();
if($user_shift[0]["edited_shift_type"] == "1"){
echo "<td style=\"background-color: #a9f5a9;\"><i class=\"fa fa-sun-o\"></i></td>
<td><i class=\"fa fa-moon-o\"></i></td>";
}elseif($user_shift[0]["edited_shift_type"] == "2"){
echo "<td><i class=\"fa fa-sun-o\"></i></td>
<td style=\"background-color: #a9f5a9;\"><i class=\"fa fa-moon-o\"></i></td>";
}elseif($user_shift[0]["edited_shift_type"] == "3"){
echo "<td style=\"background-color: #a9f5a9;\"><i class=\"fa fa-sun-o\"></i></td>
<td style=\"background-color: #a9f5a9;\"><i class=\"fa fa-moon-o\"></i></td>";
}elseif($user_shift[0]["edited_shift_type"] == "4"){
echo "<td><i class=\"fa fa-sun-o\"></i></td>
<td><i class=\"fa fa-moon-o\"></i></td>";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment