<commit_before><?php

class TaShiftsController extends TaController {
	
	public function __construct()
	{
		parent::__construct();
		if (isset($this->user))
			$this->beforeFilter('active:'.$this->user['active']);
	}

	//Method to view shifts for a certain week
	public function getIndex()
	{
		$week = array(
			"Sunday" => array(),
			"Monday" => array(),
			"Tuesday" => array(),
			"Wednesday" => array(),
			"Thursday" => array(),
			"Friday" => array(),
			"Saturday" => array()
		);

		$days = array(
			"Sunday",
			"Monday",
			"Tuesday",
			"Wednesday",
			"Thursday",
			"Friday",
			"Saturday"
		);

		//Check if asked for a different week from the GET request
		if (Input::has('week_start'))
			$week_start = Input::get('week_start');
		else 
		{
			$week_start = time() - (date('w') * 24 * 60 * 60);
			$week_start = date('Y-m-d', $week_start);
		}

		//Compute end of week which is start week plus 6 days
		$week_end = strtotime($week_start) + (6 * 24 * 60 * 60);
		$week_end = date('Y-m-d', $week_end);
		
		//Get all shifts for the TA from start of the week to the end
		$shifts = Auth::user()->TA()->shifts($week_start, $week_end);

		//Get the defined start time of the LC
		$start = Settings::get("availability_start_hour")->value;
		$start = Time::ToNumber($start);
		$time['start'] = $start;

		//Get the defined start time of the LC
		$end = Settings::get("availability_end_hour")->value;
		$end = Time::ToNumber($end);
		$time['end'] = $end;

		//Set up the data of shifts for the view to use
		foreach ($shifts as $shift){
			$day = date("l",strtotime($shift->date));
			//First cell contains all the data for the shift
			$week[$day][$shift->start]['id'] = $shift->id;

			$old = $shift->date < date("Y-m-d", strtotime('today'));
			$passed = $shift->date == date("Y-m-d", strtotime('today')) && $shift->start < Time::toNumber(date("G:i"));
			if( $old || $passed )
				$week[$day][$shift->start]['old'] = true;
			else $week[$day][$shift->start]['old'] = false;

			$week[$day][$shift->start]['mine'] = true;
			$week[$day][$shift->start]['length'] = ($shift->end - $shift->start) / 50;
			//Rest of the cells will be skipped
			for ($i=$shift->start+50; $i < $shift->end; $i+=50)
				$week[$day][$i]['skip'] = 1;
		}

		//Set up the data of free shifts for the view to use, same as the regular shifts
		$shifts = Shift::free(( $week_start > date('Y-m-d')? $week_start : date('Y-m-d') ), $week_end);
		foreach ($shifts as $shift){
			$day = date("l",strtotime($shift->date));
			if ($shift->date != date("Y-m-d") || $shift->start > Time::toNumber(date("G:i")) )
				for ($i=$shift->start; $i < $shift->end; $i+=50){
					if ( ! isset($week[$day][$i]) ){
						$week[$day][$i]['id'] = $shift->id;
						$week[$day][$i]['mine'] = false;
						if (ShiftBid::shift($shift->id, Auth::user()->TA()->id))
							$week[$day][$i]['bid'] = true;
						else $week[$day][$i]['bid'] = false;
						$week[$day][$i]['length'] = ($shift->end - $i) / 50;
						$shift_start = $i;
						for ($i=$i+50; $i < $shift->end; $i+=50)
							if (! isset($week[$day][$i]))
								$week[$day][$i]['skip'] = 1;
							else 
							{
								$week[$day][$shift_start]['length'] = ($i - $shift->start) / 50;
								break;
							}
					}
				}
		}

		//Set the page selected to Shifts
		$this->navbar['Shifts']['active'] = true;

		return View::make('ta/shifts')
					->with('user', $this->user)
					->with('navbar',$this->navbar)
					->with('days', $days)
					->with('week', $week)
					->with('time', $time)
					->with('week_start', $week_start);
	}

	//Method to drop a shift
	public function deleteIndex()
	{
		$shift = Shift::find(Input::get('shift_id'));

		//make sure the shift belongs to the TA
		if ($shift->ta_id == Auth::user()->TA()->id )
		{
			$shift->ta_id = null;
			$shift->save();

			Session::flash('success', "Shift has been dropped.");
		}
		//error message, Shift does not belong to the TA
		else Session::flash('fail', "Shift does not belong to you.");

		return Redirect::to('ta/shifts');
	}

	//Method to make a bid for a shift
	public function putIndex()
	{
		$bid = Input::except('_token','_method');

		$shift = Shift::find($bid['shift_id']);

		
		//Can cover the whole shift<commit_msg>Added place holder notifying other TAs of available shift<commit_after><?php

class TaShiftsController extends TaController {
	
	public function __construct()
	{
		parent::__construct();
		if (isset($this->user))
			$this->beforeFilter('active:'.$this->user['active']);
	}

	//Method to view shifts for a certain week
	public function getIndex()
	{
		$week = array(
			"Sunday" => array(),
			"Monday" => array(),
			"Tuesday" => array(),
			"Wednesday" => array(),
			"Thursday" => array(),
			"Friday" => array(),
			"Saturday" => array()
		);

		$days = array(
			"Sunday",
			"Monday",
			"Tuesday",
			"Wednesday",
			"Thursday",
			"Friday",
			"Saturday"
		);

		//Check if asked for a different week from the GET request
		if (Input::has('week_start'))
			$week_start = Input::get('week_start');
		else 
		{
			$week_start = time() - (date('w') * 24 * 60 * 60);
			$week_start = date('Y-m-d', $week_start);
		}

		//Compute end of week which is start week plus 6 days
		$week_end = strtotime($week_start) + (6 * 24 * 60 * 60);
		$week_end = date('Y-m-d', $week_end);
		
		//Get all shifts for the TA from start of the week to the end
		$shifts = Auth::user()->TA()->shifts($week_start, $week_end);

		//Get the defined start time of the LC
		$start = Settings::get("availability_start_hour")->value;
		$start = Time::ToNumber($start);
		$time['start'] = $start;

		//Get the defined start time of the LC
		$end = Settings::get("availability_end_hour")->value;
		$end = Time::ToNumber($end);
		$time['end'] = $end;

		//Set up the data of shifts for the view to use
		foreach ($shifts as $shift){
			$day = date("l",strtotime($shift->date));
			//First cell contains all the data for the shift
			$week[$day][$shift->start]['id'] = $shift->id;

			$old = $shift->date < date("Y-m-d", strtotime('today'));
			$passed = $shift->date == date("Y-m-d", strtotime('today')) && $shift->start < Time::toNumber(date("G:i"));
			if( $old || $passed )
				$week[$day][$shift->start]['old'] = true;
			else $week[$day][$shift->start]['old'] = false;

			$week[$day][$shift->start]['mine'] = true;
			$week[$day][$shift->start]['length'] = ($shift->end - $shift->start) / 50;
			//Rest of the cells will be skipped
			for ($i=$shift->start+50; $i < $shift->end; $i+=50)
				$week[$day][$i]['skip'] = 1;
		}

		//Set up the data of free shifts for the view to use, same as the regular shifts
		$shifts = Shift::free(( $week_start > date('Y-m-d')? $week_start : date('Y-m-d') ), $week_end);
		foreach ($shifts as $shift){
			$day = date("l",strtotime($shift->date));
			if ($shift->date != date("Y-m-d") || $shift->start > Time::toNumber(date("G:i")) )
				for ($i=$shift->start; $i < $shift->end; $i+=50){
					if ( ! isset($week[$day][$i]) ){
						$week[$day][$i]['id'] = $shift->id;
						$week[$day][$i]['mine'] = false;
						if (ShiftBid::shift($shift->id, Auth::user()->TA()->id))
							$week[$day][$i]['bid'] = true;
						else $week[$day][$i]['bid'] = false;
						$week[$day][$i]['length'] = ($shift->end - $i) / 50;
						$shift_start = $i;
						for ($i=$i+50; $i < $shift->end; $i+=50)
							if (! isset($week[$day][$i]))
								$week[$day][$i]['skip'] = 1;
							else 
							{
								$week[$day][$shift_start]['length'] = ($i - $shift->start) / 50;
								break;
							}
					}
				}
		}

		//Set the page selected to Shifts
		$this->navbar['Shifts']['active'] = true;

		return View::make('ta/shifts')
					->with('user', $this->user)
					->with('navbar',$this->navbar)
					->with('days', $days)
					->with('week', $week)
					->with('time', $time)
					->with('week_start', $week_start);
	}

	//Method to drop a shift
	public function deleteIndex()
	{
		$shift = Shift::find(Input::get('shift_id'));

		//make sure the shift belongs to the TA
		if ($shift->ta_id == Auth::user()->TA()->id )
		{
			$shift->ta_id = null;
			$shift->save();

			Session::flash('success', "Shift has been dropped.");

			/* * * * * * * * * * * * * * * * * * * * * * * * *
			 *												 *
			 *			Logic to let other TAs know			 *
			 *												 *
			 * * * * * * * * * * * * * * * * * * * * * * * * */
		}
		//error message, Shift does not belong to the TA
		else Session::flash('fail', "Shift does not belong to you.");

		return Redirect::to('ta/shifts');
	}

	//Method to make a bid for a shift
	public function putIndex()
	{
		$bid = Input::except('_token','_method');

		$shift = Shift::find($bid['shift_id']);

		
		//Can cover the whole shift
{'fraction_non_alphanumeric': 0.22363112391930837, 'fraction_numerical': 0.007377521613832853, 'mean_word_length': 3.2239532619279454, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5510597', 'n_tokens_mistral': 3746, 'n_tokens_neox': 3033, 'n_words': 749}