Пример #1
5
 public static function votedown($data)
 {
     $out = array();
     if (!MyUser::isloggedin()) {
         throw new APIException("User ist nicht angemeldet.", 100);
     }
     if (MyUser::getKarmaPoints() < 100) {
         throw new APIException("Du benötigst 100 Karma-Punkte um einen negativen Vote zu geben.", 200);
     }
     if (!isset($data["question"])) {
         throw new APIException("Benötigter Parameter fehlt (question).", 50);
     }
     $db = new SQL(0);
     $row = $db->cmdrow(0, 'SELECT * FROM questions WHERE id={0}', array($data["question"] + 0));
     if (!isset($row["id"])) {
         throw new APIException("Diese Frage existiert nicht (mehr)", 300);
     }
     if ($row["author"] == MyUser::id()) {
         throw new APIException("Sie dürfen nicht auf Ihre eigene Frage voten", 301);
     }
     $raw = $db->cmdrow(0, 'SELECT * FROM question_votes WHERE question={0} AND user={1} LIMIT 0,1', array($data["question"] + 0, MyUser::id()));
     $w = array();
     $w["question"] = $data["question"] + 0;
     $w["user"] = MyUser::id();
     $w["vote"] = -1;
     $db->CreateUpdate(0, "question_votes", $w);
     $db->cmd(0, 'UPDATE questions as T1 SET count_votes = (SELECT sum(vote) FROM question_votes WHERE question=T1.id) WHERE id={0} LIMIT 1', false, array($w["question"]));
     $out["sumvotes"] = self::getVotes(array("question" => $w["question"]));
     if (!isset($raw["id"])) {
         Karma::RuleAction("VOTEDOWN_QUESTION", array("user" => $row["author"], "question" => $w["question"]));
     }
     Badge::add(9, MyUser::id(), array("question" => $w["question"]));
     //Kritiker: für downvote
     return $out;
 }
Пример #2
2
 /**
  * Returns an array of properties representing the 'value' of a badge.
  *
  * @param Badge $badge Value should be returned.
  *
  * @return an array of values of the given badges
  */
 private static function getValue(Badge $badge)
 {
     return array("name" => $badge->getName());
 }
 public function actionMy()
 {
     $this->pageTitle = Yii::t('badgerModule.Site', 'My badges');
     $Badge = new Badge();
     $Badge->checkAndGiveOne(Badge::BADGE_LIST_MY);
     $badges = Badge::model()->my()->findAll();
     $this->render('my', array('badges' => $badges));
 }
Пример #4
1
 public function getBadges()
 {
     $result = Database::query(SQL::trainerBadges($this->id));
     $badges = array();
     if (mysqli_num_rows($result) > 0) {
         foreach ($result as $row) {
             $badge = new Badge($row);
             array_push($badges, $badge->serialize());
         }
     }
     return $badges;
 }
Пример #5
1
 /**
  * Tests all badges are valid.
  */
 public function testValid()
 {
     $badges = Badge::model()->findAll();
     foreach ($badges as $badge) {
         $this->assertFileExists(Yii::app()->params['badgeIconsDir'] . $badge->location);
     }
 }
Пример #6
1
 /**
  * Retrieves all conditions.
  * @return array the conditions
  */
 public function conditions()
 {
     $mapping = $this->getMappings();
     $conditions = array();
     foreach ($mapping as $id => $count) {
         $conditions[] = array('badge' => Badge::model()->findByPk($id), 'count' => $count);
     }
     return $conditions;
 }
Пример #7
1
 /** Parses habbo info array to \Entities\Habbo object
  *
  * @param array $data
  */
 public function parse($data)
 {
     $this->setId($data['uniqueId']);
     $this->setHabboName($data['name']);
     $this->setMotto($data['motto']);
     $this->setFigureString($data['figureString']);
     if (isset($data['memberSince'])) {
         $this->setMemberSince($data['memberSince']);
     }
     if (isset($data['profileVisible'])) {
         $this->setProfileVisible($data['profileVisible']);
     }
     if (isset($data['selectedBadges'])) {
         foreach ($data['selectedBadges'] as $badge) {
             $selectedBadge = new Badge();
             $selectedBadge->parse($badge);
             $this->addSelectedBadge($selectedBadge);
         }
     }
 }
Пример #8
0
 public function __construct($id)
 {
     $name = "Sea Pup";
     $label = "SeaPup";
     $achieved = Database::getBadgeState($id, $label);
     $requirements = Database::getBadgeRequirements($label);
     parent::__construct($name, $achieved, $requirements, $label);
 }
 public function revokeBadge($badge)
 {
     if (is_array($badge)) {
         $revokeReason = $badge['reason'];
         $badge = Badge::findOrFail($badge['model']->id);
     }
     if ($badge->count() && empty($badge->revoked_at)) {
         $this->getBadgePivotBuilder($badge->id)->update(['revoke_reason' => $revokeReason, 'revoked_at' => Carbon::now()]);
     }
 }
Пример #10
0
 public function __construct($data)
 {
     if (is_array($data)) {
         $this->id = $data['gym_id'];
         $this->name = $data['gym_name'];
         $this->city = $data['gym_city'];
         $type = Type::getById(intval($data['gym_type']));
         $this->type = $type->serialize();
         $badge = Badge::getById(intval($data['gym_badge']));
         $this->badge = $badge->serialize();
     }
 }
Пример #11
0
 /**
  * Return the reward in JSON format.
  *
  * @return the reward in JSON format
  */
 public function toJson()
 {
     $response = array();
     if (count($this->getBadges()) > 0) {
         $response["badges"] = Badge::getValues($this->getBadges());
     } else {
         $response["badges"] = array();
     }
     $response["koin_count_new"] = $this->getKoinCountNew();
     $response["koin_count_total"] = $this->getKoinCountTotal();
     return json_encode($response);
 }
Пример #12
0
 public function actionIndex()
 {
     $this->render('layouts/header');
     $this->render('general/index', array('general' => $this->getGeneral(), 'messages' => $this->getMessages()), true);
     $this->render('pokemon/index', array('pokemon' => Pokemon::getPartyPokemon(), 'owned' => $this->getGeneral()->pokedex_owned, 'seen' => $this->getGeneral()->pokedex_seen), true);
     $this->render('badge/index', array('badges' => Badge::getBadges(null, 'LIMIT 0, 8')), true);
     $this->render('pokemon_box/index', array('pokemon' => Pokemon::getBoxPokemon()), true);
     $this->render('pokemon_daycare/index', array('pokemon' => Pokemon::getDaycarePokemon()), true);
     $this->render('item/index', array('items' => Item::getAllItems()), true);
     $this->render('pokemon_history/index', array('pokemon' => Pokemon::getHistoryPokemon()), true);
     $this->render('milestone/index', array('milestones' => Milestone::getMilestones()), true);
     $this->render('fact/index', array('facts' => Fact::getFacts()), true);
     $this->render('credit/index', array('credits' => Credit::getCredits()), true);
     $this->render('layouts/footer');
 }
 public function processLevelAndBadgeValidation()
 {
     $return = true;
     $current_level = (int) Configuration::get('GF_CURRENT_LEVEL');
     $current_level_percent = (int) Configuration::get('GF_CURRENT_LEVEL_PERCENT');
     $not_viewed_badge = explode('|', ltrim(Configuration::get('GF_NOT_VIEWED_BADGE', ''), ''));
     $nbr_notif = Configuration::get('GF_NOTIFICATION', 0);
     $ids_badge = Badge::getIdsBadgesToValidate();
     if (count($ids_badge)) {
         $not_viewed_badge = array();
     }
     //reset the last badge only if there is new badge to validate
     foreach ($ids_badge as $id) {
         $badge = new Badge((int) $id);
         if ($badge->scoring + $current_level_percent >= 100) {
             $current_level++;
             $current_level_percent = $badge->scoring + $current_level_percent - 100;
         } else {
             $current_level_percent += $badge->scoring;
         }
         $badge->validated = 1;
         $return &= $badge->save();
         $nbr_notif++;
         $not_viewed_badge[] = $badge->id;
     }
     Configuration::updateGlobalValue('GF_NOTIFICATION', (int) $nbr_notif);
     Configuration::updateGlobalValue('GF_NOT_VIEWED_BADGE', implode('|', array_unique($not_viewed_badge)));
     Configuration::updateGlobalValue('GF_CURRENT_LEVEL', (int) $current_level);
     Configuration::updateGlobalValue('GF_CURRENT_LEVEL_PERCENT', (int) $current_level_percent);
     return $return;
 }
    }

    private function _render_template($template) {
	$tpl = new Template(CURRENT_THEME_FSPATH."/widget_$template.tpl");
	return $tpl->fetch();
    }

}
    
// --- controller (part 2)

// find user and badge
$user = new user();
$user->load((int)$login_uid);
try {
    $badge = new Badge($user, $badge_tag);
} catch (PAException $e) {
    switch ($e->code) {
    case CONTENT_HAS_BEEN_DELETED:
    case ROW_DOES_NOT_EXIST:
	header("Location: " . PA::$url . "/badge_create.php");
	exit;
    default:
	throw $e;
    }
}

function badge_disp($content) {
    if ($content instanceof Badge_Redirect) {
	header("Location: ".$content->url);
    } else {
Пример #15
0
 public function processImportBadges($badges, $badges_lang, $id_lang)
 {
     $formated_badges_lang = array();
     foreach ($badges_lang as $lang) {
         $formated_badges_lang[$lang->id_ps_badge] = array('name' => array($id_lang => $lang->name), 'description' => array($id_lang => $lang->description), 'group_name' => array($id_lang => $lang->group_name));
     }
     $current_badges = array();
     $result = Db::getInstance()->ExecuteS('SELECT id_ps_badge FROM ' . _DB_PREFIX_ . 'badge');
     foreach ($result as $row) {
         $current_badges[] = (int) $row['id_ps_badge'];
     }
     $cond_ids = $this->getFormatedConditionsIds();
     foreach ($badges as $badge) {
         try {
             //if badge already exist we update language data
             if (in_array((int) $badge->id_ps_badge, $current_badges)) {
                 $bdg = new Badge(Badge::getIdByIdPs((int) $badge->id_ps_badge));
                 $bdg->name[$id_lang] = $formated_badges_lang[$badge->id_ps_badge]['name'][$id_lang];
                 $bdg->description[$id_lang] = $formated_badges_lang[$badge->id_ps_badge]['description'][$id_lang];
                 $bdg->group_name[$id_lang] = $formated_badges_lang[$badge->id_ps_badge]['group_name'][$id_lang];
                 $bdg->update();
                 unset($current_badges[(int) array_search($badge->id_ps_badge, $current_badges)]);
             } else {
                 $badge_data = array_merge((array) $badge, $formated_badges_lang[$badge->id_ps_badge]);
                 $bdg = new Badge();
                 $bdg->hydrate($badge_data, (int) $id_lang);
                 $bdg->add();
                 foreach ($badge->conditions as $cond) {
                     Db::getInstance()->insert('condition_badge', array('id_condition' => $cond_ids[$cond], 'id_badge' => $bdg->id));
                 }
             }
             unset($bdg);
         } catch (Exception $e) {
             continue;
         }
     }
     // Delete badges that are not in the file anymore
     foreach ($current_badges as $id_ps_badge) {
         $bdg = new Badge(Badge::getIdByIdPs((int) $id_ps_badge));
         $bdg->delete();
     }
 }
Пример #16
0
 public function executeAddbadge()
 {
     $c = new Criteria();
     $c->add(BadgePeer::NAME, $this->getRequestParameter('badge'));
     $exbadge = BadgePeer::doSelectOne($c);
     if ($exbadge) {
         $this->setFlash('notice', 'Badge could not be added. A badge with this name already exists.');
     } else {
         $badge = new Badge();
         $badge->setName($this->getRequestParameter('badge'));
         $badge->save();
         $this->setFlash('notice', 'Badge <b>' . $badge->getName() . '</b> added successfully.');
     }
     $this->redirect('/admin/badges');
 }
Пример #17
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBadges()
 {
     return $this->hasMany(Badge::className(), ['agg_profile_id' => 'id']);
 }
Пример #18
0
Route::get('administrador/crear-contenido/{id}', array('as' => 'crear-curso-5', 'uses' => 'TemarioController@create2'));
Route::get('administrador/crear-leccion/{id}', array('as' => 'crear-curso-6', 'uses' => 'LeccionController@create'));
Route::get('administrador/crear-evaluacion/{id}', array('as' => 'crear-curso-7', 'uses' => 'EvaluacionController@create'));
Route::get('administrador/crear-preguntas/{id}', array('as' => 'crear-curso-8', 'uses' => 'PreguntaController@create'));
Route::get('administrador/asignar-color/{id}', array('as' => 'crear-curso-9', function ($id) {
    if (Session::get('user_id') == '') {
        return Redirect::to('index');
    }
    $relaciones = RelacionUsuarioCurso::where('id_usuario', '=', Session::get('user_id'))->where('id_curso', '=', $id)->where('tipo_relacion', '=', 'Profesor Admin')->get();
    if (count($relaciones) == 0 && Session::get('tipo_usuario') != "Administrador") {
        return Redirect::to('index');
    }
    if (Badge::where('id_curso', '=', $id)->count() == 0) {
        DB::table('badge')->insert(array('id_curso' => $id, 'color1' => '#FFFFFF', 'color2' => '#000000'));
    }
    $badge = Badge::find($id);
    $curso = Curso::find($id);
    return View::make('Administrador/asignar-color')->with('curso', $curso)->with('badge', $badge);
}))->where('id', '[0-9]+');
Route::get('administrador/asignar-profesor/{id}', array('as' => 'crear-curso-3', function ($id) {
    if (Session::get('user_id') == '') {
        return Redirect::to('index');
    }
    $relaciones = RelacionUsuarioCurso::where('id_usuario', '=', Session::get('user_id'))->where('id_curso', '=', $id)->where('tipo_relacion', '=', 'Profesor Admin')->get();
    if (count($relaciones) == 0 && Session::get('tipo_usuario') != "Administrador") {
        return Redirect::to('index');
    }
    $profesores = Usuario::all();
    $curso = Curso::find($id);
    return View::make('Administrador/asignar-profe')->with('profesores', $profesores)->with('curso', $curso);
}))->where('id', '[0-9]+');
Пример #19
0
});
$app->get('/trainers/:id/badges', function ($id) use($app) {
    $trainer = Trainer::getById($id);
    sendResponse($trainer->getBadges());
});
$app->get('/gyms', function () use($app) {
    sendResponse(Gym::getAll());
});
$app->get('/gyms/:id', function ($id) use($app) {
    $gym = Gym::getById($id);
    sendResponse($gym->serialize());
});
$app->get('/gyms/:id/leader', function ($id) use($app) {
    $gym = Gym::getById($id);
    sendResponse($gym->getLeader()->serialize());
});
$app->get('/types', function () use($app) {
    sendResponse(Type::getAll());
});
$app->get('/types/:id', function ($id) use($app) {
    $type = Type::getById($id);
    sendResponse($type->serialize());
});
$app->get('/badges', function () use($app) {
    sendResponse(Badge::getAll());
});
$app->get('/badges/:id', function ($id) use($app) {
    $badge = Badge::getById($id);
    sendResponse($badge->serialize());
});
$app->run();
Пример #20
0
 public static function search($searchStr)
 {
     $result = Database::query(SQL::searchBadges($searchStr));
     return Badge::badgesForResult($result);
 }
Пример #21
0
 public function delete($id)
 {
     $badge = Badge::find($id);
     $badge->delete();
     Session::flash('success', 'Badge deleted');
     return Redirect::to('admin/badges');
 }
Пример #22
0
 public function getBadge()
 {
     $badge = Badge::find($this->id_curso);
     return $badge;
 }
Пример #23
0
 public function post($slug)
 {
     $post = Post::withTrashed()->where('slug', $slug)->first();
     $nextpost = Post::where('id', '<', $post->id)->orderBy('id', 'desc')->first();
     if (empty($post)) {
         App::abort(404);
     }
     $comments = Comment::where('post_id', $post->id)->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->get();
     $attack_comments = Comment::where('post_id', $post->id)->where('type', 'attack')->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->get();
     $assist_comments = Comment::where('post_id', $post->id)->where('type', 'assist')->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->get();
     $defense_comments = Comment::where('post_id', $post->id)->where('type', 'defense')->where('parent_comment_id', 0)->orderBy('created_at', 'desc')->take(3)->get();
     $post->load(array('votes' => function ($query) {
         $query->where('user_id', Auth::id());
     }));
     $others = Post::orderBy(DB::raw('RAND()'))->take(10)->get();
     $user = User::find($post->user_id);
     $totalposts = Post::where('user_id', $user->id)->count();
     if (!$totalposts) {
         $totalposts = 0;
     }
     $badge = Badge::where('total_posts', '<=', $totalposts)->orderBy('total_posts', 'desc')->first();
     if ($badge) {
         $badgename = $badge->name;
         $badgeimage = $badge->image;
     } else {
         $badgename = '';
         $badgeimage = '';
     }
     $featured = FeaturedPost::where('post_id', $post->id)->first();
     $data = array('page' => 'page', 'post' => $post, 'nextpost' => $nextpost, 'comments' => $comments, 'attacks' => $attack_comments, 'assists' => $assist_comments, 'defenses' => $defense_comments, 'others' => $others, 'posted_by' => $user->username, 'badge_name' => $badgename, 'badge_image' => $badgeimage, 'isfeatured' => !empty($featured) ? true : false);
     return View::make('post2')->with($data);
 }
Пример #24
0
 public static function getAll()
 {
     $cacheSec = Yii::app()->getModule('badger')->cacheSec;
     $badges = Badge::model()->cache($cacheSec)->findAll();
     return $badges;
 }
Пример #25
0
 public function ToString()
 {
     $value = "<span class=\"ProfileBadges\">";
     $badges = Badge::GetByUser($this);
     foreach ($badges as $badge) {
         $value .= "<img src=\"" . System::ExpandRelativePath("~/images/badges/" . $badge->Name . ".png") . "\" alt=\"" . $badge->Title . "\" title=\"" . $badge->Title . "\" /> ";
     }
     $value .= "</span>";
     $value .= $this->LongName;
     return $value;
 }