Esempio n. 1
0
 /**
  * Return badge description with possibility
  * to replace placeholders with dynamically generated data.
  *
  * <code>
  * $badgeId    = 1;
  * $badge      = new Gamification\Badge\Badge(\JFactory::getDbo());
  *
  * $data = array(
  *     "name" => "John Dow",
  *     "title" => "..."
  * );
  *
  * echo $badge->getDescription($data);
  * </code>
  *
  * @param array $data
  * @return string
  */
 public function getDescription(array $data = array())
 {
     if (!empty($data)) {
         $result = $this->description;
         foreach ($data as $placeholder => $value) {
             $placeholder = "{" . String::strtoupper($placeholder) . "}";
             $result = str_replace($placeholder, $value, $result);
         }
         return $result;
     } else {
         return $this->description;
     }
 }
Esempio n. 2
0
 /**
  * Load categories.
  *
  * <code>
  * $parentId = 2;
  *
  * $options = array(
  *    "offset" => 0,
  *    "limit" => 10,
  *    "order_by" => "a.name",
  *    "order_dir" => "DESC",
  * );
  *
  * $categories   = new Crowdfunding\Categories();
  * $categories->setDb(\JFactory::getDbo());
  *
  * $categories->load($parentId);
  * </code>
  * 
  * @param null|int $parentId Parent ID or "root".
  * @param array $options
  */
 public function load($parentId = null, $options = array())
 {
     $offset = isset($options["offset"]) ? $options["offset"] : 0;
     $limit = isset($options["limit"]) ? $options["limit"] : 0;
     $orderBy = isset($options["order_by"]) ? $options["order_by"] : "a.title";
     $orderDir = isset($options["order_dir"]) ? $options["order_dir"] : "ASC";
     $orderDir = String::strtoupper($orderDir);
     if (!in_array($orderDir, array("ASC", "DESC"))) {
         $orderDir = "ASC";
     }
     $query = $this->db->getQuery(true);
     $query->select("a.id, a.title, a.alias, a.description, a.params, " . $query->concatenate(array("a.id", "a.alias"), ":") . " AS slug")->from($this->db->quoteName("#__categories", "a"))->where("a.extension = " . $this->db->quote($this->_extension));
     if (!is_null($parentId)) {
         $query->where("a.parent_id = " . (int) $parentId);
     }
     $query->order($this->db->quoteName($orderBy) . " " . $orderDir);
     $this->db->setQuery($query, (int) $offset, (int) $limit);
     $this->data = (array) $this->db->loadAssocList("id");
 }