Exemplo n.º 1
0
 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         common_redirect(common_local_url('all', array('nickname' => $user->nickname)));
         return;
     }
     $noticeid = $this->trimmed('notice');
     $notice = Notice::staticGet($noticeid);
     $token = $this->trimmed('token-' . $notice->id);
     if (!$token || $token != common_session_token()) {
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $gradevalue = $this->trimmed('value');
     $nickname = $user->nickname;
     $exist = Grades::getNoticeGrade($noticeid, $nickname);
     if ($exist != '?') {
         Grades::updateNotice(array('noticeid' => $noticeid, 'grade' => $gradevalue, 'userid' => $nickname));
     } else {
         Grades::register(array('userid' => $nickname, 'noticeid' => $noticeid, 'grade' => $gradevalue));
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('application/xml,text/xml;charset=utf-8');
         $this->elementStart('head');
         $this->element('title', null, _('Disfavor favorite'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->element('p');
         $this->elementEnd('body');
         $this->elementEnd('html');
     }
 }
Exemplo n.º 2
0
 * @author   Alvaro Ortego <*****@*****.**>
 *
 */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$shortoptions = 'n';
$longoptions = array('noticeid=');
$helptext = <<<END_OF_REGISTERUSER_HELP
grade.php [options]
read grades associated to a notice

  -n --noticeid id of the notice to grade

END_OF_REGISTERUSER_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
require_once INSTALLDIR . '/local/plugins/Grades/classes/Grades.php';
$noticeid = get_option_value('n', 'noticeid');
if (empty($noticeid)) {
    print "Must provide a  notice id.\n";
    exit(1);
}
try {
    $notice = Notice::staticGet('notice', $noticeid);
    if (empty($notice)) {
        throw new Exception("A notice with id '{$noticeid}' must exists.");
    }
    print 'Current grade is :' . Grades::getNoticeGrade($noticeid) . ' ';
} catch (Exception $e) {
    print $e->getMessage() . "\n";
    print $e->getTraceAsString();
    exit(1);
}
Exemplo n.º 3
0
 function onEndShowNoticeItem($args)
 {
     $user = common_current_user();
     if (!empty($user)) {
         if ($user->hasRole('grader')) {
             // Si la noticia NO es de un profesor, entonces se puede puntuar.
             if (!$args->notice->getProfile()->getUser()->hasRole('grader')) {
                 $noticeid = $args->notice->id;
                 $nickname = $user->nickname;
                 $userid = $user->id;
                 // Si puede puntuar (porque es grader en el grupo del tweet)
                 if (Grades::getValidGrader($noticeid, $userid)) {
                     $gradevalue = Grades::getNoticeGrade($noticeid, $nickname);
                     if ($gradevalue == '?') {
                         $args->out->elementStart('div', array('class' => 'notice-grades'));
                     } else {
                         if ($gradevalue != '?') {
                             $args->out->elementStart('div', array('id' => 'div-grades-hidden-' . $noticeid, 'class' => 'notice-grades-hidden'));
                         }
                     }
                     $this->showNumbers($args, 0);
                     $this->showNumbers($args, 1);
                     $this->showNumbers($args, 2);
                     $this->showNumbers($args, 3);
                     $args->out->elementEnd('div');
                 }
             }
         }
     }
     return true;
 }