/**
  * Load all user ranks and set them to group index.
  * Every user can have only one rank for a group.
  *
  * <code>
  * $options = array(
  *       'user_id'  => 1,
  *       'group_id' => 2
  * );
  *
  * $userRanks     = new Gamification\User\Ranks(JFactory::getDbo());
  * $userRanks->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.rank_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_userranks', 'a'))->innerJoin($this->db->quoteName('#__gfy_ranks', 'b') . ' ON a.rank_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) {
             $rank = new Rank(\JFactory::getDbo());
             $rank->bind($result);
             $this->items[$result['group_id']][$rank->getRankId()] = $rank;
         }
     }
 }
Example #2
0
 /**
  * Load all user ranks and set them to group index.
  * Every user can have only one rank for a group.
  *
  * <code>
  * $options = array(
  *       "user_id"  => 1,
  *       "group_id" => 2
  * );
  *
  * $userRanks     = new Gamification\User\Ranks(JFactory::getDbo());
  * $userRanks->load($options);
  * </code>
  *
  * @param array $options
  */
 public function load($options = array())
 {
     $userId = ArrayHelper::getValue($options, "user_id");
     $groupId = ArrayHelper::getValue($options, "group_id");
     // Create a new query object.
     $query = $this->db->getQuery(true);
     $query->select("a.rank_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_userranks", "a"))->innerJoin($this->db->quoteName("#__gfy_ranks", "b") . ' ON a.rank_id = b.id')->where("a.user_id = " . (int) $userId);
     if (!empty($groupId)) {
         $query->where("a.group_id = " . (int) $groupId);
     }
     $this->db->setQuery($query);
     $results = (array) $this->db->loadAssocList();
     if (!empty($results)) {
         $this->userId = $userId;
         foreach ($results as $result) {
             $rank = new Rank(\JFactory::getDbo());
             $rank->bind($result);
             $this->items[$result["group_id"]][$rank->getRankId()] = $rank;
         }
     }
 }