Changeset - da3582f113b9
[Not reviewed]
default
0 8 0
Nathan Brink (binki) - 14 years ago 2012-02-19 00:17:20
ohnobinki@ohnopublishing.net
Add support for Sunday, fixing bug #98.
8 files changed with 76 insertions and 45 deletions:
0 comments (0 inline, 0 general)
inc/class.schedule.php
Show inline comments
 
@@ -538,7 +538,8 @@ class Schedule
 
	 * Also, ensure that our $time array is big enough for all of
 
	 * these courses.
 
	 */
 
	$max_day_plusone = 5;
 
	$dayloop_max = 5;
 
        $have_sunday = FALSE;
 
	$have_saturday = FALSE;
 

	
 
	$max_time = (int)max($time);
 
@@ -550,12 +551,11 @@ class Schedule
 
	    for ($si = 0; $si < $course_slot->sections_count(); $si ++)
 
              foreach ($course_slot->section_get_i($si)->getMeetings() as $meeting)
 
		{
 
		  /* Saturdayness */
 
		  /* Sundayness and Saturdayness */
 
                  if ($meeting->getDay(6))
 
                    $have_sunday = TRUE;
 
		  if ($meeting->getDay(5))
 
		    {
 
		      $max_day_plusone = 6;
 
		      $have_saturday = TRUE;
 
		    }
 
                    $have_saturday = TRUE;
 

	
 
		  /* very late / very early classes */
 
		  while ((int)ltrim($meeting->getEndTime(), '0') > $max_time)
 
@@ -580,6 +580,9 @@ class Schedule
 
	if ($sort_time)
 
	  sort($time);
 

	
 
        if ($have_saturday)
 
          $dayloop_max = 6;
 

	
 
        echo '    <div id="regDialog" title="Registration Codes">' . PHP_EOL
 
	  . '      <div id="regDialog-content"></div>' . PHP_EOL
 
	  . '      <p class="regDialog-disclaimer graytext">' . PHP_EOL
 
@@ -679,8 +682,10 @@ class Schedule
 
				
 
	    // Header row
 
	    echo "          <tr>\n"
 
	      . '            <td class="none permuteNum">' . ($i + 1) . "</td>\n"
 
	      . "            <td class=\"day\">Monday</td>\n"
 
              . '            <td class="none permuteNum">' . ($i + 1) . "</td>\n";
 
            if ($have_sunday)
 
              echo '            <td class="day">Sunday</td>' . PHP_EOL;
 
            echo "            <td class=\"day\">Monday</td>\n"
 
	      . "            <td class=\"day\">Tuesday</td>\n"
 
	      . "            <td class=\"day\">Wednesday</td>\n"
 
	      . "            <td class=\"day\">Thursday</td>\n"
 
@@ -690,16 +695,23 @@ class Schedule
 
	    echo "          </tr>\n";
 

	
 
	    $last_meeting = array();
 
	    $rowspan = array(0, 0, 0, 0, 0, 0);
 
	    $rowspan = array(0, 0, 0, 0, 0, 0, 0);
 
	    for($r = 0; $r < (count($time)-1); $r++)
 
	      {
 

	
 
		echo "          <tr>\n"
 
		  . "            <td class=\"time\">" . $this->prettyTime($time[$r]) . "</td>\n";
 

	
 
		/* currently, 0-5 = monday-saturday */
 
		for($dayLoop = 0; $dayLoop < $max_day_plusone; $dayLoop++)
 
		/*
 
                 * Currently, 6, 0-5 = sunday, monday-saturday. We use
 
                 * the trick that -1 through 5 mod 7 is
 
                 * sunday-saturday.
 
                 */
 
		for($dayLoop = $have_sunday ? -1 : 0; $dayLoop < $dayloop_max; $dayLoop = ($dayLoop + 1) % 7)
 
		{
 
                  if ($dayLoop < 0)
 
                    $dayLoop = 6;
 

	
 
		  /* Makes sure there is not a class already in progress */
 
		  if($rowspan[$dayLoop] <= 0)
 
		    {
inc/class.section_meeting.inc
Show inline comments
 
@@ -46,9 +46,10 @@ class SectionMeeting
 
   *   Construct a SectionMeeting.
 
   *
 
   * \param $days
 
   *   A string of single-char day upon which a section meets. Monday
 
   *   is represented with 'm', Tuesday with 't', Wednesday with 'w',
 
   *   Thursday with 'h', and Friday with 'f'.
 
   *   A string of single-char day upon which a section meets. Sunday
 
   *   is represented with 'u', Monday with 'm', Tuesday with 't',
 
   *   Wednesday with 'w', Thursday with 'h', Friday with 'f', and
 
   *   Saturday with 's'.
 
   * \param $time_start
 
   *   The time of day when the section meeting starts. Use
 
   *   school_crawl_time_format() or ensure that the time is formatted
 
@@ -83,11 +84,12 @@ class SectionMeeting
 
   *
 
   * \param $days_str
 
   *   The days of the week in a string format. One char per
 
   *   day. Mon-Sat is represented with 'm', 't', 'w', 'h', 'f', 's'.
 
   *   day. Sun-Sat is represented with 'u', 'm', 't', 'w', 'h', 'f',
 
   *   's'.
 
   */
 
  private function days_set($days_str)
 
  {
 
    $this->days = array(0 => FALSE, 1 => FALSE, 2 => FALSE, 3 => FALSE, 4 => FALSE, 5 => FALSE);
 
    $this->days = array(0 => FALSE, 1 => FALSE, 2 => FALSE, 3 => FALSE, 4 => FALSE, 5 => FALSE, 6 => FALSE);
 

	
 
    $days_str_strlen = strlen($days_str);
 
    for ($i = 0; $i < $days_str_strlen; $i ++)
 
@@ -102,9 +104,11 @@ class SectionMeeting
 
   */
 
  private static function day_atoi($day_c)
 
  {
 
    static $day_atoi = array('m' => 0, 't' => 1, 'w' => 2, 'h' => 3, 'f' => 4, 's' => 5,
 
			     'M' => 0, 'T' => 1, 'W' => 2, 'H' => 3, 'F' => 4, 'S' => 5,
 
			      0  => 0,  1  => 1,  2  => 2,  3  => 3,  4  => 4,  5  => 5);
 
    static $day_atoi = array(
 
      'm' => 0, 't' => 1, 'w' => 2, 'h' => 3, 'f' => 4, 's' => 5, 'u' => 6,
 
      'M' => 0, 'T' => 1, 'W' => 2, 'H' => 3, 'F' => 4, 'S' => 5, 'U' => 6,
 
      0  => 0,  1  => 1,  2  => 2,  3  => 3,  4  => 4,  5  => 5, 6 => 6,
 
    );
 

	
 
    return $day_atoi[$day_c];
 
  }
 
@@ -218,7 +222,7 @@ class SectionMeeting
 
     * times. But if they don't both meet on the same day at least
 
     * once, they don't conflict.
 
     */
 
    for ($day = 0; $day < 6; $day ++)
 
    for ($day = 0; $day < 7; $day ++)
 
      {
 
	if ($this->getDay($day) && $that->getDay($day))
 
	  return TRUE;
 
@@ -242,7 +246,7 @@ class SectionMeeting
 
   */
 
  public function to_json_array()
 
  {
 
    static $daymap = array(0 => 'm', 1 => 't', 2 => 'w', 3 => 'h', 4 => 'f', 5 => 's');
 
    static $daymap = array(0 => 'm', 1 => 't', 2 => 'w', 3 => 'h', 4 => 'f', 5 => 's', 6 => 'u');
 

	
 
    $json_array = array(
 
			'time_start' => $this->time_start,
 
@@ -253,7 +257,7 @@ class SectionMeeting
 
			'type' => $this->type,
 
			);
 

	
 
    for ($day = 0; $day < 6; $day ++)
 
    for ($day = 0; $day < 7; $day ++)
 
      $json_array['days'][$daymap[$day]] = $this->getDay($day);
 

	
 
    return $json_array;
inc/school.crawl.inc
Show inline comments
 
@@ -165,14 +165,14 @@ function school_crawl_gmmktime(array $tm
 
 *   simplicity. One-char representations are supported, however, but
 
 *   use 'm', 't', 'w', 'h', 'f' to distinguish Thursday and
 
 *   Tuesday. 'r' may also be used for Thursday.). Case does not
 
 *   matter. 's' is for Saturday, based on CCBCMD.
 
 *   matter. 's' is for Saturday, based on CCBCMD. 'u' is for Sunday.
 
 * \return
 
 *   slate_permutate's strange internal days representation.
 
 */
 
function school_crawl_days_format(array $school_crawl_log, $days)
 
{
 
  static $daymap_1 = array('m' => 'm', 't' => 't', 'w' => 'w', 'h' => 'h', 'r' => 'h', 'f' => 'f', 's' => 's');
 
  static $daymap_2 = array('th' => 'h');
 
  static $daymap_1 = array('u' => 'u', 'm' => 'm', 't' => 't', 'w' => 'w', 'h' => 'h', 'r' => 'h', 'f' => 'f', 's' => 's');
 
  static $daymap_2 = array('su' => 'u', 'th' => 'h');
 

	
 
  $my_days = array();
 
  foreach ($days as $day)
input.php
Show inline comments
 
@@ -313,6 +313,7 @@ if (!empty($_REQUEST['selectsemester']))
 
	  <col />
 
	  <col />
 
	  <col />
 
	  <col class="sunday<?php if (school_has_auto($inputPage->get_school())) echo ' collapsed';?>" />
 
	  <col />
 
	  <col />
 
	  <col />
 
@@ -329,12 +330,13 @@ if (!empty($_REQUEST['selectsemester']))
 
          <td class="center">Prof</td>
 
          <td class="center">Start Time</td>
 
          <td class="center">End Time</td>
 
	  <td class="center">Su</td>
 
          <td class="center">M</td>
 
          <td class="center">Tu</td>
 
          <td class="center">W</td>
 
          <td class="center">Th</td>
 
          <td class="center">F</td>
 
	  <td class="center">S</td>
 
	  <td class="center">Sa</td>
 
          <td class="center"></td>
 
          <td class="center"></td>
 
        </tr>
 
@@ -381,7 +383,8 @@ function input_course_js(Course $course,
 
	    . json_encode($section->getSynonym()) . ', '
 
	    . json_encode($meeting->getStartTime()) . ', '
 
	    . json_encode($meeting->getEndTime()) . ', '
 
	    . json_encode(array('m' => $meeting->getDay(0), 't' => $meeting->getDay(1), 'w' => $meeting->getDay(2), 'h' => $meeting->getDay(3), 'f' => $meeting->getDay(4),
 
	    . json_encode(array('u' => $meeting->getDay(6), 'm' => $meeting->getDay(0), 't' => $meeting->getDay(1),
 
				'w' => $meeting->getDay(2), 'h' => $meeting->getDay(3), 'f' => $meeting->getDay(4),
 
				's' => $meeting->getDay(5))) . ', '
 
	    . json_encode($meeting->instructor_get()) . ', '
 
	    . json_encode($meeting->getLocation()) . ', '
process.php
Show inline comments
 
@@ -31,16 +31,16 @@ function arrayToDays($array, $mode = 'nu
 
	switch($mode)
 
	  {
 
		case 'short':
 
			$days = array('Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat');
 
		  $days = array('Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun');
 
			break;
 
		case 'long':
 
			$days = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
 
		  $days = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
 
			break;
 
		case 'num':
 
			$days = array('1','2','3','4','5');
 
		  $days = array('1','2','3','4','5', '6');
 
			break;
 
	  case 'alpha':
 
	    $days = array('m', 't', 'w', 'h', 'f', 's');
 
	    $days = array('m', 't', 'w', 'h', 'f', 's', 'u');
 
	    break;
 
		default:
 
			$outString = 'Invalid mode passed to arrayToDays()!';
 
@@ -55,13 +55,21 @@ function arrayToDays($array, $mode = 'nu
 
					$outString .= ', ';
 
			}
 
		}
 
		/*
 
		 * Sunday is last in the array format (our input, the
 
		 * array indices used on the input.php page) but first
 
		 * in good/real formats:
 
		 */
 
		if (isset($array[$i]) && $array[$i] == $key)
 
		    $outString = $days[$i] . ($pretty ? ', ' : '') . $outString;
 

	
 
		if($pretty){
 
			$outString = substr($outString,0,strlen($outString) - 2); // Remove last comma and space
 
			$outString = substr($outString,0, strrpos( $outString, ' ')) . ' and' . substr($outString, strrpos( $outString, ' '), strlen($outString));
 
		}
 
	}
 
	else {
 
		for($i=0; $i < 6; $i++)
 
		for($i=0; $i < 7; $i++)
 
			if(isset($array[$i]))
 
				$outString = $days[$i];
 
	}
school.d/hope.crawl.inc
Show inline comments
 
@@ -291,6 +291,8 @@ function hope_crawl_semester(array $scho
 
	    }
 
	}
 

	
 
      if (trim($section_csv[$fields['U']]))
 
	school_crawl_logf($school_crawl_log, 0, "Section %d has sunday.", $synonym);
 
      $days = school_crawl_days_format($school_crawl_log, array_filter(array_slice($section_csv, $fields['M'], 7), '_hope_crawl_days_filter'));
 
      list($time_start, $time_end) = explode('-', $section_csv[$fields['Times']]);
 
      if (strlen($time_start) != 4 || strlen($time_end) != 4)
school.d/umich.crawl.inc
Show inline comments
 
@@ -165,7 +165,7 @@ function umich_crawl_semester(array $sch
 
		  'TH' => FALSE,
 
		  'F' => FALSE,
 
		  'S' => FALSE,
 
		  'SU' => FALSE /* OK, we'll have to add Sunday support someday ;-) */,
 
		  'SU' => FALSE,
 
		  'Start Date' => FALSE /* yea! */,
 
		  'End Date' => FALSE /* "12/13/2011" */,
 
		  'Time' => FALSE /* "1230-130PM", "9-1030AM", "1130-1PM" */,
 
@@ -174,12 +174,11 @@ function umich_crawl_semester(array $sch
 
		  'Units' => FALSE /* As in credit hours */,
 
		  );
 
  $ignored_fields = array(
 
			  'Term' => TRUE,
 
			  'Session' => TRUE,
 
			  'Acad Group' => TRUE,
 
			  'Codes' => TRUE,
 
			  'SU' => TRUE,
 
			  );
 
    'Term' => TRUE,
 
    'Session' => TRUE,
 
    'Acad Group' => TRUE,
 
    'Codes' => TRUE,
 
  );
 

	
 
  foreach (str_getcsv($csv[0]) as $col_num => $col_name)
 
    if (isset($fields[$col_name]))
 
@@ -229,7 +228,7 @@ function umich_crawl_semester(array $sch
 
      $credit_hours = (float)$row[$fields['Units']];
 

	
 
      $days = '';
 
      foreach (array('M' => 'm', 'T' => 't', 'W' => 'w', 'TH' => 'h', 'F' => 'f', 'S' => 's')
 
      foreach (array('SU' => 'u', 'M' => 'm', 'T' => 't', 'W' => 'w', 'TH' => 'h', 'F' => 'f', 'S' => 's')
 
	       as $field => $day)
 
	if (strlen(trim($row[$fields[$field]])))
 
	  $days .= $day;
scripts/scheduleInput.js
Show inline comments
 
@@ -200,7 +200,8 @@ function add_section_n(cnum, name, synon
 
	    section_html = section_html + genOptionHtml(etime, prettyTime(etime), etime);
 
    }
 

	
 
    section_html = section_html + '</select></td>\
 
    section_html = section_html + '</select></td>\n\
 
<td class="cbrow"><input type="checkbox" title="Sunday" class="daysRequired" name="postData[' + cnum +'][' + snum + '][days][6]" value="1" ' + (days.u ? 'checked="checked"' : '') + ' /></td>\
 
<td class="cbrow"><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][0]" value="1" ' + (days.m ? 'checked="checked"' : '') + ' /></td>\
 
<td class="cbrow"><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][1]" value="1" ' + (days.t ? 'checked="checked"' : '') + ' /></td>\
 
<td class="cbrow"><input type="checkbox" class="daysRequired" name="postData[' + cnum + '][' + snum + '][days][2]" value="1" ' + (days.w ? 'checked="checked"' : '') + ' /></td>\
 
@@ -244,7 +245,9 @@ function add_section_n(cnum, name, synon
 
    section_tr.find('.section-type-entry').val(type);
 
	section_tr.find('.section-credit-hours-entry').val(credit_hours);
 

	
 
    /* unhide the saturday columns if it's used by autocomplete data */
 
    /* unhide the saturday and sunday columns if they're used by autocomplete data */
 
	if (days.u)
 
		jQuery('#jsrows col.sunday').removeClass('collapsed');
 
    if (days.s)
 
	jQuery('#jsrows col.saturday').removeClass('collapsed');
 

	
 
@@ -254,7 +257,7 @@ function add_section_n(cnum, name, synon
 
}
 
function add_section(cnum)
 
{
 
    var section_i = add_section_n(cnum, '', '', '', '', {m: false, t: false, w: false, h: false, f: false, s: false}, '', '', '', 'default', -1);
 
    var section_i = add_section_n(cnum, '', '', '', '', {}, '', '', '', 'default', -1);
 
    if (cnum == slate_permutate_course_free)
 
	course_free_check(cnum);
 
    return section_i;
 
@@ -340,7 +343,7 @@ function course_add_slot_row(course_i, s
 
    jQuery('tr.class' + course_i + ':last').after(
 
	'<tr class="class' + course_i + ' tr-slot-id ' + safe_css_class('slot-' + slot_id) + extra_classes + '">\n' +
 
	    '  <td><span /></td>\n' +
 
	    '  <td colspan="10"><span class="slot-id-text" /></td>\n' +
 
	    '  <td colspan="11"><span class="slot-id-text" /></td>\n' +
 
	    '  <td colspan="2"><span /></td>\n' +
 
	    '</tr>\n'
 
    );
 
@@ -385,7 +388,7 @@ function add_class_n(course_id, title)
 

	
 
    sectionsOfClass[classNum] = 0; // Initialize at 0
 
    course_ajax_requests[classNum] = false;
 
    jQuery('#jsrows').append('<tr id="tr-course-' + classNum + '" class="class class' + classNum + ' pclass' + classNum + '"><td class="nameTip"><input type="text" id="input-course-' + classNum + '" class="classRequired defText className'+classNum+' className" title="Class Name" name="postData[' + classNum + '][name]" /></td><td colspan="10"><input type="text" name="postData[' + classNum + '][title]" class="inPlace inPlace-enable course-title-entry input-submit-disable" /><span class="course-credit-hours course-credit-hours-' + classNum + '"></span></td><td class="tdInput"><div class="deleteClass"><input type="button" value="Remove" class="gray" /></div></td><td class="none"><button type="button" class="addSection gray">+</button></td></tr>');
 
    jQuery('#jsrows').append('<tr id="tr-course-' + classNum + '" class="class class' + classNum + ' pclass' + classNum + '"><td class="nameTip"><input type="text" id="input-course-' + classNum + '" class="classRequired defText className'+classNum+' className" title="Class Name" name="postData[' + classNum + '][name]" /></td><td colspan="11"><input type="text" name="postData[' + classNum + '][title]" class="inPlace inPlace-enable course-title-entry input-submit-disable" /><span class="course-credit-hours course-credit-hours-' + classNum + '"></span></td><td class="tdInput"><div class="deleteClass"><input type="button" value="Remove" class="gray" /></div></td><td class="none"><button type="button" class="addSection gray">+</button></td></tr>');
 

	
 
		/* store classNum as course_i into the <tr />: */
 
    var tr_course = jQuery('#tr-course-' + classNum);
0 comments (0 inline, 0 general)