/** * Build image of the achievement and save it to the given path * @param Achievement $achievement achievement * @param string $path image file path including format (eg: achievements/1.png) * @access public * @return void */ function generate_achievement($achievement, $path) { if (!can_write($path)) { throw new Exception(_f('Can\'t write to file %s', array($path))); } $image = $achievement->generate(); $image->save($path); return $image; }
public function Achievement($cache = true) { require_once $this->App()->config("paths")['backend']['Achievement']; require_once $this->App()->config("paths")['backend']['CacheWrapper']; $Achievement = new Achievement(); $Achievement->setFont($this->App()->config("defaults")['achievement']['font'])->setBackground($this->App()->config("defaults")['achievement']['background']); if ($cache) { return new CacheWrapper($this->App()->config("paths")['cache'], $Achievement); } else { return $Achievement; } }
/** * @return null|object|Achievement * get singleton instance */ public static function getInstance() { if (!self::$instance) { self::$instance = new Achievement(); } return self::$instance; }
public static function joinPoint($mode, $class, $method, $args = null, $defaultValue = null) { $value = Aspect::findPointCut($mode, $class, $method, $args); if (Session::isPluginLoaded("mAchievement") and $mode == "after") { Achievement::findPointCut($class, $method, $args); } if ($value === null) { return $defaultValue; } return $value; }
/** * Load all user achievements and set them to group index. * Every user can have only one achievement for a group. * * <code> * $options = array( * 'user_id' => 1, * 'group_id' => 2 * ); * * $userAchievements = new Gamification\User\Achievements(JFactory::getDbo()); * $userAchievements->load($options); * </code> * * @param array $options */ public function load(array $options = array()) { $userId = $this->getOptionId($options, 'user_id'); $groupId = $this->getOptionId($options, 'group_id'); // Create a new query object. $query = $this->db->getQuery(true); $query->select('a.achievement_id, a.user_id, a.group_id')->select('b.title, b.points, b.image, b.published, b.points_id, b.group_id')->from($this->db->quoteName('#__gfy_userachievements', 'a'))->innerJoin($this->db->quoteName('#__gfy_achievements', 'b') . ' ON a.achievement_id = b.id')->where('a.user_id = ' . (int) $userId); if ($groupId > 0) { $query->where('a.group_id = ' . (int) $groupId); } $this->db->setQuery($query); $results = (array) $this->db->loadAssocList(); if (count($results) > 0) { $this->userId = $userId; foreach ($results as $result) { $achievement = new Achievement(\JFactory::getDbo()); $achievement->bind($result); $this->items[$result['group_id']][$achievement->getAchievementId()] = $achievement; } } }
/** * save new achievement via REST. * role: player */ public function unlock_achievement() { if (Authenticate::is_player()) { if (isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) { $this->model_achievement = Achievement::getInstance(); /* * populate type of achievement. * invoke method to unlock the achievement. * log this event about achievement earning. */ $achievement = $_POST["achievement"]; $result = $this->model_achievement->unlock_achievement($achievement); $log = Log::getInstance(); $log->logging_game_earn_achievement("Achievement id {$achievement}"); $binding = array("result_var" => "session_ready", "unlock_status" => $result); binding_data($binding); } else { transport("error404"); } } else { $binding = array("result_var" => "no_session"); binding_data($binding); } }
file_put_contents($path . "images/" . $filename . ".jpg", base64_decode($section->picture)); echo ' <img class="img-polaroid" src="http://skoolyf.kellyescape.com/' . $path . 'images/' . $filename . '.jpg" />'; echo ' </div>'; echo ' <div class="span12 thebox">'; echo ' <p class="ybname2">Adviser Message</p>'; echo ' <p class="advisermessage">'; echo ' ' . $section->advisermessage . ''; echo ' </p>'; echo ' </div>'; $sectionusers = SectionUser::getUsersInSection($section->id); foreach ($sectionusers as $sectionuser) { $counter++; $filename = $counter; if ($sectionuser->pending == 0 && $sectionuser->enabled == 1) { $user = User::get_by_id($sectionuser->userid); $achievements = Achievement::get($user->id, "user", $batch->id); $clubusers = ClubUser::getClubsImIn($user->id); $groupusers = GroupUser::getGroupsImIn($user->id); $comments = Comment::get_all_comments($user->id, "user"); if ($user->pending == 0 && $user->enabled == 1) { echo '<div class="span12"></div>'; echo ' <div class="span12 mygridbox">'; echo ' <div class="span4">'; file_put_contents($path . "images/" . $filename . "xx.jpg", base64_decode($user->picture)); echo ' <img class="img-polaroid img-circle yearbookimage ybimage" src="http://skoolyf.kellyescape.com/' . $path . 'images/' . $filename . 'xx.jpg" />'; //echo ' <img class="img-polaroid img-circle yearbookimage ybimage" src="data:image/jpeg;base64, '.$user->picture.'"/>'; echo ' </div>'; echo ' <div class="span8">'; echo ' <p class="ybname">' . $user->get_full_name() . '</p>'; echo ' <p class="ybmotto">'; echo ' ' . $user->moto . '';
public function intranet_update() { self::Restrict("intranet"); $event = Event::find_by_permalink($_GET['permalink']); if (!$event) { Site::Flash("error", "Unable to find event"); Error404(); } $event_id = mysql_real_escape_string($event->id); $id = null; // Achievements $result = array(); if (isset($_REQUEST['achievements'])) { $achievements = unserialize($_REQUEST['achievements']); foreach ($achievements as $achieve) { if ($achieve['id']) { $id = mysql_real_escape_string($achieve['id']); $achievement = Achievement::find("achievements.event_id = '{$event_id}' AND achievements.intranet_id = '{$id}'"); } if (!$achievement) { $achievement = new Achievement(); $achievement->event_id = $event->id; $achievement->intranet_id = $id; } $achievement->name = $achieve['name']; $achievement->description = $achieve['description']; $achievement->image = $achieve['image']; $success = false; if ($achievement->save()) { $success = true; } $result[] = array('id' => $id, 'result' => $success, 'achievement' => $achievement); } } $this->assign("result", $result); // User achievements UserAchievement::MarkNotUpdated($event_id); $result = array(); if (isset($_REQUEST['user_achievements'])) { $user_achievements = unserialize($_REQUEST['user_achievements']); foreach ($user_achievements as $achieve) { $id = mysql_real_escape_string($achieve['achievement_id']); $user_id = mysql_real_escape_string($achieve['user_id']); $achievement = Achievement::find("achievements.intranet_id = '{$id}' AND achievements.event_id = '{$event_id}'"); if (!$achievement) { $success = false; } else { $achievement_id = mysql_real_escape_string($achievement->id); $user_achievement = UserAchievement::find("achievements.id = '{$achievement_id}' and users.id = '{$user_id}'"); $success = false; if (!$user_achievement) { $user_achievement = new UserAchievement(); $user_achievement->user_id = $user_id; $user_achievement->achievement_id = $achievement_id; } $user_achievement->updated = true; if ($user_achievement->save()) { $success = true; } } $result[] = array('id' => $achieve['id'], 'result' => $success, 'user_achievement' => $user_achievement); } } UserAchievement::DestroyNotUpdated(); $this->assign("user_result", $result); header('Content-Type: text/xml'); $this->render("achievement/intranet_update.tpl", true); }
/** * Preview action : generate an achievement preview * @access public * @return void */ public function preview() { $this->layout = ''; $this->form = new AchievementCreateForm(); if (!$this->form->is_valid($this->params)) { //FIXME: error management ? render an error image ? $this->flash['error'] = __('Fail to create achievement : Check data.'); return; } $achievement = new Achievement($this->form->cleaned_data); $image = $achievement->generate(); $this->render_image($image->image); $image->destroy(); }
protected function load_achievement($id = null) { if (!$id) { $id = $this->GetData('id'); } $achievement = Achievement::find_by_id($id); if ($achievement) { return $achievement; } else { throw new Error404(); } }
/** * show player details, show achievement and statistic. * role: administrator * redirected from: Controller.Player.suspend() whatever suspend result * Controller.Player.reactivate() whatever reactivate result */ public function detail() { if (Authenticate::is_authorized()) { $model_player = Player::getInstance(); $model_journal = Journal::getInstance(); $model_achievement = Achievement::getInstance(); $model_asset = Asset::getInstance(); $model_material = Material::getInstance(); $model_employee = Employee::getInstance(); $model_memorycard = Memorycard::getInstance(); $id = $this->framework->url->url_part(3); $this->framework->view->page = "player"; $this->framework->view->content = "/backend/pages/player_detail"; $this->framework->view->player_detail = $model_player->player_detail($id); $this->framework->view->player_summary = $model_player->fetch($id); $this->framework->view->player_performance = $model_player->performance($id); $this->framework->view->player_finance = $model_journal->finance_summaries($id); $this->framework->view->player_achievements = $model_achievement->get_achievement($id); $this->framework->view->player_assets = $model_asset->get_player_asset($id); $this->framework->view->player_employees = $model_employee->get_player_employee($id); $this->framework->view->player_materials = $model_material->get_player_material($id); $this->framework->view->player_game = $model_memorycard->load_game_data($id); $this->framework->view->show("backend/template"); } else { transport("administrator"); } }
protected static function get_fields() { return implode(', ', array(self::select_fields(), User::select_fields(), Achievement::select_fields(), AchievementCategory::select_fields())); }
/** * load game data every play game. * role: player * @return string */ public function load_data() { if (Authenticate::is_player()) { if (true || isset($_POST['token']) && Authenticate::is_valid_token($_POST['token'])) { $this->model_product = Product::getInstance(); $this->model_material = Material::getInstance(); $this->model_asset = Asset::getInstance(); $this->model_supplier = Supplier::getInstance(); $this->model_employee = Employee::getInstance(); $this->model_achievement = Achievement::getInstance(); $this->model_journal = Journal::getInstance(); $this->model_memorycard = Memorycard::getInstance(); $this->model_leaderboard = Leaderboard::getInstance(); /* * retrieve data each component. * log this event, wrap it up and convert to json format. */ $game = $this->model_memorycard->load_game_data(); $work_history = $this->model_memorycard->get_work_stress_history(); $total_work = $this->model_memorycard->get_total_work(); $candidate = $this->model_employee->get_candidate(); $employee = $this->model_employee->get_player_employee(); $material = $this->model_material->get_material_data(); $player_material = $this->model_material->get_player_material(); $asset = $this->model_asset->get_asset_data(); $player_asset = $this->model_asset->get_player_asset(); $product = $this->model_product->get_product_data(); $player_product = $this->model_product->get_player_product(); $product_material = $this->model_product->get_product_material(); $supplier = $this->model_supplier->get_supplier_data(); $achievement = $this->model_achievement->get_achievement(); $account = $this->model_journal->get_account(); $simulation = $this->model_memorycard->get_simulation(); $star = $this->model_leaderboard->get_player_ranking(); $binding = array("result_var" => "session_ready", "game_var" => json_encode($game, JSON_PRETTY_PRINT), "candidate_var" => json_encode($candidate, JSON_PRETTY_PRINT), "employee_var" => json_encode($employee, JSON_PRETTY_PRINT), "product_var" => json_encode($product, JSON_PRETTY_PRINT), "player_product_var" => json_encode($player_product, JSON_PRETTY_PRINT), "product_material_var" => json_encode($product_material, JSON_PRETTY_PRINT), "material_var" => json_encode($material, JSON_PRETTY_PRINT), "player_material_var" => json_encode($player_material, JSON_PRETTY_PRINT), "asset_var" => json_encode($asset, JSON_PRETTY_PRINT), "player_asset_var" => json_encode($player_asset, JSON_PRETTY_PRINT), "supplier_var" => json_encode($supplier, JSON_PRETTY_PRINT), "achievement_var" => json_encode($achievement, JSON_PRETTY_PRINT), "account_var" => json_encode($account, JSON_PRETTY_PRINT), "simulation_var" => json_encode($simulation, JSON_PRETTY_PRINT), "work_history_var" => json_encode($work_history, JSON_PRETTY_PRINT), "work_total_var" => $total_work, "star" => $star["star"]); $log = Log::getInstance(); $log->logging_game_load(json_encode($binding)); binding_data($binding); } else { transport("error404"); } } else { $binding = array("result_var" => "no_session"); binding_data($binding); } }
$id = $f3->get('PARAMS.id'); // If user sending request is authenticated if ($sender_id = authenticated()) { $user = new User(null, $id); if ($user_info = $user->getInfo(false)) { $response = (object) array('status' => 1, 'status_explanation' => 'Success.', 'handle' => $user_info->handle, 'first_name' => $user_info->first_name, 'last_name' => $user_info->last_name, 'image' => $user_info->image); } else { $response = (object) array('status' => -2, 'status_explanation' => 'Couldn\'t fetch user information from database.'); } } else { $response = (object) array('status' => -1, 'status_explanation' => 'Insufficient data provided.'); } header('Content-Type: application/json'); echo json_encode($response, JSON_PRETTY_PRINT); }, $f3->get('route_ttl')); /** * Route: Retrieve all achievements * @todo the achievement system needs to be finished. Right now it just returns a list of available achievements. Nothing more. * * @example /achievements/ */ $f3->route(array('GET /achievements'), function ($f3, $params) use($db) { if ($achievements = Achievement::getAll()) { $result = (object) array('status' => 1, 'achievements' => $achievements); } else { $result = (object) array('status' => -1, 'status_explanation' => 'Could not retrieve achievements.'); } header('Content-Type: application/json'); echo json_encode($result); }, $f3->get('route_ttl')); $f3->run();