Example #1
0
 /**
  * Create an instance of the object and load data.
  *
  * <code>
  * // create object points by ID
  * $pointsId   = 1;
  * $points     = Gamification\Points\Points::getInstance(\JFactory::getDbo(), $pointsId);
  *
  * // create object points by abbreviation
  * $keys = array(
  *    "abbr" => "P"
  * );
  * $points     = Gamification\Points\Points::getInstance(\JFactory::getDbo(), $keys);
  * </code>
  *
  * @param \JDatabaseDriver $db
  * @param int|array $keys
  *
  * @return null|self
  */
 public static function getInstance($db, $keys)
 {
     if (is_array($keys)) {
         $index = ArrayHelper::getValue($keys, "abbr");
     } else {
         $index = (int) $keys;
     }
     $index = \JApplicationHelper::getHash($index);
     if (!isset(self::$instances[$index])) {
         $item = new Points($db);
         $item->load($keys);
         self::$instances[$index] = $item;
     }
     return self::$instances[$index];
 }
 protected function preparePointsObject($pointsId)
 {
     $key = StringHelper::generateMd5Hash(BasicPoints::class, $pointsId);
     if ($this->container !== null) {
         if ($this->container->exists($key)) {
             $this->points = $this->container->get($key);
         } else {
             $this->points = new BasicPoints($this->db);
             $this->points->load($pointsId);
             $this->container->set($key, $this->points);
         }
     } else {
         $this->points = new BasicPoints($this->db);
         $this->points->load($pointsId);
     }
 }