43        $this->lng = 
$DIC->language();
 
   44        $this->db = 
$DIC->database();
 
   58        $sql = 
"SELECT * FROM badge_badge" .
 
   59            " WHERE parent_id = " . 
$ilDB->quote($a_parent_id);
 
   62            if ($a_filter[
"title"]) {
 
   63                $sql .= 
" AND " . 
$ilDB->like(
"title", 
"text", 
"%" . trim($a_filter[
"title"]) . 
"%");
 
   65            if ($a_filter[
"type"]) {
 
   66                $sql .= 
" AND type_id = " . 
$ilDB->quote($a_filter[
"type"], 
"integer");
 
   70        $set = 
$ilDB->query($sql .
 
   72        while ($row = 
$ilDB->fetchAssoc($set)) {
 
   74            $obj->importDBRow($row);
 
   89        $set = 
$ilDB->query(
"SELECT * FROM badge_badge" .
 
   90            " WHERE type_id = " . 
$ilDB->quote($a_type_id) .
 
   92        while ($row = 
$ilDB->fetchAssoc($set)) {
 
   94            $obj->importDBRow($row);
 
  105            return $handler->getTypeInstanceByUniqueId($this->
getTypeId());
 
  109    public function copy($a_new_parent_id)
 
  117        if ($this->
getId()) {
 
  136        $res = $raw = array();
 
  140        if ($a_filter[
"type"]) {
 
  141            $where .= 
" AND bb.type_id = " . 
$ilDB->quote($a_filter[
"type"], 
"text");
 
  143        if ($a_filter[
"title"]) {
 
  144            $where .= 
" AND " . 
$ilDB->like(
"bb.title", 
"text", 
"%" . $a_filter[
"title"] . 
"%");
 
  146        if ($a_filter[
"object"]) {
 
  147            $where .= 
" AND " . 
$ilDB->like(
"od.title", 
"text", 
"%" . $a_filter[
"object"] . 
"%");
 
  150        $set = 
$ilDB->query(
"SELECT bb.*, od.title parent_title, od.type parent_type" .
 
  151            " FROM badge_badge bb" .
 
  152            " JOIN object_data od ON (bb.parent_id = od.obj_id)" .
 
  153            " WHERE od.type <> " . 
$ilDB->quote(
"bdga", 
"text") .
 
  155        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  159        $set = 
$ilDB->query(
"SELECT bb.*, od.title parent_title, od.type parent_type" .
 
  160            " FROM badge_badge bb" .
 
  161            " JOIN object_data_del od ON (bb.parent_id = od.obj_id)" .
 
  162            " WHERE od.type <> " . 
$ilDB->quote(
"bdga", 
"text") .
 
  164        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  165            $row[
"deleted"] = 
true;
 
  169        foreach ($raw as $row) {
 
  185        $this->
id = (int) $a_id;
 
  195        $this->parent_id = (int) $a_id;
 
  205        $this->type_id = trim($a_id);
 
  215        $this->active = (bool) $a_value;
 
  225        $this->title = trim($a_value);
 
  235        $this->desc = trim($a_value);
 
  245        $this->criteria = trim($a_value);
 
  255        $this->valid = trim($a_value);
 
  265        if (is_array($a_value) &&
 
  269        $this->config = $a_value;
 
  279        $this->image = trim($a_value);
 
  293        if ($this->
getId() &&
 
  294            $a_upload_meta[
"tmp_name"]) {
 
  295            $this->
setImage($a_upload_meta[
"name"]);
 
  306        if (file_exists($a_file)) {
 
  316        if ($this->
getId()) {
 
  317            $suffix = strtolower(array_pop(explode(
".", $this->
getImage())));
 
  321                return "img" . $this->
getId() . 
"." . $suffix;
 
  338        $path = $storage->getAbsolutePath() . 
"/";
 
  341            $path .= $a_subdir . 
"/";
 
  343            if (!is_dir($path)) {
 
  360        $set = 
$ilDB->query(
"SELECT * FROM badge_badge" .
 
  361            " WHERE id = " . 
$ilDB->quote($a_id, 
"integer"));
 
  362        if (
$ilDB->numRows($set)) {
 
  363            $row = 
$ilDB->fetchAssoc($set);
 
  370        $this->
setId($a_row[
"id"]);
 
  380                ? unserialize($a_row[
"conf"])
 
  388        if ($this->
getId()) {
 
  397        $fields[
"id"] = array(
"integer", 
$id);
 
  398        $fields[
"parent_id"] = array(
"integer", $this->
getParentId());
 
  399        $fields[
"type_id"] = array(
"text", $this->
getTypeId());
 
  401        $ilDB->insert(
"badge_badge", $fields);
 
  408        if (!$this->
getId()) {
 
  417            array(
"id" => array(
"integer", $this->
getId()))
 
  421    public function delete()
 
  425        if (!$this->
getId()) {
 
  437        $ilDB->manipulate(
"DELETE FROM badge_badge" .
 
  438            " WHERE id = " . 
$ilDB->quote($this->getId(), 
"integer"));
 
  444            "active" => array(
"integer", $this->
isActive()),
 
  445            "title" => array(
"text", $this->
getTitle()),
 
  448            "image" => array(
"text", $this->
getImage()),
 
  449            "valid" => array(
"text", $this->
getValid()),
 
  470            if ($parent[
"type"]) {
 
  471                $parent_type = $parent[
"type"];
 
  472                $parent_title = $parent[
"title"];
 
  479            "type" => $parent_type,
 
  480            "title" => $parent_title,
 
  481            "deleted" => $deleted
 
  492        $json = 
new stdClass();
 
  493        $json->{
"@context"} = 
"https://w3id.org/openbadges/v1";
 
  494        $json->type = 
"BadgeClass";
 
  495        $json->id = $a_base_url . 
"class.json";
 
  498        $json->image = $a_base_url . 
"image." . $a_img_suffix;
 
  499        $json->criteria = $a_base_url . 
"criteria.txt";
 
  511        if (!file_exists($path . 
"class.json")) {
 
  512            $img_suffix = array_pop(explode(
".", $this->getImage()));
 
  514            $json = json_encode($this->prepareJson($base_url, $img_suffix));
 
  515            file_put_contents($path . 
"class.json", $json);
 
  518            copy($this->getImagePath(), $path . 
"image." . $img_suffix);
 
  520            file_put_contents($path . 
"criteria.txt", $this->getCriteria());
 
  523        return $base_url . 
"class.json";
 
  541        return $a_type->getCaption() . 
" (" .
 
  543                ? 
$lng->txt(
"badge_subtype_auto")
 
  544                : 
$lng->txt(
"badge_subtype_manual")) . 
")";
 
An exception for terminatinating execution or to throw for unit testing.
static deleteByBadgeId($a_badge_id)
static getInstance()
Constructor.
setConfiguration(array $a_value=null)
__construct($a_id=null)
Constructor.
uploadImage(array $a_upload_meta)
static getInstancesByParentId($a_parent_id, array $a_filter=null)
importImage($a_name, $a_file)
static getInstancesByType($a_type_id)
getImagePath($a_full_path=true)
static getExtendedTypeCaption(ilBadgeType $a_type)
prepareJson($a_base_url, $a_img_suffix)
getPropertiesForStorage()
importDBRow(array $a_row)
getFilePath($a_id, $a_subdir=null)
Init file system storage.
static getObjectInstances(array $a_filter=null)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
foreach($_POST as $key=> $value) $res