/**
  * Convenience method to instantiate the event.
  *
  * @param template $template The template.
  * @return self
  */
 public static final function create_from_template(template $template)
 {
     if (!$template->get_id()) {
         throw new \coding_exception('The template ID must be set.');
     }
     $event = static::create(array('contextid' => $template->get_contextid(), 'objectid' => $template->get_id()));
     $event->add_record_snapshot(template::TABLE, $template->to_record());
     return $event;
 }
 /**
  * Construct this renderable.
  *
  * @param template $template The learning plan template.
  * @param context $pagecontext The page context.
  */
 public function __construct(template $template, context $pagecontext)
 {
     $this->pagecontext = $pagecontext;
     $this->template = $template;
     $this->templatestatistics = new template_statistics($template->get_id());
     $this->competencies = api::list_competencies_in_template($template);
     $this->canmanagecompetencyframeworks = has_capability('moodle/competency:competencymanage', $this->pagecontext);
     $this->canmanagetemplatecompetencies = has_capability('moodle/competency:templatemanage', $this->pagecontext);
     $this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $this->pagecontext->id));
 }
示例#3
0
 /**
  * Sets up the table.
  *
  * @param string $uniqueid Unique id of table.
  * @param \core_competency\template $template The template.
  */
 public function __construct($uniqueid, \core_competency\template $template)
 {
     parent::__construct($uniqueid);
     // This object should not be used without the right permissions.
     if (!$template->can_read()) {
         throw new \required_capability_exception($template->get_context(), 'moodle/competency:templateview', 'nopermissions', '');
     }
     // Set protected properties.
     $this->template = $template;
     $this->context = $this->template->get_context();
     // Define columns in the table.
     $this->define_table_columns();
     // Define configs.
     $this->define_table_configs();
 }
示例#4
0
文件: lib.php 项目: dg711/moodle
/**
 * This function extends the category navigation to add learning plan links.
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param context $coursecategorycontext The context of the course category
 */
function tool_lp_extend_navigation_category_settings($navigation, $coursecategorycontext)
{
    if (!get_config('core_competency', 'enabled')) {
        return false;
    }
    // We check permissions before renderring the links.
    $templatereadcapability = \core_competency\template::can_read_context($coursecategorycontext);
    $competencyreadcapability = \core_competency\competency_framework::can_read_context($coursecategorycontext);
    if (!$templatereadcapability && !$competencyreadcapability) {
        return false;
    }
    // The link to the learning plan page.
    if ($templatereadcapability) {
        $title = get_string('templates', 'tool_lp');
        $path = new moodle_url("/admin/tool/lp/learningplans.php", array('pagecontextid' => $coursecategorycontext->id));
        $settingsnode = navigation_node::create($title, $path, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/competencies', ''));
        if (isset($settingsnode)) {
            $navigation->add_node($settingsnode);
        }
    }
    // The link to the competency frameworks page.
    if ($competencyreadcapability) {
        $title = get_string('competencyframeworks', 'tool_lp');
        $path = new moodle_url("/admin/tool/lp/competencyframeworks.php", array('pagecontextid' => $coursecategorycontext->id));
        $settingsnode = navigation_node::create($title, $path, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/competencies', ''));
        if (isset($settingsnode)) {
            $navigation->add_node($settingsnode);
        }
    }
}
 /**
  * Export this data so it can be used as the context for a mustache template.
  *
  * @param renderer_base $output Renderer base.
  * @return stdClass
  */
 public function export_for_template(renderer_base $output)
 {
     $data = new stdClass();
     $data->pagecontextid = $this->pagecontext->id;
     $data->templates = array();
     foreach ($this->templates as $template) {
         $exporter = new template_exporter($template);
         $data->templates[] = $exporter->export($output);
     }
     $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
     $data->navigation = array();
     foreach ($this->navigation as $button) {
         $data->navigation[] = $output->render($button);
     }
     $data->canmanage = template::can_manage_context($this->pagecontext);
     return $data;
 }
示例#6
0
文件: api_test.php 项目: dg711/moodle
 public function test_delete_template_unlink_plans()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $u1 = $dg->create_user();
     $f = $lpg->create_framework();
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $f->get_id()));
     $c2 = $lpg->create_competency(array('competencyframeworkid' => $f->get_id()));
     $tpl = $lpg->create_template();
     $tplc1 = $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $c1->get_id(), 'sortorder' => 1));
     $tplc2 = $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $c2->get_id(), 'sortorder' => 2));
     $p1 = $lpg->create_plan(array('templateid' => $tpl->get_id(), 'userid' => $u1->id));
     // Check pre-test.
     $this->assertTrue(\core_competency\template::record_exists($tpl->get_id()));
     $this->assertEquals(2, \core_competency\template_competency::count_competencies($tpl->get_id()));
     $this->assertEquals(1, count(\core_competency\plan::get_records(array('templateid' => $tpl->get_id()))));
     $result = api::delete_template($tpl->get_id(), false);
     $this->assertTrue($result);
     // Check that the template does not exist anymore.
     $this->assertFalse(\core_competency\template::record_exists($tpl->get_id()));
     // Check that associated competencies are also deleted.
     $this->assertEquals(0, \core_competency\template_competency::count_competencies($tpl->get_id()));
     // Check that associated plan still exist but unlink from template.
     $plans = \core_competency\plan::get_records(array('id' => $p1->get_id()));
     $this->assertEquals(1, count($plans));
     $this->assertEquals($plans[0]->get_origtemplateid(), $tpl->get_id());
     $this->assertNull($plans[0]->get_templateid());
 }
示例#7
0
 /**
  * Template event viewed.
  *
  * Requires moodle/competency:templateview capability at the system context.
  *
  * @param mixed $templateorid The id or the template.
  * @return boolean
  */
 public static function template_viewed($templateorid)
 {
     static::require_enabled();
     $template = $templateorid;
     if (!is_object($template)) {
         $template = new template($template);
     }
     // First we do a permissions check.
     if (!$template->can_read()) {
         throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview', 'nopermissions', '');
     }
     // Trigger a template viewed event.
     \core\event\competency_template_viewed::create_from_template($template)->trigger();
     return true;
 }
示例#8
0
文件: lib.php 项目: evltuma/moodle
 /**
  * Create a template.
  *
  * @param array|stdClass $record
  * @return template
  */
 public function create_template($record = null)
 {
     $this->templatecount++;
     $i = $this->templatecount;
     $record = (object) $record;
     if (!isset($record->shortname)) {
         $record->shortname = "Template shortname {$i}";
     }
     if (!isset($record->description)) {
         $record->description = "Template {$i} description ";
     }
     if (!isset($record->contextid)) {
         $record->contextid = context_system::instance()->id;
     }
     $template = new template(0, $record);
     $template->create();
     return $template;
 }
示例#9
0
 /**
  * Set-up a template page.
  *
  * Example:
  * list($title, $subtitle) = page_helper::setup_for_template($pagecontextid, $url, $template, $pagetitle);
  * echo $OUTPUT->heading($title);
  * echo $OUTPUT->heading($subtitle, 3);
  *
  * @param  int $pagecontextid The page context ID.
  * @param  moodle_url $url The current page.
  * @param  \core_competency\template $template The template, if any.
  * @param  string $subtitle The title of the subpage, if any.
  * @param  string $returntype The desired return page.
  * @return array With the following:
  *               - Page title
  *               - Page sub title
  *               - Return URL
  */
 public static function setup_for_template($pagecontextid, moodle_url $url, $template = null, $subtitle = '', $returntype = null)
 {
     global $PAGE, $SITE;
     $pagecontext = context::instance_by_id($pagecontextid);
     $context = $pagecontext;
     if (!empty($template)) {
         $context = $template->get_context();
     }
     $templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
     $templateurl = null;
     if ($template) {
         $templateurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', ['templateid' => $template->get_id(), 'pagecontextid' => $pagecontextid]);
     }
     $returnurl = $templatesurl;
     if ($returntype != 'templates' && $templateurl) {
         $returnurl = $templateurl;
     }
     $PAGE->navigation->override_active_url($templatesurl);
     $PAGE->set_context($pagecontext);
     if (!empty($template)) {
         $title = format_string($template->get_shortname(), true, array('context' => $context));
     } else {
         $title = get_string('templates', 'tool_lp');
     }
     if ($pagecontext->contextlevel == CONTEXT_SYSTEM) {
         $heading = $SITE->fullname;
     } else {
         if ($pagecontext->contextlevel == CONTEXT_COURSECAT) {
             $heading = $pagecontext->get_context_name();
         } else {
             throw new coding_exception('Unexpected context!');
         }
     }
     $PAGE->set_pagelayout('admin');
     $PAGE->set_url($url);
     $PAGE->set_title($title);
     $PAGE->set_heading($heading);
     if (!empty($template)) {
         $PAGE->navbar->add($title, $templateurl);
         if (!empty($subtitle)) {
             $PAGE->navbar->add($subtitle, $url);
         }
     } else {
         if (!empty($subtitle)) {
             // We're in a sub page without a specific template.
             $PAGE->navbar->add($subtitle, $url);
         }
     }
     return array($title, $subtitle, $returnurl);
 }
 /**
  * Validate templateid.
  *
  * @param  int $value ID.
  * @return true|lang_string
  */
 protected function validate_templateid($value)
 {
     if (!template::record_exists($value)) {
         return new \lang_string('invaliddata', 'error');
     }
     return true;
 }
示例#11
0
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * This page lets users to manage site wide competencies.
 *
 * @package    tool_lp
 * @copyright  2015 Damyon Wiese
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once __DIR__ . '/../../../config.php';
require_once $CFG->libdir . '/adminlib.php';
$pagecontextid = required_param('pagecontextid', PARAM_INT);
$context = context::instance_by_id($pagecontextid);
require_login(0, false);
\core_competency\api::require_enabled();
if (!\core_competency\template::can_read_context($context)) {
    throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
}
$url = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url);
$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
echo $output->heading($title);
$page = new \tool_lp\output\manage_templates_page($context);
echo $output->render($page);
echo $output->footer();
示例#12
0
 public function test_create_template()
 {
     $this->resetAfterTest(true);
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $this->assertEquals(0, template::count_records());
     $template = $lpg->create_template();
     $template = $lpg->create_template();
     $this->assertEquals(2, template::count_records());
     $this->assertInstanceOf('\\core_competency\\template', $template);
 }
示例#13
0
文件: plan.php 项目: evltuma/moodle
 /**
  * Update from template.
  *
  * Bulk update a lot of plans from a template
  *
  * @param  template $template
  * @return bool
  */
 public static function update_multiple_from_template(template $template)
 {
     global $DB;
     if (!$template->is_valid()) {
         // As we will bypass this model's validation we rely on the template being validated.
         throw new \coding_exception('The template must be validated before updating plans.');
     }
     $params = array('templateid' => $template->get_id(), 'status' => self::STATUS_COMPLETE, 'name' => $template->get_shortname(), 'description' => $template->get_description(), 'descriptionformat' => $template->get_descriptionformat(), 'duedate' => $template->get_duedate());
     $sql = "UPDATE {" . self::TABLE . "}\n                   SET name = :name,\n                       description = :description,\n                       descriptionformat = :descriptionformat,\n                       duedate = :duedate\n                 WHERE templateid = :templateid\n                   AND status != :status";
     return $DB->execute($sql, $params);
 }
示例#14
0
 /**
  * Return an array of templates persistent with their missing userids.
  *
  * Note that only cohorts associated with visible templates are considered,
  * as well as only templates with a due date in the future, or no due date.
  *
  * @param int $lastruntime  The last time the Cohort ssync task ran.
  * @param bool $unlinkedaremissing When true, unlinked plans are considered as missing.
  * @return array( array(
  *                   'template' => \core_competency\template,
  *                   'userids' => array
  *              ))
  */
 public static function get_all_missing_plans($lastruntime = 0, $unlinkedaremissing = false)
 {
     global $DB;
     $planwhereclause = " WHERE (p.id is NULL\n                               AND (cm.timeadded >= :lastruntime1\n                                OR tc.timecreated >= :lastruntime3\n                                OR t.timemodified >= :lastruntime4))";
     if ($unlinkedaremissing) {
         $planwhereclause .= " OR (p.origtemplateid IS NOT NULL AND cm.timeadded < :lastruntime2)";
     }
     $sql = "SELECT " . $DB->sql_concat('cm.userid', 'tc.templateid') . " as uniqueid, cm.userid, t.*\n                  FROM {cohort_members} cm\n                  JOIN {" . self::TABLE . "} tc ON cm.cohortid = tc.cohortid\n                  JOIN {" . template::TABLE . "} t\n                    ON (tc.templateid = t.id AND t.visible = 1)\n                   AND (t.duedate = 0 OR t.duedate > :time1)\n             LEFT JOIN {" . plan::TABLE . "} p ON (cm.userid = p.userid AND (t.id = p.templateid OR t.id = p.origtemplateid))\n                  {$planwhereclause}\n              ORDER BY t.id";
     $params = array('time1' => time(), 'time2' => time(), 'lastruntime1' => $lastruntime, 'lastruntime2' => $lastruntime, 'lastruntime3' => $lastruntime, 'lastruntime4' => $lastruntime);
     $results = $DB->get_records_sql($sql, $params);
     $missingplans = array();
     foreach ($results as $usertemplate) {
         $userid = $usertemplate->userid;
         // Check if template already exist in the array.
         if (isset($missingplans[$usertemplate->id])) {
             $missingplans[$usertemplate->id]['userids'][] = $userid;
         } else {
             unset($usertemplate->userid);
             unset($usertemplate->uniqueid);
             $template = new template(0, $usertemplate);
             $missingplans[$template->get_id()]['template'] = $template;
             $missingplans[$template->get_id()]['userids'][] = $userid;
         }
     }
     return array_values($missingplans);
 }