static function isGrader($userid, $groupid) { $qry = 'SELECT gg.userid' . ' FROM grades_group gg' . ' where gg.userid=' . $userid . ' and gg.groupid =' . $groupid; $grGroup = new Gradesgroup(); $grGroup->query($qry); if ($grGroup->fetch()) { $result = true; } else { $result = false; } $grGroup->free(); return $result; }
/** * Make user an admin * * @return void */ function makeGrader() { if (!$this->profile->hasRole('grader')) { $this->profile->grantRole('grader'); } if (!$this->profile->hasRole('deleter')) { $this->profile->grantRole('deleter'); } $result = Gradesgroup::vincularGrupo($this->profile->id, $this->group->id); if (!$result) { $this->clientError(sprintf(_('Ha habido un error al vincular a %1$s con el grupo "%2$s".'), $this->profile->getBestName(), $this->group->getBestName()), 401); } $this->returnToPrevious(); }
function createTask() { $groupsIds = Gradesgroup::getGroups($this->user->id); $groups = User_group::multiGet('id', $groupsIds)->fetchAll(); if (empty($groups)) { $this->element('p', 'error', 'No tiene ningún grupo asociado.'); } else { foreach ($groups as $group) { $this->elementStart('div', array('id' => 'div-group-task-' . $group->id, 'class' => 'group-task-grader')); $this->element('h2', null, strtoupper($group->getBestName())); // Comprobamos si la tarea de ese día para ese grupo ya está creada. $result = Task_Grader::checkTask($this->user->id, $group->id); // Creamos el form para ese grupo. $form = new InitForm($this, $group->id, $result); $form->show(); $this->element('p', null, 'Fecha: ' . strftime('%d-%m-%Y')); // Cogemos el histórico de tareas de ese grupo y ese profesor. $historical = Task_Grader::getHistorical($this->user->id, $group->id); $this->elementStart('div', array('class' => 'wrapper-group-historical')); // Creamos el título del histórico y un enlace para expandirlo. $this->elementStart('a', array('class' => 'task-show-historical', 'onclick' => 'showHistorical(' . $group->id . ');')); $this->raw('Histórico de tareas <span class="show-historical">▸</span>'); $this->elementEnd('a'); $this->elementStart('div', array('id' => 'historical-' . $group->id, 'class' => 'div-group-historical')); if (count($historical) > 0) { foreach ($historical as $taskHistory) { $this->elementStart('div', array('id' => 'task-' . $taskHistory['id'], 'class' => 'div-historical-task')); if ($taskHistory['status'] == 1) { $status = 'Iniciada'; } else { $status = 'Cancelada'; } if ($taskHistory['tag'] == "") { $taskHistory['tag'] = '<Ninguno>'; } $this->elementStart('p'); $this->raw('<span class="historical-bold">' . $status . '</span> ' . '| <span class="historical-bold">Fecha:</span> ' . $taskHistory['cdate'] . ' ' . '| <span class="historical-bold">Tag:</span> ' . $taskHistory['tag'] . ' ' . '| <span class="historical-bold">Completada:</span> ' . $taskHistory['completed'] . '/' . $taskHistory['total']); $this->elementEnd('p'); if ($taskHistory['completed'] == 0) { if ($taskHistory['status'] == 1) { $form = new CancelForm($this, $taskHistory['id']); $form->show(); } else { $form = new ReopenForm($this, $taskHistory['id']); $form->show(); } } $this->elementEnd('div'); } } else { $this->element('p', null, 'Todavía no ha iniciado ninguna tarea.'); } $this->elementEnd('div'); $this->elementEnd('div'); $this->element('p', 'task-underline'); $this->elementEnd('div'); } } }
try { if ($profile->hasRole('grader')) { print "Fallo. Ya era grader.\n"; } else { $profile->grantRole($role); print "OK\n"; } print "Granting role '{$role2}' to user '{$profile->nickname}' ({$profile->id})..."; if ($profile->hasRole('deleter')) { print "Fallo. Ya era deleter.\n"; } else { $profile->grantRole($role2); print "OK\n"; } print "Vinculando usuario '{$profile->nickname}' con Grupo '{$lgroup->nickname}' ({$lgroup->group_id})..."; $group = User_group::staticGet('id', $lgroup->group_id); if (!$profile->isMember($group)) { $profile->joinGroup($group, true); } if (!Gradesgroup::isGrader($profile->id, $lgroup->group_id)) { Gradesgroup::vincularGrupo($profile->id, $lgroup->group_id); print "OK\n"; } else { print "Fallo. Ya estaba vinculado como profesor al grupo.\n"; } } catch (Exception $e) { print "FAIL\n"; print $e->getMessage(); print "\n"; } }
function onEndProfileListItemActionElements($item) { if ($item->action->args['action'] === 'groupmembers') { $user = common_current_user(); if ($user->hasRole('grader') && $user->isAdmin($item->group)) { if ($user->id != $item->profile->id && !Gradesgroup::isGrader($item->profile->id, $item->group->id)) { $args = array('action' => 'groupmembers', 'nickname' => $item->group->nickname); $page = $item->out->arg('page'); if ($page) { $args['param-page'] = $page; } $item->out->elementStart('li', 'entity_make_grader'); $mgf = new MakeGraderForm($item->out, $item->profile, $item->group, $args); $mgf->show(); $item->out->elementEnd('li'); } } } return true; }