本文整理汇总了PHP中Period::setCourseYear方法的典型用法代码示例。如果您正苦于以下问题:PHP Period::setCourseYear方法的具体用法?PHP Period::setCourseYear怎么用?PHP Period::setCourseYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Period
的用法示例。
在下文中一共展示了Period::setCourseYear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actualitza
public function actualitza($courseYear, $date = NULL)
{
$this->logger = sfContext::getInstance()->getLogger();
$this->courseYear = $courseYear;
$this->sessions = array();
$timetableDOM = new simple_html_dom();
//echo $this->courseYear."<br>";
//echo $timetableDOM->load_file($courseYear->getUrlHorari())."<br>";
$timetableDOM = file_get_html($courseYear->getUrlHorari());
if (!($timetableDOM && is_object($timetableDOM) && isset($timetableDOM->nodes))) {
$this->logger->debug("La pàgina HTML és invàlida: " . $this->courseYear);
return -1;
}
// Date of first week is in the first table, second row, second cell.
$firstWeek = $timetableDOM->find('table', 0)->find('tr', 1)->find('td', 1)->plaintext;
$currWeekNum = $this->calculateCurrentWeek($firstWeek, $date);
$this->logger->info('Current week number is ' . $currWeekNum);
$currWeekDOM = $timetableDOM->find('table', $currWeekNum);
if ($date) {
$currWeekStartDate = $this->weekStartDate(new DateTime($date));
} else {
$currWeekStartDate = $this->weekStartDate(new DateTime());
}
$this->deleteWeekSessions($currWeekStartDate->format('d.m.Y H:i:s'));
$this->logger->info("Current week start date is " . $currWeekStartDate->format('d.m.Y H:i:s'));
//echo "////// /////// /////// Current week start date is ". $currWeekStartDate->format('d.m.Y H:i:s');
// Create sessions for each period in the timetable and save them to the database.
$rows = $currWeekDOM->find('tr');
for ($row = 0; $row < sizeof($rows); $row++) {
if ($row > 1) {
$cells = $rows[$row]->find('div');
$period = new Period($cells[0]->plaintext);
$period->setCourseYear($this->courseYear);
$this->logger->info("Start time is " . $period->getStart()->format("H:i:s") . ". End time is " . $period->getEnd()->format("H:i:s"));
for ($cell = 0; $cell < sizeof($cells); $cell++) {
if ($cell > 0) {
// Parse the start/end times for this row's period.
if (trim($cells[$cell]->plaintext) === '') {
$this->logger->debug("Skipping cell [" . $row . "][" . $cell . "], it's empty.");
continue;
}
// Session start date is the week's start date + current day of week. Time is provided in the first cell of each row
$sessionStartDateTime = new DateTime($currWeekStartDate->format('d.m.Y'));
$sessionStartDateTime->add(new DateInterval('P' . strval($cell - 1) . 'D'));
$sessionStartDateTime->setTime($period->getStart()->format('H'), $period->getStart()->format('i'));
$period->setStart($sessionStartDateTime);
$this->logger->debug('SessionStartDateTime is: ' . $sessionStartDateTime->format('d.m.Y H:i:s'));
// Agafem el timestamp de l'hora que acaba la classe i la guardem a la variable period
$sessionEndDateTime = new DateTime($currWeekStartDate->format('d.m.Y'));
$sessionEndDateTime->add(new DateInterval('P' . strval($cell - 1) . 'D'));
$sessionEndDateTime = $sessionEndDateTime->setTime($period->getEnd()->format('H'), $period->getEnd()->format('i'));
$period->setEnd($sessionEndDateTime);
$this->logger->debug('SessionEndDateTime is: ' . $sessionEndDateTime->format('d.m.Y H:i:s'));
//echo "*******LA PRUEBA DEL DELITO: ".$cells[$cell]->plaintext."**********<br>";
// Get the plaintext for the period and insert each line into an array.
$this->logger->debug("Periodinfoarray is: " . var_export($cells[$cell]->plaintext, true), 'err');
$periodInfo = html_entity_decode($cells[$cell]->plaintext, ENT_QUOTES, 'UTF-8');
$periodInfo = Encoding::toUTF8($periodInfo);
$periodInfoArray = explode("\n", $periodInfo);
foreach ($periodInfoArray as $i => $value) {
unset($periodInfoArray[$i]);
$periodInfoArray[] = trim($value);
}
// Re-index the array starting from zero.
$period->setDetails(array_values($periodInfoArray));
$this->logger->debug("Trimmed periodinfoarray is: " . var_export($period->getDetails(), true));
//echo "parsejant<br />";
$this->parseSession($period);
}
}
unset($period);
}
}
}