1: <?php if(!defined('APPLICATION')) exit();
2: /* Copyright 2013 Zachary Doll */
3:
4: /**
5: * Renders a user's badges in a nice grid in the panel
6: *
7: * @package Yaga
8: * @since 1.0
9: */
10: class BadgesModule extends Gdn_Module {
11:
12: /**
13: * Retrieves the user's badgelist upon construction of the module object.
14: *
15: * @param string $Sender
16: */
17: public function __construct($Sender = '') {
18: parent::__construct($Sender);
19:
20: // default to the user object on the controller/the currently logged in user
21: if(property_exists($Sender, 'User')
22: && $Sender->User) {
23: $UserID = $Sender->User->UserID;
24: }
25: else {
26: $UserID = Gdn::Session()->UserID;
27: }
28:
29: if(Gdn::Session()->UserID == $UserID) {
30: $this->Title = T('Yaga.MyBadges');
31: }
32: else {
33: $this->Title = T('Yaga.Badges');
34: }
35:
36: $BadgeAwardModel = Yaga::BadgeAwardModel();
37: $this->Data = $BadgeAwardModel->GetByUser($UserID);
38: }
39:
40: /**
41: * Specifies the asset this module should be rendered to.
42: *
43: * @return string
44: */
45: public function AssetTarget() {
46: return 'Panel';
47: }
48:
49: /**
50: * Renders a badge list in a nice little box.
51: *
52: * @return string
53: */
54: public function ToString() {
55: if($this->Data) {
56: if($this->Visible) {
57: $ViewPath = $this->FetchViewLocation('badges', 'yaga');
58: $String = '';
59: ob_start();
60: include ($ViewPath);
61: $String = ob_get_contents();
62: @ob_end_clean();
63: return $String;
64: }
65: }
66: return '';
67: }
68:
69: }
70: