本文整理汇总了PHP中core_date::get_user_timezone_object方法的典型用法代码示例。如果您正苦于以下问题:PHP core_date::get_user_timezone_object方法的具体用法?PHP core_date::get_user_timezone_object怎么用?PHP core_date::get_user_timezone_object使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_date
的用法示例。
在下文中一共展示了core_date::get_user_timezone_object方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: url_get_variable_values
/**
* Get the parameter values that may be appended to URL
* @param object $url module instance
* @param object $cm
* @param object $course
* @param object $config module config options
* @return array of parameter values
*/
function url_get_variable_values($url, $cm, $course, $config)
{
global $USER, $CFG;
$site = get_site();
$coursecontext = context_course::instance($course->id);
$values = array('courseid' => $course->id, 'coursefullname' => format_string($course->fullname), 'courseshortname' => format_string($course->shortname, true, array('context' => $coursecontext)), 'courseidnumber' => $course->idnumber, 'coursesummary' => $course->summary, 'courseformat' => $course->format, 'lang' => current_language(), 'sitename' => format_string($site->fullname), 'serverurl' => $CFG->wwwroot, 'currenttime' => time(), 'urlinstance' => $url->id, 'urlcmid' => $cm->id, 'urlname' => format_string($url->name), 'urlidnumber' => $cm->idnumber);
if (isloggedin()) {
$values['userid'] = $USER->id;
$values['userusername'] = $USER->username;
$values['useridnumber'] = $USER->idnumber;
$values['userfirstname'] = $USER->firstname;
$values['userlastname'] = $USER->lastname;
$values['userfullname'] = fullname($USER);
$values['useremail'] = $USER->email;
$values['usericq'] = $USER->icq;
$values['userphone1'] = $USER->phone1;
$values['userphone2'] = $USER->phone2;
$values['userinstitution'] = $USER->institution;
$values['userdepartment'] = $USER->department;
$values['useraddress'] = $USER->address;
$values['usercity'] = $USER->city;
$now = new DateTime('now', core_date::get_user_timezone_object());
$values['usertimezone'] = $now->getOffset() / 3600.0;
// Value in hours for BC.
$values['userurl'] = $USER->url;
}
// weak imitation of Single-Sign-On, for backwards compatibility only
// NOTE: login hack is not included in 2.0 any more, new contrib auth plugin
// needs to be createed if somebody needs the old functionality!
if (!empty($config->secretphrase)) {
$values['encryptedcode'] = url_get_encrypted_parameter($url, $config);
}
//hmm, this is pretty fragile and slow, why do we need it here??
if ($config->rolesinparams) {
$coursecontext = context_course::instance($course->id);
$roles = role_fix_names(get_all_roles($coursecontext), $coursecontext, ROLENAME_ALIAS);
foreach ($roles as $role) {
$values['course' . $role->shortname] = $role->localname;
}
}
return $values;
}
示例2: update
/**
* Update or create an event within the database
*
* Pass in a object containing the event properties and this function will
* insert it into the database and deal with any associated files
*
* @see self::create()
* @see self::update()
*
* @param stdClass $data object of event
* @param bool $checkcapability if moodle should check calendar managing capability or not
* @return bool event updated
*/
public function update($data, $checkcapability = true)
{
global $DB, $USER;
foreach ($data as $key => $value) {
$this->properties->{$key} = $value;
}
$this->properties->timemodified = time();
$usingeditor = !empty($this->properties->description) && is_array($this->properties->description);
// Prepare event data.
$eventargs = array('context' => $this->properties->context, 'objectid' => $this->properties->id, 'other' => array('repeatid' => empty($this->properties->repeatid) ? 0 : $this->properties->repeatid, 'timestart' => $this->properties->timestart, 'name' => $this->properties->name));
if (empty($this->properties->id) || $this->properties->id < 1) {
if ($checkcapability) {
if (!calendar_add_event_allowed($this->properties)) {
print_error('nopermissiontoupdatecalendar');
}
}
if ($usingeditor) {
switch ($this->properties->eventtype) {
case 'user':
$this->properties->courseid = 0;
$this->properties->course = 0;
$this->properties->groupid = 0;
$this->properties->userid = $USER->id;
break;
case 'site':
$this->properties->courseid = SITEID;
$this->properties->course = SITEID;
$this->properties->groupid = 0;
$this->properties->userid = $USER->id;
break;
case 'course':
$this->properties->groupid = 0;
$this->properties->userid = $USER->id;
break;
case 'group':
$this->properties->userid = $USER->id;
break;
default:
// Ewww we should NEVER get here, but just incase we do lets
// fail gracefully
$usingeditor = false;
break;
}
// If we are actually using the editor, we recalculate the context because some default values
// were set when calculate_context() was called from the constructor.
if ($usingeditor) {
$this->properties->context = $this->calculate_context($this->properties);
$this->editorcontext = $this->properties->context;
}
$editor = $this->properties->description;
$this->properties->format = $this->properties->description['format'];
$this->properties->description = $this->properties->description['text'];
}
// Insert the event into the database
$this->properties->id = $DB->insert_record('event', $this->properties);
if ($usingeditor) {
$this->properties->description = file_save_draft_area_files($editor['itemid'], $this->editorcontext->id, 'calendar', 'event_description', $this->properties->id, $this->editoroptions, $editor['text'], $this->editoroptions['forcehttps']);
$DB->set_field('event', 'description', $this->properties->description, array('id' => $this->properties->id));
}
// Log the event entry.
$eventargs['objectid'] = $this->properties->id;
$eventargs['context'] = $this->properties->context;
$event = \core\event\calendar_event_created::create($eventargs);
$event->trigger();
$repeatedids = array();
if (!empty($this->properties->repeat)) {
$this->properties->repeatid = $this->properties->id;
$DB->set_field('event', 'repeatid', $this->properties->repeatid, array('id' => $this->properties->id));
$eventcopy = clone $this->properties;
unset($eventcopy->id);
$timestart = new DateTime('@' . $eventcopy->timestart);
$timestart->setTimezone(core_date::get_user_timezone_object());
for ($i = 1; $i < $eventcopy->repeats; $i++) {
$timestart->add(new DateInterval('P7D'));
$eventcopy->timestart = $timestart->getTimestamp();
// Get the event id for the log record.
$eventcopyid = $DB->insert_record('event', $eventcopy);
// If the context has been set delete all associated files
if ($usingeditor) {
$fs = get_file_storage();
$files = $fs->get_area_files($this->editorcontext->id, 'calendar', 'event_description', $this->properties->id);
foreach ($files as $file) {
$fs->create_file_from_storedfile(array('itemid' => $eventcopyid), $file);
}
}
$repeatedids[] = $eventcopyid;
// Trigger an event.
//.........这里部分代码省略.........
示例3: usertime
/**
* Given a GMT timestamp (seconds since epoch), offsets it by
* the timezone. eg 3pm in India is 3pm GMT - 7 * 3600 seconds
*
* NOTE: this function does not include DST properly,
* you should use the PHP date stuff instead!
*
* @package core
* @category time
* @param int $date Timestamp in GMT
* @param float|int|string $timezone user timezone
* @return int
*/
function usertime($date, $timezone = 99)
{
$userdate = new DateTime('@' . $date);
$userdate->setTimezone(core_date::get_user_timezone_object($timezone));
$dst = dst_offset_on($date, $timezone);
return $date - $userdate->getOffset() + $dst;
}
示例4: test_get_user_timezone_object
public function test_get_user_timezone_object()
{
global $CFG, $USER;
$this->resetAfterTest();
$this->setTimezone('Pacific/Auckland');
$CFG->forcetimezone = '99';
$zones = core_date::get_list_of_timezones();
foreach ($zones as $zone) {
$USER->timezone = $zone;
$tz = core_date::get_user_timezone_object();
$this->assertInstanceOf('DateTimeZone', $tz);
$this->assertSame($zone, $tz->getName());
}
}