<commit_before><?php

class AdminScheduleDayController extends AdminController {

	public function getIndex()
	{
		$day = Input::get('day');
		$start = Settings::get("availability_start_hour")->value;
		$start = Time::ToNumber($start);
		$time['start'] = $start;

		$end = Settings::get("availability_end_hour")->value;
		$end = Time::ToNumber($end);
		$time['end'] = $end;

		$availabilities = Availability::day($day);

		$tas = TA::active();

		$available = array();
		foreach ($availabilities as $availability)
			for ($i=$availability->start; $i < $availability->end; $i+=50)
				$available[$availability->ta_id][$i] = $availability->prefered;

		$this->navbar['Schedule']['active'] = true;

		return View::make('admin/schedule_day')
					->with('user', $this->user)
					->with('navbar', $this->navbar)
					->with('available',$available)
					->with('day',$day)
					->with('tas',$tas)
					->with('time', $time);
	}

	public function postIndex()
	{
		$day = Input::get('day');
		$tas = Input::except(array('_token','day'));

		$shifts = array();
		
		foreach ($tas as $ta_id => $times)
		{
			$start = null;
			$end;
			$ta_id = explode('-', $ta_id)[1];

			foreach ($times as $time => $value)
			{
				if ( $start != null )
				{
					if ($value == 0 || $time != $end )
					{
						$shifts[] = array('ta_id'=>$ta_id,'day'=>$day,'start'=>$start,'end'=>$end);
						$start = null;
					} 
				}

				if ( $value == 1 )
				{
					if ( $start == null )
						$start = $time;
					$end = $time+50;
				}
			}

			if ( $start != null )
				$shifts[] = array('ta_id'=>$ta_id,'day'=>$day,'start'=>$start,'end'=>$end);
		}

		foreach ($shifts as $shift){
			Schedule::create($shift);

			$ta = TA::find($shift['ta_id']);
			$ta->current_hours += ($shift['end'] - $shift['start']) / 50 / 2;
			$ta->save();
		}

		Session::flash('success', "$day's Schedule saved!");
		return Redirect::to('admin/schedule');
	}
}<commit_msg>Added correct display of already assigned shifts<commit_after><?php

class AdminScheduleDayController extends AdminController {

	public function getIndex()
	{
		$day = Input::get('day');
		$start = Settings::get("availability_start_hour")->value;
		$start = Time::ToNumber($start);
		$time['start'] = $start;

		$end = Settings::get("availability_end_hour")->value;
		$end = Time::ToNumber($end);
		$time['end'] = $end;

		$availabilities = Availability::day($day);

		$tas = TA::active();

		$available = array();
		foreach ($availabilities as $availability)
			for ($i=$availability->start; $i < $availability->end; $i+=50)
				$available[$availability->ta_id][$i] = $availability->prefered;

		$schedule = Schedule::day($day);
		$assigned = array();
		foreach ($schedule as $shift)
			for ($i=$shift->start; $i < $shift->end; $i+=50)
				$assigned[$shift->ta_id][$i] = 1;

		$this->navbar['Schedule']['active'] = true;

		return View::make('admin/schedule_day')
					->with('user', $this->user)
					->with('navbar', $this->navbar)
					->with('available',$available)
					->with('assigned', $assigned)
					->with('day',$day)
					->with('tas',$tas)
					->with('time', $time);
	}

	public function postIndex()
	{
		$day = Input::get('day');
		$tas = Input::except(array('_token','day'));

		$shifts = array();
		
		foreach ($tas as $ta_id => $times)
		{
			$start = null;
			$end;
			$ta_id = explode('-', $ta_id)[1];

			foreach ($times as $time => $value)
			{
				if ( $start != null )
				{
					if ($value == 0 || $time != $end )
					{
						$shifts[] = array('ta_id'=>$ta_id,'day'=>$day,'start'=>$start,'end'=>$end);
						$start = null;
					} 
				}

				if ( $value == 1 )
				{
					if ( $start == null )
						$start = $time;
					$end = $time+50;
				}
			}

			if ( $start != null )
				$shifts[] = array('ta_id'=>$ta_id,'day'=>$day,'start'=>$start,'end'=>$end);
		}

		$old_shifts = Schedule::day($day);
		foreach ($old_shifts as $shift) {
			$ta = $shift->TA();
			$ta->current_hours -= ($shift->end - $shift->start) / 50 / 2;
			$ta->save();

			$shift->delete();
		}

		foreach ($shifts as $shift){
			Schedule::create($shift);

			$ta = TA::find($shift['ta_id']);
			$ta->current_hours += ($shift['end'] - $shift['start']) / 50 / 2;
			$ta->save();
		}

		Session::flash('success', "$day's Schedule saved!");
		return Redirect::to('admin/schedule');
	}
}
{'fraction_non_alphanumeric': 0.23332558679990703, 'fraction_numerical': 0.006042296072507553, 'mean_word_length': 3.5496828752642706, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '816582', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1514, 'n_words': 284}