add Achievement condition ?qrcode? to trigger Achievements by scanning a QR-code (implements #126)
This commit is contained in:
parent
3939def456
commit
28c914a926
12 changed files with 319 additions and 35 deletions
|
|
@ -693,6 +693,10 @@
|
|||
case 'achievement':
|
||||
$conditions = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
|
||||
break;
|
||||
// QR-Code conditions
|
||||
case 'qrcode':
|
||||
$conditions = $this->Achievements->getAchievementConditionsQrcode($achievement['id']);
|
||||
break;
|
||||
}
|
||||
|
||||
// Values
|
||||
|
|
@ -809,6 +813,12 @@
|
|||
);
|
||||
}
|
||||
break;
|
||||
// QR-Code conditions
|
||||
case 'qrcode':
|
||||
if(array_key_exists($condition['id'], $deletes)) {
|
||||
$this->Achievements->deleteAchievementConditionQrcode($condition['id']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -892,6 +902,16 @@
|
|||
);
|
||||
}
|
||||
break;
|
||||
// QR-code conditions
|
||||
case 'qrcode':
|
||||
if(array_key_exists('qrcode', $condition))
|
||||
{
|
||||
$this->Achievements->addAchievementConditionQrcode(
|
||||
$this->Auth->getUserId(),
|
||||
$achievement['id']
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,11 +25,84 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'charactergroupsachievements');
|
||||
public $models = array('seminaries', 'achievements', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'charactergroupsachievements');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: a.
|
||||
*
|
||||
* Trigger an Achievement by a hash typically provided via a QR-code.
|
||||
*
|
||||
* @param $achievementConditionHash Hash value of QR-code condition of an Achievement
|
||||
*/
|
||||
public function a($achievementConditionHash)
|
||||
{
|
||||
// Check Achievement condition
|
||||
$condition = $this->Achievements->getAchievementConditionQrcode(
|
||||
$achievementConditionHash
|
||||
);
|
||||
if(empty($condition)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($achievementConditionHash);
|
||||
}
|
||||
|
||||
// Get Achievement
|
||||
$achievement = $this->Achievements->getAchievementById($condition['achievement_id']);
|
||||
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryById($achievement['seminary_id']);
|
||||
|
||||
// Get Character
|
||||
$character = $this->Characters->getCharacterForUserAndSeminary(
|
||||
self::$user['id'],
|
||||
$seminary['id']
|
||||
);
|
||||
|
||||
// Set Achievement achieved
|
||||
$this->Achievements->setAchievementAchieved(
|
||||
$achievement['id'],
|
||||
$character['id']
|
||||
);
|
||||
|
||||
// Add notifications
|
||||
$this->Notification->addNotification(
|
||||
\hhu\z\controllers\components\NotificationComponent::TYPE_ACHIEVEMENT,
|
||||
$achievement['title'],
|
||||
$this->linker->link(
|
||||
array(
|
||||
'achievements',
|
||||
'index',
|
||||
$seminary['url']
|
||||
), 0, true, null, true, $achievement['url']
|
||||
),
|
||||
(
|
||||
!is_null($achievement['achieved_achievementsmedia_id'])
|
||||
? $this->linker->link(
|
||||
array(
|
||||
'media',
|
||||
'achievement',
|
||||
$seminary['url'],
|
||||
$achievement['url']
|
||||
)
|
||||
)
|
||||
: null
|
||||
)
|
||||
);
|
||||
|
||||
// Redirect to Character profile
|
||||
$this->redirect(
|
||||
$this->linker->link(
|
||||
array(
|
||||
'achievements',
|
||||
'index',
|
||||
$seminary['url']
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: cgqs.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'charactergroupsachievements');
|
||||
public $models = array('seminaries', 'achievements', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'charactergroupsachievements');
|
||||
|
||||
|
||||
|
||||
|
|
@ -46,6 +46,48 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: achievement
|
||||
*
|
||||
* Display a QR-code for an Achievement.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $groupsgroupUrl URL-Title of a Character groups-group
|
||||
* @param string $achievementUrl URL of Achievement
|
||||
*/
|
||||
public function achievement($seminaryUrl, $achievementUrl, $size=1)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Achievement
|
||||
$achievement = $this->Achievements->getAchievementByUrl(
|
||||
$seminary['id'],
|
||||
$achievementUrl
|
||||
);
|
||||
|
||||
// Get condition
|
||||
$conditions = $this->Achievements->getAchievementConditionsQrcode(
|
||||
$achievement['id']
|
||||
);
|
||||
if(empty($conditions)) {
|
||||
throw new IdNotFoundException($achievementUrl);
|
||||
}
|
||||
|
||||
// Generate QR-code
|
||||
$url = $this->linker->link(array('qr', 'a', $conditions[0]['hash']), 0, true, null, true, null, true);
|
||||
$file = $this->generateQRcode($url, $size);
|
||||
if(is_null($file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('file', $file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: charactergroupsqueststation
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue