当前位置: 首页>>代码示例>>PHP>>正文


PHP Course::getInstanceWithCourseInfo方法代码示例

本文整理汇总了PHP中Course::getInstanceWithCourseInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP Course::getInstanceWithCourseInfo方法的具体用法?PHP Course::getInstanceWithCourseInfo怎么用?PHP Course::getInstanceWithCourseInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Course的用法示例。


在下文中一共展示了Course::getInstanceWithCourseInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getInstanceAuto

 public static function getInstanceAuto(array $course)
 {
     if (!array_key_exists('code', $course) || !array_key_exists('index', $course) || !array_key_exists('year', $course) || !array_key_exists('sem', $course)) {
         return null;
     }
     $code = $course['code'];
     $code = strtoupper($code);
     $index = $course['index'];
     $examTime = array_key_exists('examTime', $course) ? $course['examTime'] : null;
     $info = array('year' => $course['year'], 'sem' => $course['sem']);
     if (!array_key_exists('year', $info) || !array_key_exists('sem', $info)) {
         return null;
     }
     $html = str_get_html(fetch(courseURL($code, $info)));
     if (!$html) {
         return null;
     }
     $table = $html->find('table');
     if (!$table) {
         return null;
     }
     //get course information
     $tr = str_get_html($table[0])->find('tr');
     $InfoBlock = str_get_html($tr[0]);
     $nameAndAuBlock = $InfoBlock->find('b');
     $courseName = $nameAndAuBlock[1]->plaintext;
     $courseAU = $nameAndAuBlock[2]->plaintext;
     //get index block
     $indexBlock = null;
     $line = -1;
     $trBlocks = str_get_html($table[1])->find('tr');
     for ($i = 0; $i < count($trBlocks); $i++) {
         $cols = str_get_html($trBlocks[$i])->find('b');
         for ($j = 0; $j < count($cols); $j++) {
             if ($index == $cols[0]->plaintext) {
                 $indexBlock = $trBlocks[$i];
                 $line = $i;
                 break;
             }
         }
         if ($line != -1) {
             break;
         }
     }
     if ($line == -1) {
         return null;
     }
     //create a course instance
     $c = array('code' => $code, 'index' => $index, 'name' => $courseName, 'au' => $courseAU, 'examTime' => $examTime, 'lessons' => array());
     $trs = array();
     array_push($trs, $trBlocks[$line]);
     $line++;
     while (TRUE) {
         if ($line >= count($trBlocks)) {
             break;
         }
         $cols = str_get_html($trBlocks[$line])->find('b');
         $first = $cols[0]->plaintext;
         if ($first != '') {
             break;
         }
         array_push($trs, $trBlocks[$line]);
         $line++;
     }
     foreach ($trs as $value) {
         $lessonInfo = str_get_html($value)->find('b');
         if (!$lessonInfo) {
             return null;
         }
         $times = explode('-', $lessonInfo[4]->plaintext);
         if (!$times) {
             return null;
         }
         $lesson = new Lesson(array('type' => $lessonInfo[1]->plaintext, 'group' => $lessonInfo[2]->plaintext, 'time' => new LessonTime(array('wkDay' => $lessonInfo[3]->plaintext, 'startTime' => intval($times[0]), 'endTime' => intval($times[1]))), 'venue' => $lessonInfo[5]->plaintext, 'remark' => $lessonInfo[6]->plaintext));
         array_push($c['lessons'], $lesson);
     }
     return Course::getInstanceWithCourseInfo($c);
 }
开发者ID:hubandbob,项目名称:Course-Cal-php,代码行数:78,代码来源:Course.Class.php

示例2: Lesson

<?php

require_once '../Course.Class.php';
echo 'Test Lesson Class: </br>';
$lesson = new Lesson(array('type' => 'LEC', 'group' => 'FS2', 'time' => new LessonTime(array('startTime' => '0830', 'endTime' => '0930', 'wkDay' => 'mon')), 'venue' => 'LT1'));
echo 'Test Case 1: a new lesson created, </br>';
echo $lesson->toString();
echo '</br></br>';
echo 'Test Course Class: </br>';
echo 'Test case 1, getInstanceWithCourseInfo: </br>';
$course = Course::getInstanceWithCourseInfo(array('code' => 'CZ2001', 'index' => '1000', 'name' => 'Shit Course', 'au' => '3', 'lessons' => array($lesson)));
echo $course->toString() . '</br>';
echo 'Test case 2, getInstanceAuto: </br>';
$course = Course::getInstanceAuto(array('code' => 'CZ2001', 'index' => '10733', 'year' => '2013', 'sem' => '1'));
if (!$course) {
    echo 'cannot create an instance.';
} else {
    echo $course->toString();
}
开发者ID:hubandbob,项目名称:Course-Cal-php,代码行数:19,代码来源:test_Course.Class.php

示例3: createCalWithCustomInformation

function createCalWithCustomInformation(array $info)
{
    //check important value
    if (!array_key_exists('year', $info) || !array_key_exists('sem', $info) || !array_key_exists('courses', $info)) {
        return null;
    }
    $mode = array_key_exists('mode', $info) ? $info['mode'] : 'auto';
    $unique_id = array_key_exists('unique_id', $info) ? $info['unique_id'] : rand();
    $TZID = array_key_exists('tz', $info) ? $info['tz'] : 'Asia/Singapore';
    $filename = array_key_exists('filename', $info) ? $info['filename'] : 'Course_Cal_file';
    $year = $info['year'];
    $sem = $info['sem'];
    $courses = $info['courses'];
    if (!is_numeric($year) || !is_numeric($sem)) {
        return null;
    }
    //create ical
    $config = array('unique_id' => $unique_id, 'TZID' => $TZID, 'filename' => $filename);
    $ical = new vcalendar($config);
    //add courses
    foreach ($courses as $course) {
        $c = null;
        if ($mode == 'manual') {
            $c = Course::getInstanceWithCourseInfo($course);
        } else {
            $course['year'] = $info['year'];
            $course['sem'] = $info['sem'];
            $c = Course::getInstanceAuto($course);
        }
        if ($c) {
            setCourseEvent($c, $ical, $info);
        }
    }
    return array('ics' => $ical);
}
开发者ID:hubandbob,项目名称:Course-Cal-php,代码行数:35,代码来源:ical.php


注:本文中的Course::getInstanceWithCourseInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。