| Línea 29... | 
            Línea 29... | 
          
          
            | 29 | 
            /* Include required award criteria library. */
  | 
            29 | 
            /* Include required award criteria library. */
  | 
          
          
            | 30 | 
            require_once($CFG->dirroot . '/badges/criteria/award_criteria.php');
  | 
            30 | 
            require_once($CFG->dirroot . '/badges/criteria/award_criteria.php');
  | 
          
          
            | Línea 31... | 
            Línea 31... | 
          
          
            | 31 | 
             
  | 
            31 | 
             
  | 
          
          
            | 32 | 
            /* Include required user badge exporter */
  | 
            32 | 
            /* Include required user badge exporter */
  | 
          
          
            | - | 
               | 
            33 | 
            use core_badges\external\user_badge_exporter;
  | 
          
          
            | - | 
               | 
            34 | 
            /* Include required badge class exporter */
  | 
          
          
            | Línea 33... | 
            Línea 35... | 
          
          
            | 33 | 
            use core_badges\external\user_badge_exporter;
  | 
            35 | 
            use core_badges\external\badgeclass_exporter;
  | 
          
          
            | 34 | 
             
  | 
            36 | 
             
  | 
          
          
            | 35 | 
            /*
  | 
            37 | 
            /*
  | 
          
          
            | 36 | 
             * Number of records per page.
  | 
            38 | 
             * Number of records per page.
  | 
          
          
            | Línea 100... | 
            Línea 102... | 
          
          
            | 100 | 
             * URL of backpack. Custom ones can be added.
  | 
            102 | 
             * URL of backpack. Custom ones can be added.
  | 
          
          
            | 101 | 
             */
  | 
            103 | 
             */
  | 
          
          
            | 102 | 
            define('BADGRIO_BACKPACKAPIURL', 'https://api.badgr.io/v2');
  | 
            104 | 
            define('BADGRIO_BACKPACKAPIURL', 'https://api.badgr.io/v2');
  | 
          
          
            | 103 | 
            define('BADGRIO_BACKPACKWEBURL', 'https://badgr.io');
  | 
            105 | 
            define('BADGRIO_BACKPACKWEBURL', 'https://badgr.io');
  | 
          
          
            | Línea 104... | 
            Línea 106... | 
          
          
            | 104 | 
             
  | 
            106 | 
             
  | 
          
          
            | 105 | 
            /*
  | 
            107 | 
            /**
  | 
          
          
            | - | 
               | 
            108 | 
             * @deprecated since Moodle 4.5.
  | 
          
          
            | 106 | 
             * @deprecated since 3.9 (MDL-66357).
  | 
            109 | 
             * @todo Final deprecation in Moodle 6.0. See MDL-82332.
  | 
          
          
            | 107 | 
             */
  | 
            - | 
               | 
          
          
            | 108 | 
            define('BADGE_BACKPACKAPIURL', 'https://backpack.openbadges.org');
  | 
            110 | 
             */
  | 
          
          
            | Línea 109... | 
            Línea 111... | 
          
          
            | 109 | 
            define('BADGE_BACKPACKWEBURL', 'https://backpack.openbadges.org');
  | 
            111 | 
            define('OPEN_BADGES_V1', 1);
  | 
          
          
            | 110 | 
             
  | 
            112 | 
             
  | 
          
          
            | 111 | 
            /*
  | 
            113 | 
            /*
  | 
          
          
            | 112 | 
             * Open Badges specifications.
  | 
            - | 
               | 
          
          
            | 113 | 
             */
  | 
            114 | 
             * Open Badges specifications.
  | 
          
          
            | 114 | 
            define('OPEN_BADGES_V1', 1);
  | 
            115 | 
             */
  | 
          
          
            | Línea 115... | 
            Línea 116... | 
          
          
            | 115 | 
            define('OPEN_BADGES_V2', 2);
  | 
            116 | 
            define('OPEN_BADGES_V2', 2);
  | 
          
          
            | 116 | 
            define('OPEN_BADGES_V2P1', 2.1);
  | 
            117 | 
            define('OPEN_BADGES_V2P1', 2.1);
  | 
          
          
            | Línea 121... | 
            Línea 122... | 
          
          
            | 121 | 
            define('OPEN_BADGES_V2_CONTEXT', 'https://w3id.org/openbadges/v2');
  | 
            122 | 
            define('OPEN_BADGES_V2_CONTEXT', 'https://w3id.org/openbadges/v2');
  | 
          
          
            | 122 | 
            define('OPEN_BADGES_V2_TYPE_ASSERTION', 'Assertion');
  | 
            123 | 
            define('OPEN_BADGES_V2_TYPE_ASSERTION', 'Assertion');
  | 
          
          
            | 123 | 
            define('OPEN_BADGES_V2_TYPE_BADGE', 'BadgeClass');
  | 
            124 | 
            define('OPEN_BADGES_V2_TYPE_BADGE', 'BadgeClass');
  | 
          
          
            | 124 | 
            define('OPEN_BADGES_V2_TYPE_ISSUER', 'Issuer');
  | 
            125 | 
            define('OPEN_BADGES_V2_TYPE_ISSUER', 'Issuer');
  | 
          
          
            | 125 | 
            define('OPEN_BADGES_V2_TYPE_ENDORSEMENT', 'Endorsement');
  | 
            126 | 
            define('OPEN_BADGES_V2_TYPE_ENDORSEMENT', 'Endorsement');
  | 
          
          
            | 126 | 
            define('OPEN_BADGES_V2_TYPE_AUTHOR', 'Author');
  | 
            - | 
               | 
          
          
            | Línea 127... | 
            Línea 127... | 
          
          
            | 127 | 
             
  | 
            127 | 
             
  | 
          
          
            | 128 | 
            define('BACKPACK_MOVE_UP', -1);
  | 
            128 | 
            define('BACKPACK_MOVE_UP', -1);
  | 
          
          
            | Línea 129... | 
            Línea 129... | 
          
          
            | 129 | 
            define('BACKPACK_MOVE_DOWN', 1);
  | 
            129 | 
            define('BACKPACK_MOVE_DOWN', 1);
  | 
          
          
            | 130 | 
             
  | 
            130 | 
             
  | 
          
          
            | Línea -... | 
            Línea 131... | 
          
          
            | - | 
               | 
            131 | 
            // Global badge class has been moved to the component namespace.
  | 
          
          
            | - | 
               | 
            132 | 
            class_alias('\core_badges\badge', 'badge');
  | 
          
          
            | 131 | 
            // Global badge class has been moved to the component namespace.
  | 
            133 | 
             
  | 
          
          
            | 132 | 
            class_alias('\core_badges\badge', 'badge');
  | 
            134 | 
            use core_badges\png_metadata_handler;
  | 
          
          
            | 133 | 
             
  | 
            135 | 
             
  | 
          
          
            | 134 | 
            /**
  | 
            136 | 
            /**
  | 
          
          
            | 135 | 
             * Sends notifications to users about awarded badges.
  | 
            137 | 
             * Sends notifications to users about awarded badges.
  | 
          
          
            | Línea 420... | 
            Línea 422... | 
          
          
            | 420 | 
             * @param stdClass $badge
  | 
            422 | 
             * @param stdClass $badge
  | 
          
          
            | 421 | 
             * @param stdClass $user
  | 
            423 | 
             * @param stdClass $user
  | 
          
          
            | 422 | 
             * @return object
  | 
            424 | 
             * @return object
  | 
          
          
            | 423 | 
             */
  | 
            425 | 
             */
  | 
          
          
            | 424 | 
            function badges_prepare_badge_for_external(stdClass $badge, stdClass $user): object {
  | 
            426 | 
            function badges_prepare_badge_for_external(stdClass $badge, stdClass $user): object {
  | 
          
          
            | 425 | 
                global $PAGE, $USER;
  | 
            427 | 
                global $PAGE, $SITE, $USER;
  | 
          
          
            | 426 | 
                if ($badge->type == BADGE_TYPE_SITE) {
  | 
            428 | 
                if ($badge->type == BADGE_TYPE_SITE) {
  | 
          
          
            | 427 | 
                    $context = context_system::instance();
  | 
            429 | 
                    $context = context_system::instance();
  | 
          
          
            | 428 | 
                } else {
  | 
            430 | 
                } else {
  | 
          
          
            | 429 | 
                    $context = context_course::instance($badge->courseid);
  | 
            431 | 
                    $context = context_course::instance($badge->courseid);
  | 
          
          
            | 430 | 
                }
  | 
            432 | 
                }
  | 
          
          
            | Línea 442... | 
            Línea 444... | 
          
          
            | 442 | 
                        'uniquehash'    => $badge->uniquehash,
  | 
            444 | 
                        'uniquehash'    => $badge->uniquehash,
  | 
          
          
            | 443 | 
                        'dateissued'    => $badge->dateissued,
  | 
            445 | 
                        'dateissued'    => $badge->dateissued,
  | 
          
          
            | 444 | 
                        'dateexpire'    => $badge->dateexpire,
  | 
            446 | 
                        'dateexpire'    => $badge->dateexpire,
  | 
          
          
            | 445 | 
                        'version'       => $badge->version,
  | 
            447 | 
                        'version'       => $badge->version,
  | 
          
          
            | 446 | 
                        'language'      => $badge->language,
  | 
            448 | 
                        'language'      => $badge->language,
  | 
          
          
            | 447 | 
                        'imageauthorname'  => $badge->imageauthorname,
  | 
            - | 
               | 
          
          
            | 448 | 
                        'imageauthoremail' => $badge->imageauthoremail,
  | 
            - | 
               | 
          
          
            | 449 | 
                        'imageauthorurl'   => $badge->imageauthorurl,
  | 
            - | 
               | 
          
          
            | 450 | 
                        'imagecaption'     => $badge->imagecaption,
  | 
            449 | 
                        'imagecaption'     => $badge->imagecaption,
  | 
          
          
            | 451 | 
                    ];
  | 
            450 | 
                    ];
  | 
          
          
            | 452 | 
                }
  | 
            451 | 
                }
  | 
          
          
            | Línea -... | 
            Línea 452... | 
          
          
            | - | 
               | 
            452 | 
             
  | 
          
          
            | - | 
               | 
            453 | 
                // Course.
  | 
          
          
            | - | 
               | 
            454 | 
                if ($badge->type == BADGE_TYPE_COURSE) {
  | 
          
          
            | - | 
               | 
            455 | 
                    $course = get_course($context->instanceid);
  | 
          
          
            | - | 
               | 
            456 | 
                    $badge->coursefullname = \core_external\util::format_string($course->fullname, $context);
  | 
          
          
            | - | 
               | 
            457 | 
                }
  | 
          
          
            | - | 
               | 
            458 | 
             
  | 
          
          
            | - | 
               | 
            459 | 
                // Recipient (the badge was awarded to this person).
  | 
          
          
            | - | 
               | 
            460 | 
                $badge->recipientid = $user->id;
  | 
          
          
            | - | 
               | 
            461 | 
                if ($user->deleted) {
  | 
          
          
            | - | 
               | 
            462 | 
                    $strdata = new stdClass();
  | 
          
          
            | - | 
               | 
            463 | 
                    $strdata->user = fullname($user);
  | 
          
          
            | - | 
               | 
            464 | 
                    $strdata->site = format_string($SITE->fullname, true, ['context' => context_system::instance()]);
  | 
          
          
            | - | 
               | 
            465 | 
                    $badge->recipientfullname = get_string('error:userdeleted', 'badges', $strdata);
  | 
          
          
            | - | 
               | 
            466 | 
                } else {
  | 
          
          
            | - | 
               | 
            467 | 
                    $badge->recipientfullname = fullname($user);
  | 
          
          
            | - | 
               | 
            468 | 
                }
  | 
          
          
            | 453 | 
             
  | 
            469 | 
             
  | 
          
          
            | 454 | 
                // Create a badge instance to be able to get the endorsement and other info.
  | 
            470 | 
                // Create a badge instance to be able to get the endorsement and other info.
  | 
          
          
            | 455 | 
                $badgeinstance = new badge($badge->id);
  | 
            471 | 
                $badgeinstance = new badge($badge->id);
  | 
          
          
            | 456 | 
                $endorsement   = $badgeinstance->get_endorsement();
  | 
            - | 
               | 
          
          
            | 457 | 
                $alignments    = $badgeinstance->get_alignments();
  | 
            472 | 
                $endorsement   = $badgeinstance->get_endorsement();
  | 
          
          
            | - | 
               | 
            473 | 
                $relatedbadges = $badgeinstance->get_related_badges();
  | 
          
          
            | - | 
               | 
            474 | 
                $alignments    = [];
  | 
          
          
            | - | 
               | 
            475 | 
                foreach ($badgeinstance->get_alignments() as $alignment) {
  | 
          
          
            | - | 
               | 
            476 | 
                    $alignmentobj = (object) [
  | 
          
          
            | - | 
               | 
            477 | 
                        'id' => $alignment->id,
  | 
          
          
            | - | 
               | 
            478 | 
                        'badgeid' => $alignment->badgeid,
  | 
          
          
            | - | 
               | 
            479 | 
                        'targetName' => $alignment->targetname,
  | 
          
          
            | - | 
               | 
            480 | 
                        'targetUrl' => $alignment->targeturl,
  | 
          
          
            | - | 
               | 
            481 | 
                    ];
  | 
          
          
            | - | 
               | 
            482 | 
                    // Include only the properties visible by the user.
  | 
          
          
            | - | 
               | 
            483 | 
                    if ($canconfiguredetails) {
  | 
          
          
            | - | 
               | 
            484 | 
                        $alignmentobj->targetDescription = $alignment->targetdescription;
  | 
          
          
            | - | 
               | 
            485 | 
                        $alignmentobj->targetFramework = $alignment->targetframework;
  | 
          
          
            | - | 
               | 
            486 | 
                        $alignmentobj->targetCode = $alignment->targetcode;
  | 
          
          
            | - | 
               | 
            487 | 
                    }
  | 
          
          
            | - | 
               | 
            488 | 
                    $alignments[] = $alignmentobj;
  | 
          
          
            | Línea 458... | 
            Línea 489... | 
          
          
            | 458 | 
                $relatedbadges = $badgeinstance->get_related_badges();
  | 
            489 | 
                }
  | 
          
          
            | 459 | 
             
  | 
            490 | 
             
  | 
          
          
            | 460 | 
                if (!$canconfiguredetails) {
  | 
            - | 
               | 
          
          
            | 461 | 
                    // Return only the properties visible by the user.
  | 
            - | 
               | 
          
          
            | 462 | 
                    if (!empty($alignments)) {
  | 
            - | 
               | 
          
          
            | 463 | 
                        foreach ($alignments as $alignment) {
  | 
            - | 
               | 
          
          
            | 464 | 
                            unset($alignment->targetdescription);
  | 
            - | 
               | 
          
          
            | 465 | 
                            unset($alignment->targetframework);
  | 
            - | 
               | 
          
          
            | 466 | 
                            unset($alignment->targetcode);
  | 
            - | 
               | 
          
          
            | 467 | 
                        }
  | 
            - | 
               | 
          
          
            | 468 | 
                    }
  | 
            491 | 
                if (!$canconfiguredetails) {
  | 
          
          
            | 469 | 
             
  | 
            492 | 
                    // Return only the properties visible by the user.
  | 
          
          
            | 470 | 
                    if (!empty($relatedbadges)) {
  | 
            493 | 
                    if (!empty($relatedbadges)) {
  | 
          
          
            | 471 | 
                        foreach ($relatedbadges as $relatedbadge) {
  | 
            494 | 
                        foreach ($relatedbadges as $relatedbadge) {
  | 
          
          
            | 472 | 
                            unset($relatedbadge->version);
  | 
            495 | 
                            unset($relatedbadge->version);
  | 
          
          
            | Línea 486... | 
            Línea 509... | 
          
          
            | 486 | 
                $exporter = new user_badge_exporter($badge, $related);
  | 
            509 | 
                $exporter = new user_badge_exporter($badge, $related);
  | 
          
          
            | 487 | 
                return $exporter->export($PAGE->get_renderer('core'));
  | 
            510 | 
                return $exporter->export($PAGE->get_renderer('core'));
  | 
          
          
            | 488 | 
            }
  | 
            511 | 
            }
  | 
          
          
            | Línea 489... | 
            Línea 512... | 
          
          
            | 489 | 
             
  | 
            512 | 
             
  | 
          
          
            | - | 
               | 
            513 | 
            /**
  | 
          
          
            | - | 
               | 
            514 | 
             * Prepare badgeclass for external functions.
  | 
          
          
            | - | 
               | 
            515 | 
             * @param core_badges\output\badgeclass $badgeclass
  | 
          
          
            | - | 
               | 
            516 | 
             * @return stdClass
  | 
          
          
            | - | 
               | 
            517 | 
             */
  | 
          
          
            | - | 
               | 
            518 | 
            function badges_prepare_badgeclass_for_external(core_badges\output\badgeclass $badgeclass): stdClass {
  | 
          
          
            | - | 
               | 
            519 | 
                global $PAGE;
  | 
          
          
            | - | 
               | 
            520 | 
                $context = $badgeclass->context;
  | 
          
          
            | - | 
               | 
            521 | 
                $canconfiguredetails = has_capability('moodle/badges:configuredetails', $context);
  | 
          
          
            | - | 
               | 
            522 | 
             
  | 
          
          
            | - | 
               | 
            523 | 
                $badgeurl = new \moodle_url('/badges/badgeclass.php', [
  | 
          
          
            | - | 
               | 
            524 | 
                    'id' => $badgeclass->badge->id,
  | 
          
          
            | - | 
               | 
            525 | 
                ]);
  | 
          
          
            | - | 
               | 
            526 | 
                $badgeurl = $badgeurl->out(false);
  | 
          
          
            | - | 
               | 
            527 | 
                $file = \moodle_url::make_webservice_pluginfile_url(
  | 
          
          
            | - | 
               | 
            528 | 
                    $badgeclass->context->id,
  | 
          
          
            | - | 
               | 
            529 | 
                    'badges',
  | 
          
          
            | - | 
               | 
            530 | 
                    'badgeimage',
  | 
          
          
            | - | 
               | 
            531 | 
                    $badgeclass->badge->id,
  | 
          
          
            | - | 
               | 
            532 | 
                    '/',
  | 
          
          
            | - | 
               | 
            533 | 
                    'f3'
  | 
          
          
            | - | 
               | 
            534 | 
                );
  | 
          
          
            | - | 
               | 
            535 | 
                $image = $file->out(false);
  | 
          
          
            | - | 
               | 
            536 | 
             
  | 
          
          
            | - | 
               | 
            537 | 
                $badge = (object) [
  | 
          
          
            | - | 
               | 
            538 | 
                    'id'            => $badgeurl,
  | 
          
          
            | - | 
               | 
            539 | 
                    'name'          => $badgeclass->badge->name,
  | 
          
          
            | - | 
               | 
            540 | 
                    'type'          => OPEN_BADGES_V2_TYPE_BADGE,
  | 
          
          
            | - | 
               | 
            541 | 
                    'description'   => $badgeclass->badge->description,
  | 
          
          
            | - | 
               | 
            542 | 
                    'issuer'        => $badgeclass->badge->issuername,
  | 
          
          
            | - | 
               | 
            543 | 
                    'hostedUrl'     => $badgeclass->badge->issuerurl,
  | 
          
          
            | - | 
               | 
            544 | 
                    'image'         => $image,
  | 
          
          
            | - | 
               | 
            545 | 
                ];
  | 
          
          
            | - | 
               | 
            546 | 
             
  | 
          
          
            | - | 
               | 
            547 | 
                // Course.
  | 
          
          
            | - | 
               | 
            548 | 
                if ($badgeclass->badge->type == BADGE_TYPE_COURSE) {
  | 
          
          
            | - | 
               | 
            549 | 
                    $course = get_course($badgeclass->badge->courseid);
  | 
          
          
            | - | 
               | 
            550 | 
                    $badge->coursefullname = \core_external\util::format_string($course->fullname, $context);
  | 
          
          
            | - | 
               | 
            551 | 
                    if ($canconfiguredetails) {
  | 
          
          
            | - | 
               | 
            552 | 
                        $badge->courseid = $course->id;
  | 
          
          
            | - | 
               | 
            553 | 
                    }
  | 
          
          
            | - | 
               | 
            554 | 
                }
  | 
          
          
            | - | 
               | 
            555 | 
             
  | 
          
          
            | - | 
               | 
            556 | 
                // Create a badge instance to be able to get the endorsement and other info.
  | 
          
          
            | - | 
               | 
            557 | 
                $badgeinstance = new badge($badgeclass->badge->id);
  | 
          
          
            | - | 
               | 
            558 | 
                $endorsement   = $badgeinstance->get_endorsement();
  | 
          
          
            | - | 
               | 
            559 | 
                $relatedbadges = $badgeinstance->get_related_badges();
  | 
          
          
            | - | 
               | 
            560 | 
                $alignments = [];
  | 
          
          
            | - | 
               | 
            561 | 
                foreach ($badgeinstance->get_alignments() as $alignment) {
  | 
          
          
            | - | 
               | 
            562 | 
                    $alignmentobj = (object) [
  | 
          
          
            | - | 
               | 
            563 | 
                        'id' => $alignment->id,
  | 
          
          
            | - | 
               | 
            564 | 
                        'badgeid' => $alignment->badgeid,
  | 
          
          
            | - | 
               | 
            565 | 
                        'targetName' => $alignment->targetname,
  | 
          
          
            | - | 
               | 
            566 | 
                        'targetUrl' => $alignment->targeturl,
  | 
          
          
            | - | 
               | 
            567 | 
                    ];
  | 
          
          
            | - | 
               | 
            568 | 
                    // Include only the properties visible by the user.
  | 
          
          
            | - | 
               | 
            569 | 
                    if ($canconfiguredetails) {
  | 
          
          
            | - | 
               | 
            570 | 
                        $alignmentobj->targetDescription = $alignment->targetdescription;
  | 
          
          
            | - | 
               | 
            571 | 
                        $alignmentobj->targetFramework = $alignment->targetframework;
  | 
          
          
            | - | 
               | 
            572 | 
                        $alignmentobj->targetCode = $alignment->targetcode;
  | 
          
          
            | - | 
               | 
            573 | 
                    }
  | 
          
          
            | - | 
               | 
            574 | 
                    $alignments[] = $alignmentobj;
  | 
          
          
            | - | 
               | 
            575 | 
                }
  | 
          
          
            | - | 
               | 
            576 | 
             
  | 
          
          
            | - | 
               | 
            577 | 
                if (!$canconfiguredetails) {
  | 
          
          
            | - | 
               | 
            578 | 
                    // Return only the properties visible by the user.
  | 
          
          
            | - | 
               | 
            579 | 
                    if (!empty($relatedbadges)) {
  | 
          
          
            | - | 
               | 
            580 | 
                        foreach ($relatedbadges as $relatedbadge) {
  | 
          
          
            | - | 
               | 
            581 | 
                            unset($relatedbadge->version);
  | 
          
          
            | - | 
               | 
            582 | 
                            unset($relatedbadge->language);
  | 
          
          
            | - | 
               | 
            583 | 
                            unset($relatedbadge->type);
  | 
          
          
            | - | 
               | 
            584 | 
                        }
  | 
          
          
            | - | 
               | 
            585 | 
                    }
  | 
          
          
            | - | 
               | 
            586 | 
                }
  | 
          
          
            | - | 
               | 
            587 | 
             
  | 
          
          
            | - | 
               | 
            588 | 
                $related = [
  | 
          
          
            | - | 
               | 
            589 | 
                    'context'       => $context,
  | 
          
          
            | - | 
               | 
            590 | 
                    'endorsement'   => $endorsement ? $endorsement : null,
  | 
          
          
            | - | 
               | 
            591 | 
                    'relatedbadges' => $relatedbadges,
  | 
          
          
            | - | 
               | 
            592 | 
                ];
  | 
          
          
            | - | 
               | 
            593 | 
             
  | 
          
          
            | - | 
               | 
            594 | 
                if (!empty($alignments)) {
  | 
          
          
            | - | 
               | 
            595 | 
                    $related['alignment'] = $alignments;
  | 
          
          
            | - | 
               | 
            596 | 
                }
  | 
          
          
            | - | 
               | 
            597 | 
             
  | 
          
          
            | - | 
               | 
            598 | 
                $exporter = new badgeclass_exporter($badge, $related);
  | 
          
          
            | - | 
               | 
            599 | 
                return $exporter->export($PAGE->get_renderer('core', 'badges'));
  | 
          
          
            | - | 
               | 
            600 | 
            }
  | 
          
          
            | - | 
               | 
            601 | 
             
  | 
          
          
            | 490 | 
            /**
  | 
            602 | 
            /**
  | 
          
          
            | 491 | 
             * Extends the course administration navigation with the Badges page
  | 
            603 | 
             * Extends the course administration navigation with the Badges page
  | 
          
          
            | 492 | 
             *
  | 
            604 | 
             *
  | 
          
          
            | 493 | 
             * @param navigation_node $coursenode
  | 
            605 | 
             * @param navigation_node $coursenode
  | 
          
          
            | 494 | 
             * @param object $course
  | 
            606 | 
             * @param object $course
  | 
          
          
            | Línea 515... | 
            Línea 627... | 
          
          
            | 515 | 
             
  | 
            627 | 
             
  | 
          
          
            | 516 | 
                    $coursenode->get('coursebadges')->add(get_string('managebadges', 'badges'), $url,
  | 
            628 | 
                    $coursenode->get('coursebadges')->add(get_string('managebadges', 'badges'), $url,
  | 
          
          
            | Línea 517... | 
            Línea 629... | 
          
          
            | 517 | 
                        navigation_node::TYPE_SETTING, null, 'coursebadges');
  | 
            629 | 
                        navigation_node::TYPE_SETTING, null, 'coursebadges');
  | 
          
          
            | 518 | 
             
  | 
            630 | 
             
  | 
          
          
            | Línea 519... | 
            Línea 631... | 
          
          
            | 519 | 
                    if (has_capability('moodle/badges:createbadge', $coursecontext)) {
  | 
            631 | 
                    if (has_capability('moodle/badges:createbadge', $coursecontext)) {
  | 
          
          
            | 520 | 
                        $url = new moodle_url('/badges/newbadge.php', array('type' => BADGE_TYPE_COURSE, 'id' => $course->id));
  | 
            632 | 
                        $url = new moodle_url('/badges/edit.php', ['action' => 'new', 'courseid' => $course->id]);
  | 
          
          
            | 521 | 
             
  | 
            633 | 
             
  | 
          
          
            | 522 | 
                        $coursenode->get('coursebadges')->add(get_string('newbadge', 'badges'), $url,
  | 
            634 | 
                        $coursenode->get('coursebadges')->add(get_string('newbadge', 'badges'), $url,
  | 
          
          
            | Línea 563... | 
            Línea 675... | 
          
          
            | 563 | 
                require_once($CFG->libdir. '/gdlib.php');
  | 
            675 | 
                require_once($CFG->libdir. '/gdlib.php');
  | 
          
          
            | Línea 564... | 
            Línea 676... | 
          
          
            | 564 | 
             
  | 
            676 | 
             
  | 
          
          
            | 565 | 
                if (!empty($CFG->gdversion)) {
  | 
            677 | 
                if (!empty($CFG->gdversion)) {
  | 
          
          
            | 566 | 
                    process_new_icon($badge->get_context(), 'badges', 'badgeimage', $badge->id, $iconfile, true);
  | 
            678 | 
                    process_new_icon($badge->get_context(), 'badges', 'badgeimage', $badge->id, $iconfile, true);
  | 
          
          
            | 567 | 
                    @unlink($iconfile);
  | 
            - | 
               | 
          
          
            | 568 | 
             
  | 
            - | 
               | 
          
          
            | 569 | 
                    // Clean up file draft area after badge image has been saved.
  | 
            - | 
               | 
          
          
            | 570 | 
                    $context = context_user::instance($USER->id, MUST_EXIST);
  | 
            - | 
               | 
          
          
            | 571 | 
                    $fs = get_file_storage();
  | 
            - | 
               | 
          
          
            | 572 | 
                    $fs->delete_area_files($context->id, 'user', 'draft');
  | 
            679 | 
                    @unlink($iconfile);
  | 
          
          
            | 573 | 
                }
  | 
            680 | 
                }
  | 
          
          
            | Línea 574... | 
            Línea 681... | 
          
          
            | 574 | 
            }
  | 
            681 | 
            }
  | 
          
          
            | 575 | 
             
  | 
            682 | 
             
  | 
          
          
            | Línea 600... | 
            Línea 707... | 
          
          
            | 600 | 
             * @param boolean $pathhash Return file pathhash instead of image url (optional).
  | 
            707 | 
             * @param boolean $pathhash Return file pathhash instead of image url (optional).
  | 
          
          
            | 601 | 
             * @return string|moodle_url|null Returns either new file path hash or new file URL
  | 
            708 | 
             * @return string|moodle_url|null Returns either new file path hash or new file URL
  | 
          
          
            | 602 | 
             */
  | 
            709 | 
             */
  | 
          
          
            | 603 | 
            function badges_bake($hash, $badgeid, $userid = 0, $pathhash = false) {
  | 
            710 | 
            function badges_bake($hash, $badgeid, $userid = 0, $pathhash = false) {
  | 
          
          
            | 604 | 
                global $CFG, $USER;
  | 
            711 | 
                global $CFG, $USER;
  | 
          
          
            | 605 | 
                require_once(__DIR__ . '/../badges/lib/bakerlib.php');
  | 
            - | 
               | 
          
          
            | Línea 606... | 
            Línea 712... | 
          
          
            | 606 | 
             
  | 
            712 | 
             
  | 
          
          
            | 607 | 
                $badge = new badge($badgeid);
  | 
            713 | 
                $badge = new badge($badgeid);
  | 
          
          
            | 608 | 
                $badge_context = $badge->get_context();
  | 
            714 | 
                $badge_context = $badge->get_context();
  | 
          
          
            | 609 | 
                $userid = ($userid) ? $userid : $USER->id;
  | 
            715 | 
                $userid = ($userid) ? $userid : $USER->id;
  | 
          
          
            | Línea 612... | 
            Línea 718... | 
          
          
            | 612 | 
                $fs = get_file_storage();
  | 
            718 | 
                $fs = get_file_storage();
  | 
          
          
            | 613 | 
                if (!$fs->file_exists($user_context->id, 'badges', 'userbadge', $badge->id, '/', $hash . '.png')) {
  | 
            719 | 
                if (!$fs->file_exists($user_context->id, 'badges', 'userbadge', $badge->id, '/', $hash . '.png')) {
  | 
          
          
            | 614 | 
                    if ($file = $fs->get_file($badge_context->id, 'badges', 'badgeimage', $badge->id, '/', 'f3.png')) {
  | 
            720 | 
                    if ($file = $fs->get_file($badge_context->id, 'badges', 'badgeimage', $badge->id, '/', 'f3.png')) {
  | 
          
          
            | 615 | 
                        $contents = $file->get_content();
  | 
            721 | 
                        $contents = $file->get_content();
  | 
          
          
            | Línea 616... | 
            Línea 722... | 
          
          
            | 616 | 
             
  | 
            722 | 
             
  | 
          
          
            | 617 | 
                        $filehandler = new PNG_MetaDataHandler($contents);
  | 
            723 | 
                        $filehandler = new png_metadata_handler($contents);
  | 
          
          
            | 618 | 
                        // For now, the site backpack OB version will be used as default.
  | 
            724 | 
                        // For now, the site backpack OB version will be used as default.
  | 
          
          
            | 619 | 
                        $obversion = badges_open_badges_backpack_api();
  | 
            725 | 
                        $obversion = badges_open_badges_backpack_api();
  | 
          
          
            | 620 | 
                        $assertion = new core_badges_assertion($hash, $obversion);
  | 
            726 | 
                        $assertion = new core_badges_assertion($hash, $obversion);
  | 
          
          
            | 621 | 
                        $assertionjson = json_encode($assertion->get_badge_assertion());
  | 
            727 | 
                        $assertionjson = json_encode($assertion->get_badge_assertion());
  | 
          
          
            | Línea 1098... | 
            Línea 1204... | 
          
          
            | 1098 | 
             *
  | 
            1204 | 
             *
  | 
          
          
            | 1099 | 
             * @return array(version)
  | 
            1205 | 
             * @return array(version)
  | 
          
          
            | 1100 | 
             */
  | 
            1206 | 
             */
  | 
          
          
            | 1101 | 
            function badges_get_badge_api_versions() {
  | 
            1207 | 
            function badges_get_badge_api_versions() {
  | 
          
          
            | 1102 | 
                return [
  | 
            1208 | 
                return [
  | 
          
          
            | 1103 | 
                    (string)OPEN_BADGES_V1 => get_string('openbadgesv1', 'badges'),
  | 
            - | 
               | 
          
          
            | 1104 | 
                    (string)OPEN_BADGES_V2 => get_string('openbadgesv2', 'badges'),
  | 
            1209 | 
                    (string)OPEN_BADGES_V2 => get_string('openbadgesv2', 'badges'),
  | 
          
          
            | 1105 | 
                    (string)OPEN_BADGES_V2P1 => get_string('openbadgesv2p1', 'badges')
  | 
            1210 | 
                    (string)OPEN_BADGES_V2P1 => get_string('openbadgesv2p1', 'badges')
  | 
          
          
            | 1106 | 
                ];
  | 
            1211 | 
                ];
  | 
          
          
            | 1107 | 
            }
  | 
            1212 | 
            }
  |