本文整理汇总了PHP中Course::fromId方法的典型用法代码示例。如果您正苦于以下问题:PHP Course::fromId方法的具体用法?PHP Course::fromId怎么用?PHP Course::fromId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Course
的用法示例。
在下文中一共展示了Course::fromId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
function create()
{
Auth::checkLoggedIn();
$course = Course::fromId(Input::get('courseid'));
if (!$course->canEdit(Auth::getUser())) {
throw new Exception('You are not allowed to create an entry in this course.');
}
$entry = Entry::create(Auth::getUser(), $course, Input::get('title'), Input::get('description'));
if (Input::exists('due_at')) {
$entry->setDueTime(Input::get('due_at'));
}
if (Input::exists('display_at')) {
$entry->setDisplayTime(Input::get('display_at'));
}
if (Input::exists('visible')) {
$entry->setVisible(Input::getBoolean('visible'));
}
View::renderJson($entry->getContext(Auth::getUser()));
}
示例2: remove_student
function remove_student()
{
Auth::checkLoggedIn();
// Get the course and make sure the user can edit it
$course = Course::fromId(Input::get('courseid'));
if (!$course->canEdit(Auth::getUser())) {
throw new Exception('You cannot remove users from this course');
}
// Get the user id to remove
$user = User::fromId(Input::get('userid'));
// Make sure permissions are not being overstepped
if ($course->getCreatorUserId() != Auth::getUser()->getUserId() && !$user->isAdmin() && $user->getUserId() == $course->getCreatorUserId()) {
throw new Exception('You are not allowed to remove the creator from the class.');
}
// Remove the user
$course->removeUser($user);
// Render the new context
View::renderJson($course->getContext(Auth::getUser()));
}
示例3: canEdit
/**
* Determines whether or not a given user can edit this entry.
* @param User $user The user to check permissions for.
* @return boolean
*/
public function canEdit(User $user)
{
$course = Course::fromId($this->getCourseId());
if ($course->canEdit($user)) {
return true;
}
return $user->getUserId() == $this->getCreatorUserId();
}
示例4: getContext
/**
* Returns the context for this answer.
* @return array
*/
public function getContext(User $user)
{
// Build the likes array
$likesUsers = $this->getLikes();
$likes_contexts = array();
foreach ($likesUsers as $like) {
array_push($likes_contexts, $like->getContext($user));
}
// See if the professor has liked this answer
$professorLiked = false;
$course = Course::fromId(Question::fromId($this->getQuestionId())->getCourseId());
foreach ($likesUsers as $curUser) {
if ($course->canEdit($curUser)) {
$professorLiked = true;
break;
}
}
$isProfessor = $course->canEdit(User::fromId($this->getUserId()));
// Return the context
return array('answerid' => $this->getAnswerId(), 'questionid' => $this->getQuestionId(), 'created_at' => $this->getCreationTime(), 'created_by' => User::fromId($this->getUserId())->getContext($user), 'edited' => $this->isEdited(), 'edited_at' => $this->getEditedTime(), 'edited_by' => User::fromId($this->getEditorUserid())->getContext($user), 'text' => $this->getText(), 'can_edit' => $this->canEdit($user), 'has_liked' => $this->hasLiked($user), 'likes' => $likes_contexts, 'professor_liked' => $professorLiked, 'is_professor' => $isProfessor);
}