Example #1
0
 /**
  * Save a new event on database table "_events"
  * @param Event $event
  * @return Event
  */
 public function saveEvent(Event $event)
 {
     $sql = 'INSERT INTO gm_events
             (alias, description, allow_repetitions, reach_required_repetitions, id_each_badge, id_reach_badge, each_points, max_points, each_callback, reach_callback)
             VALUES
             (:alias, :description, :allow_repetitions, :reach_required_repetitions, :id_each_badge, :id_reach_badge, :each_points, :max_points, :each_callback, :reach_callback)';
     $params = array(':alias' => $event->getAlias(), ':description' => $event->getDescription(), ':allow_repetitions' => $event->getAllowRepetitions(), ':reach_required_repetitions' => $event->getRequiredRepetitions(), ':id_each_badge' => $event->getIdEachBadge(), ':id_reach_badge' => $event->getIdReachBadge(), ':each_points' => $event->getEachPoints(), ':max_points' => $event->getMaxPoints(), ':each_callback' => $event->getEachCallback(), ':reach_callback' => $event->getReachCallback());
     $this->execute($sql, $params);
     return $this->getEventById($this->lastInsertId());
 }
 private static function addEvent($event = null)
 {
     // Postando?
     if (count($_POST) > 0) {
         if ($_POST['id']) {
             // Update??
             die("Update não implementado");
         } else {
             $event = new Event();
             $event->setAlias($_POST['alias']);
             $event->setDescription($_POST['description']);
             $event->setAllowRepetitions($_POST['allow_repetitions'] == 1);
             if ($_POST['reach_required_repetitions']) {
                 $event->setReachRequiredRepetitions($_POST['reach_required_repetitions']);
             }
             if ($_POST['id_each_badge']) {
                 $badge = Gamification::getInstance()->getBadge($_POST['id_each_badge']);
                 $event->setEachBadgeGranted($badge);
             }
             if ($_POST['id_reach_badge']) {
                 $badge = Gamification::getInstance()->getBadge($_POST['id_reach_badge']);
                 $event->setReachBadgeGranted($badge);
             }
             if ($_POST['each_points']) {
                 $event->setEachPointsGranted($_POST['each_points']);
             }
             if ($_POST['reach_points']) {
                 $event->setReachPointsGranted($_POST['reach_points']);
             }
             $event = Gamification::getInstance()->addEvent($event);
         }
         ControllerGamification::eventList();
     } else {
         require_once PLUGINPATH . '/view/gamification/form_event.php';
     }
 }
Example #3
0
    $event->setAlias('login')->setEachPointsGranted(25)->setEachBadgeGranted($gamification->getBadgeByAlias('newbee'))->setReachRequiredRepetitions(10)->setReachPointsGranted(50)->setReachBadgeGranted($gamification->getBadgeByAlias('addict'));
    $gamification->addEvent($event);
    // Each Post to the chat/Posted 20 messages to the chat (5 points each post, badge when 20 reached)
    $event = new Event();
    $event->setAlias('post_to_chat')->setEachPointsGranted(5)->setReachRequiredRepetitions(20)->setReachBadgeGranted($gamification->getBadgeByAlias('king_of_chat'))->setReachCallback("MyOtherClass::myPostToChatReachCallBackFunction");
    $gamification->addEvent($event);
    // Each post to blog/You wrote 5 post to your blog (100 points each + badge, 1000 points reach)
    $event = new Event();
    $event->setAlias('post_to_blog')->setEachPointsGranted(150)->setEachBadgeGranted($gamification->getBadgeByAlias('spreader'))->setEachCallback("MyOtherClass::myPostToBlogCallBackFunction")->setReachRequiredRepetitions(50)->setReachBadgeGranted($gamification->getBadgeByAlias('professional_writer'));
    $gamification->addEvent($event);
    // When you get the Five Stars level
    $event = new Event();
    $event->setAlias('grant_five_stars_badge')->setEachBadgeGranted($gamification->getBadgeByAlias('five_stars_badge'));
    $gamification->addEvent($event);
    // When you get the Five Stars level
    $event = new Event();
    $event->setAlias('donate_money')->setEachBadgeGranted($gamification->getBadgeByAlias('money_user'));
    $gamification->addEvent($event);
} else {
    if ($truncateDatabaseUsers == true) {
        $gamification->truncateDatabase(false);
    }
}
/**
 * USAGE:
 */
// User who receives gamification events
$gamification->setUserId(1);
// Show user scores before events
echo "<b>Before execute events</b>";
showUserScores($gamification);
 public function clearAllData()
 {
     $gamification = self::$gamification;
     // Reset all data
     $gamification->truncateDatabase(true);
     /**
      * Configurações do GDG como no Drive:
      */
     // Badges definitions
     $noogler = $gamification->addBadge('noogler', 'GDG Noogler', '');
     $friend = $gamification->addBadge('friend', 'GDG Friend', '');
     $pequenoGafanhoto = $gamification->addBadge('pequeno_gafanhoto', 'Pequeno Gafanhoto', '');
     $dino = $gamification->addBadge('dino', 'Dinossauro do GDGJF', '');
     $gamification->addBadge('king_of_chat', 'King of the Chat', 'You posted 10 messages to the chat (500 points)', 'img/badge2.png');
     $gamification->addBadge('spreader', 'Blog Spreader', 'You wrote 5 post to your blog (1000 points)', 'img/badge3.png');
     $gamification->addBadge('five_stars_badge', 'Five Stars', 'You get the Five Stars level', 'img/badge4.png');
     // Niveis
     $gamification->addLevel(0, 'Hello World');
     //        $gamification->addLevel(1000, 'Five stars', 'grant_five_stars_badge'); // Execute event: grant_five_stars_badge
     // Primeira vez no GDG - 10 pontos - badge noogler
     $event = new Event();
     $event->setAlias('first_presence')->setDescription('Primeira presença no GDGJF')->setEachPointsGranted(10)->setAllowRepetitions(false)->setEachCallback('\\lib\\Gamification::CallbackFirstPresence')->setEachBadgeGranted($noogler);
     $gamification->addEvent($event);
     // Já tinha ido no GDG antes vez no GDG - 15 pontos - badge noogler
     $event = new Event();
     $event->setAlias('before_gamification')->setDescription('Já ia ao GDG antes da Era do Gamification, é um dinosauro praticamente!')->setEachPointsGranted(15)->setAllowRepetitions(false)->setEachCallback('\\lib\\Gamification::CallbackBeforeGamification')->setEachBadgeGranted($dino);
     $gamification->addEvent($event);
     // Estar presente em um evento do GDG - 10 pontos - (5x) badge friend
     $event = new Event();
     $event->setAlias('event_presence')->setDescription('Esteve presente ao evento')->setEachPointsGranted(10)->setEachCallback('\\lib\\Gamification::CallbackEventPresence')->setAllowRepetitions(true);
     //            ->setReachRequiredRepetitions(5)
     //            ->setEachBadgeGranted($friend);
     $gamification->addEvent($event);
     // Dar Feedback de evento - 5 points
     $event = new Event();
     $event->setAlias('event_feedback')->setDescription('Respondeu o formulário de feedback do evento')->setEachPointsGranted(5)->setAllowRepetitions(true)->setEachCallback('\\lib\\Gamification::CallbackEventFeedback');
     $gamification->addEvent($event);
     // Ir ao hamburger após o evento - 5 points
     $event = new Event();
     $event->setAlias('lets_hamburger')->setDescription('Foi ao hamburger com a galera do GDG')->setEachPointsGranted(5)->setAllowRepetitions(true);
     $gamification->addEvent($event);
     // Escrever post pro blog - 20 pontos - (4x) badge writer
     $event = new Event();
     $event->setAlias('blog_post')->setDescription('Escreveu um post para o Blog')->setEachPointsGranted(20)->setAllowRepetitions(true);
     //            ->setEachCallback('\lib\Gamification::CallbackBlogPost')
     //            ->setReachRequiredRepetitions(5)
     //            ->setEachBadgeGranted($friend);
     $gamification->addEvent($event);
     // Apresentar conteúdo - 10 pontos - (1x) badge writer - 4x badge
     $event = new Event();
     $event->setAlias('event_present')->setDescription('Apresentou conteúdo no evento')->setEachPointsGranted(10)->setAllowRepetitions(true)->setEachCallback('\\lib\\Gamification::CallbackEventPresent')->setReachRequiredRepetitions(1)->setEachBadgeGranted($pequenoGafanhoto);
     $gamification->addEvent($event);
     // Auxiliar na organização - 10 pontos - (1x) badge  - 4x badge
     $event = new Event();
     $event->setAlias('event_support')->setDescription('Auxiliou na organização de evento')->setEachPointsGranted(10)->setAllowRepetitions(true)->setEachCallback('\\lib\\Gamification::CallbackEventSupport');
     $gamification->addEvent($event);
     echo "<br><B>Dados apagados!!!</B><Br>";
 }