示例#1
0
 /**
  * Create an instance of the object and load data.
  *
  * <code>
  * $rankId = 1;
  * $rank   = Gamification\Rank\Rank::getInstance(\JFactory::getDbo(), $rankId);
  * </code>
  *
  * @param \JDatabaseDriver $db
  * @param int $id
  *
  * @return null|Rank
  */
 public static function getInstance(\JDatabaseDriver $db, $id)
 {
     if (empty(self::$instances[$id])) {
         $item = new Rank($db);
         $item->load($id);
         self::$instances[$id] = $item;
     }
     return self::$instances[$id];
 }
 protected function prepareRankObject($rankId)
 {
     if ($rankId > 0) {
         $key = StringHelper::generateMd5Hash(BasicRank::class, $rankId);
         if ($this->container !== null) {
             if ($this->container->exists($key)) {
                 $this->rank = $this->container->get($key);
             } else {
                 $this->rank = new BasicRank($this->db);
                 $this->rank->setContainer($this->container);
                 $this->rank->load($rankId);
                 $this->container->set($key, $this->rank);
             }
         } else {
             $this->rank = new BasicRank($this->db);
             $this->rank->load($rankId);
         }
     }
 }