/** * Displays a list of all contests. * * @since 0.1 * * @param array $contests */ protected function displayContestsTable(array $contests) { $user = $this->getUser(); $out = $this->getOutput(); $out->addHTML(Html::element('h2', array('class' => 'contests-title'), wfMsg('contest-special-existing'))); $out->addHTML(Xml::openElement('table', array('class' => 'wikitable sortable contests-table'))); $headers = array(Html::element('th', array(), wfMsg('contest-special-name')), Html::element('th', array(), wfMsg('contest-special-status')), Html::element('th', array(), wfMsg('contest-special-submissioncount'))); $headers[] = Html::element('th', array('class' => 'unsortable')); $out->addHTML('<thead><tr>' . implode('', $headers) . '</tr></thead>'); $out->addHTML('<tbody>'); foreach ($contests as $contest) { /** * @var $contest Contest */ $fields = array(); if ($user->isAllowed('contestant')) { $name = Html::element('a', array('href' => SpecialPage::getTitleFor('ContestWelcome', $contest->getField('name'))->getLocalURL()), $contest->getField('name')); } else { $name = $contest->getField('name'); } $fields[] = Html::rawElement('td', array('data-sort-value' => $contest->getField('name')), $name); $fields[] = Html::element('td', array('data-sort-value' => $contest->getStatus()), Contest::getStatusMessage($contest->getStatus())); $fields[] = Html::element('td', array(), $this->getLanguage()->formatNum($contest->getField('submission_count'))); $links = array(); if ($user->isAllowed('contestjudge')) { $links[] = Html::element('a', array('href' => SpecialPage::getTitleFor('Contest', $contest->getField('name'))->getLocalURL()), wfMsg('contest-nav-contest')); } if ($user->isAllowed('contestadmin')) { $links[] = Html::element('a', array('href' => SpecialPage::getTitleFor('EditContest', $contest->getField('name'))->getLocalURL()), wfMsg('contest-special-edit')); if (ContestSettings::get('contestDeletionEnabled')) { $links[] = Html::element('a', array('href' => '#', 'class' => 'contest-delete', 'data-contest-id' => $contest->getId(), 'data-contest-token' => $this->getUser()->editToken('deletecontest' . $contest->getId())), wfMsg('contest-special-delete')); } } $links[] = Html::element('a', array('href' => SpecialPage::getTitleFor('ContestWelcome', $contest->getField('name'))->getLocalURL()), wfMsg('contest-nav-contestwelcome')); if ($user->isAllowed('contestant')) { $links[] = Html::element('a', array('href' => SpecialPage::getTitleFor('ContestSignup', $contest->getField('name'))->getLocalURL()), wfMsg('contest-nav-contestsignup')); } $fields[] = Html::rawElement('td', array(), $this->getLanguage()->pipeList($links)); $out->addHTML('<tr>' . implode('', $fields) . '</tr>'); } $out->addHTML('</tbody>'); $out->addHTML('</table>'); $out->addModules('contest.special.contests'); }
/** * Gets the summary data. * * @since 0.1 * * @param Contest $contest * * @return array */ protected function getSummaryData(Contest $contest) { $stats = array(); $stats['name'] = $contest->getField('name'); $stats['status'] = Contest::getStatusMessage($contest->getStatus()); $stats['submissioncount'] = $this->getLanguage()->formatNum($contest->getField('submission_count')); $stats['end'] = wfMsgExt($contest->getDaysLeft() < 0 ? 'contest-contest-days-ago' : 'contest-contest-days-left', 'parsemag', $this->getLanguage()->timeanddate($contest->getField('end'), true), $this->getLanguage()->formatNum(abs($contest->getDaysLeft()))); return $stats; }