/
KalturaQuizUserEntry.php
116 lines (102 loc) · 2.99 KB
/
KalturaQuizUserEntry.php
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
109
110
111
112
113
114
115
116
<?php
/**
* @package api
* @subpackage objects
*/
class KalturaQuizUserEntry extends KalturaUserEntry{
/**
* @var float
* @readonly
*/
public $score;
/**
* @var string
* @maxLength 1024
*/
public $feedback;
private static $map_between_objects = array
(
"score",
"feedback"
);
public function getMapBetweenObjects ( )
{
return array_merge ( parent::getMapBetweenObjects() , self::$map_between_objects );
}
/**
* KalturaQuizUserEntry constructor.
*/
public function __construct()
{
$this->type = QuizPlugin::getCoreValue('UserEntryType', QuizUserEntryType::QUIZ);
}
public function toObject($object_to_fill = null, $props_to_skip = array())
{
if (is_null($object_to_fill))
{
$object_to_fill = new QuizUserEntry();
}
return parent::toObject($object_to_fill, $props_to_skip);
}
/* (non-PHPdoc)
* @see KalturaObject::toInsertableObject()
*/
public function toInsertableObject ( $object_to_fill = null , $props_to_skip = array() )
{
$object_to_fill = parent::toInsertableObject($object_to_fill, $props_to_skip);
$isAnonymous = false;
$anonKusers = kuserPeer::getKuserByPartnerAndUids(kCurrentContext::getCurrentPartnerId(), array('', 0));
foreach ($anonKusers as $anonKuser)
{
if ($anonKuser->getKuserId() == $object_to_fill->getKuserId())
{
$isAnonymous = true;
}
}
if (!$isAnonymous)
{
$c = new Criteria();
$c->add(UserEntryPeer::KUSER_ID, $object_to_fill->getKuserId());
$c->add(UserEntryPeer::ENTRY_ID, $this->entryId);
$c->add(UserEntryPeer::TYPE, QuizPlugin::getCoreValue('UserEntryType', QuizUserEntryType::QUIZ));
$userEntry = UserEntryPeer::doSelect($c);
if (count($userEntry) > 0)
{
throw new KalturaAPIException(KalturaQuizErrors::QUIZ_USER_ENTRY_ALREADY_EXISTS, $this->entryId);
}
}
return $object_to_fill;
}
public function validateForInsert($propertiesToSkip = array())
{
if(!QuizPlugin::isQuiz($this->entryId))
throw new KalturaAPIException(KalturaQuizErrors::PROVIDED_ENTRY_IS_NOT_A_QUIZ, $this->entryId);
parent::validateForInsert($propertiesToSkip);
$dbEntry = entryPeer::retrieveByPK($this->entryId);
if ($this->feedback != null && !kEntitlementUtils::isEntitledForEditEntry($dbEntry) )
{
KalturaLog::debug('Insert feedback on quiz is allowed only with admin KS or entry owner or co-editor');
throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
}
}
public function validateForUpdate($sourceObject, $propertiesToSkip = array())
{
$dbEntry = entryPeer::retrieveByPK($this->entryId);
if ( !kEntitlementUtils::isEntitledForEditEntry($dbEntry) )
{
KalturaLog::debug('Update quiz allowed only with admin KS or entry owner or co-editor');
throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
}
return parent::validateForUpdate($sourceObject, $propertiesToSkip);
}
protected function validateEntryId()
{
//do nothing - already validating in QuizPlugin::isQuiz
return null;
}
protected function validateUserId()
{
//do nothing
return null;
}
}