| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- /**
- * Guild skill group entity file.
- *
- * Creates the entity and makes it available.
- *
- * @author Iñigo Valentin <i@inigovalentin.com>
- * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
- * @package SWDB
- */
- require_once(PATH::ENTITY . "Entity.php");
- require_once(PATH::ENTITY . "Guild_Skill.php");
- /**
- * Guild skill group.
- *
- * Represents a category of guild skills.
- *
- * @category Entity
- */
- class Guild_Skill_Group extends Entity{
- /**
- * @var int Group ID.
- */
- private $id;
- /**
- * @var string Group name.
- */
- private $name;
- /**
- * @var string Group description.
- */
- private $description;
- /**
- * @var bool Internal flag to check if the group skills have been loaded into the entity.
- */
- private $flag_skills = false;
- /**
- * @var Guild_Skill[] Skills in the group.
- */
- private $skills = [];
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * skill group, populating it and it's items.
- *
- * @param int $id Skill group identifier.
- */
- public function __construct($id){
- $statement = get_context()->get_db()->prepare("
- SELECT
- id,
- name,
- description
- FROM guild_skill_group
- WHERE id = :id;
- ");
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->id = $r["id"];
- $this->name = HTML::e($r["name"]);
- $this->description = HTML::e($r["description"]);
- }
- }
- /**
- * Loads the skills in the group.
- *
- * Must be called only once before trying to get the skills. Sets the flag
- * {@link Guild_Skill_Group:$flag_skills} to true.
- */
- private function load_skills(){
- $statement = get_context()->get_db()->prepare("
- SELECT id
- FROM guild_skill
- WHERE skill_group = :id;
- ");
- $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->skills, new Guild_Skill($r["id"]));
- }
- $this->flag_skills = true;
- }
- /**
- * Retrieves the identifier of the skill group.
- *
- * @return int Group ID
- */
- public function get_id(){
- return $this->id;
- }
- /**
- * Retrieves the name of the skill_group.
- *
- * @return string Group name.
- */
- public function get_name(){
- return $this->name;
- }
- /**
- * Retrieves the description of the skill group.
- *
- * @return string Group description.
- */
- public function get_description(){
- return $this->description;
- }
- /**
- * Retrieves the skills in the group.
- *
- * @return Guild_Skill[] Skills in the group.
- */
- public function get_skills(){
- if (! $this->flag_skills){
- $this->load_skills();
- }
- return $this->skills;
- }
- /**
- * Gets the pathto the skill group image.
- *
- * @return string Image URL, or a fixed unknown image.
- */
- public function get_image(){
- return APPLICATION::img("SKILL_GUILD", $this->id);
- }
- }
|