-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQuizResultButtonHelper.php
More file actions
108 lines (100 loc) · 3.02 KB
/
QuizResultButtonHelper.php
File metadata and controls
108 lines (100 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* Quizzes App Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('AppHelper', 'View/Helper');
/**
* Quizzes ResultButton Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @package NetCommons\Quizzes\View\Helper
*/
class QuizResultButtonHelper extends AppHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'NetCommons.NetCommonsHtml',
'Workflow.Workflow',
'Quizzes.QuizGradeLink',
'Html'
);
/**
* getResultButtons 成績ボタン表示
* 基本的に常に表示される
* 回答期間じゃなくても成績はいつでも見られるようにする
* まだ回答してなくて見に行っても、データがないだけだから
*
* @param array $quiz 小テスト
* @param array $options option
* @return string
*/
public function getResultButtons($quiz, $options = array()) {
//
// 成績ボタン
// (not editor)でかつ
// 小テスト自体が公開状態にないまたはまだ回答日がきてないときは表示しない
// これでいくと一般が作成したときの小テスト、承認待ちのあいだは見に行けなくなってしまう
// なので、やはりEditableかどうかに判断を変更することにした
$canGrade = $this->QuizGradeLink->canGrade($quiz);
$canEdit = $this->Workflow->canEdit('Quiz', $quiz);
if (! $canEdit &&
($quiz['Quiz']['status'] != WorkflowComponent::STATUS_PUBLISHED ||
$quiz['Quiz']['period_range_stat'] == QuizzesComponent::QUIZ_PERIOD_STAT_BEFORE)) {
return '';
}
$key = $quiz['Quiz']['key'];
// 編集できる人かどうかで見に行くアクションが異なる
// 総合情報(index)は公開権限の人しか見ることができません
if ($canGrade) {
$action = 'index';
} else {
$action = 'view';
}
list($title, $icon, $btnClass) = $this->_getBtnAttributes($options);
$url = NetCommonsUrl::actionUrl(array(
'controller' => 'quiz_result',
'action' => $action,
Current::read('Block.id'),
$key,
'frame_id' => Current::read('Frame.id'),
));
$html = $this->NetCommonsHtml->link($icon . $title,
$url, array(
'class' => $btnClass,
'escape' => false
));
return $html;
}
/**
* _getBtnAttributes ボタン属性整理作成
*
* @param array $options option
* @return array
*/
protected function _getBtnAttributes($options) {
$btnClass = 'btn btn-default quiz-listbtn';
if (isset($options['class'])) {
$btnClass = 'btn btn-' . $options['class'];
}
if (isset($options['size'])) {
$btnClass .= ' btn-' . $options['size'];
}
$title = '';
if (isset($options['title'])) {
$title = $options['title'];
}
$icon = '';
if (isset($options['icon'])) {
$icon = '<span class="glyphicon glyphicon-' . $options['icon'] . '" aria-hidden="true"></span>';
}
return array($title, $icon, $btnClass);
}
}