Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
M
moodle-block_featuredcourses
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Daniel Neis Araujo
moodle-block_featuredcourses
Commits
7fc3de75
Commit
7fc3de75
authored
May 06, 2015
by
Daniel Neis Araujo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
funcionando a adição
parent
3909f693
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
198 additions
and
12 deletions
+198
-12
edit_form.php
edit_form.php
+2
-7
featuredcourses.php
featuredcourses.php
+59
-0
featuredcourses_form.php
featuredcourses_form.php
+106
-0
lang/en/block_featuredcourses.php
lang/en/block_featuredcourses.php
+14
-5
lib.php
lib.php
+15
-0
settings.php
settings.php
+2
-0
No files found.
edit_form.php
View file @
7fc3de75
...
...
@@ -3,14 +3,9 @@
class
block_featuredcourses_edit_form
extends
block_edit_form
{
protected
function
specific_definition
(
$mform
)
{
global
$CFG
;
// Section header title according to language file.
$mform
->
addElement
(
'header'
,
'configheader'
,
get_string
(
'blocksettings'
,
'block'
));
// A sample string variable with a default value.
$mform
->
addElement
(
'text'
,
'config_text'
,
get_string
(
'blockstring'
,
'block_featuredcourses'
));
$mform
->
setDefault
(
'config_text'
,
'default value'
);
$mform
->
setType
(
'config_text'
,
PARAM_MULTILANG
);
$mform
->
addElement
(
'static'
,
'link'
,
get_string
(
'editlink'
,
'block_featuredcourses'
,
$CFG
->
wwwroot
.
'/blocks/featuredcourses/featuredcourses.php'
));
}
}
featuredcourses.php
0 → 100644
View file @
7fc3de75
<?php
require_once
(
'../../config.php'
);
require_once
(
$CFG
->
libdir
.
'/coursecatlib.php'
);
require_once
(
$CFG
->
dirroot
.
'/blocks/featuredcourses/lib.php'
);
require_once
(
$CFG
->
dirroot
.
'/blocks/featuredcourses/featuredcourses_form.php'
);
require_login
();
$system_context
=
context_system
::
instance
();
require_capability
(
'block/featuredcourses:addinstance'
,
$system_context
);
$PAGE
->
set_pagelayout
(
'admin'
);
$PAGE
->
set_url
(
'/blocks/featuredcourses/featuredcourses.php'
);
$PAGE
->
set_context
(
$system_context
);
$args
=
array
(
'availablecourses'
=>
coursecat
::
get
(
0
)
->
get_courses
(
array
(
'recursive'
=>
true
)),
'featuredcourses'
=>
featuredcourses_get_all
()
);
$editform
=
new
featuredcourses_form
(
null
,
$args
);
if
(
$editform
->
is_cancelled
())
{
redirect
(
$CFG
->
wwwroot
.
'/?redirect=0'
);
}
else
if
(
$data
=
$editform
->
get_data
())
{
if
(
isset
(
$data
->
doadd
)
&&
$data
->
doadd
==
1
)
{
try
{
$DB
->
insert_record
(
'block_featuredcourses'
,
$data
->
newfeatured
);
}
catch
(
Exception
$e
)
{
throw
new
moodle_exception
();
}
}
if
(
isset
(
$data
->
featured
)
&&
!
empty
(
$data
->
featured
))
{
try
{
foreach
(
$data
->
featured
as
$f
)
{
$DB
->
update_record
(
'block_featuredcourses'
,
$f
);
}
}
catch
(
Exception
$e
)
{
throw
new
moodle_exception
();
}
}
redirect
(
$CFG
->
wwwroot
.
'/blocks/featuredcourses/featuredcourses.php'
);
}
$site
=
get_site
();
$PAGE
->
set_title
(
get_string
(
'editpagetitle'
,
'block_featuredcourses'
));
$PAGE
->
set_heading
(
$site
->
fullname
.
' - '
.
get_string
(
'pluginname'
,
'block_featuredcourses'
));
echo
$OUTPUT
->
header
();
echo
$OUTPUT
->
heading
(
get_string
(
'editpagedesc'
,
'block_featuredcourses'
));
$editform
->
display
();
echo
$OUTPUT
->
footer
();
featuredcourses_form.php
0 → 100644
View file @
7fc3de75
<?php
defined
(
'MOODLE_INTERNAL'
)
||
die
;
require_once
(
$CFG
->
libdir
.
'/formslib.php'
);
/**
* The form for handling featured courses.
*/
class
featuredcourses_form
extends
moodleform
{
/**
* Form definition.
*/
function
definition
()
{
$mform
=
$this
->
_form
;
$availablecourses
=
$this
->
_customdata
[
'availablecourses'
];
// this contains the data of this form
$featuredcourses
=
$this
->
_customdata
[
'featuredcourses'
];
// this contains the data of this form
$availablecourseslist
=
array
();
foreach
(
$availablecourses
as
$c
)
{
$availablecourseslist
[
$c
->
id
]
=
$c
->
shortname
.
' : '
.
$c
->
fullname
;
}
// Forms to edit existing featured courses
foreach
(
$featuredcourses
as
$c
)
{
$mform
->
addElement
(
'header'
,
'featured'
,
get_string
(
'featuredcourse'
,
'block_featuredcourses'
,
$c
->
shortname
.
' - '
.
$c
->
fullname
));
$mform
->
addElement
(
'hidden'
,
'featured['
.
$c
->
id
.
'][id]'
,
null
);
$mform
->
setType
(
'featured['
.
$c
->
id
.
'][id]'
,
PARAM_INT
);
$mform
->
setConstant
(
'featured['
.
$c
->
id
.
'][id]'
,
$c
->
id
);
$mform
->
addElement
(
'text'
,
'featured['
.
$c
->
id
.
'][proximaturma]'
,
get_string
(
'proximaturma'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingproximatuma'), 'required', null, 'client');
$mform
->
setType
(
'featured['
.
$c
->
id
.
'][proximaturma]'
,
PARAM_TEXT
);
$mform
->
setDefault
(
'featured['
.
$c
->
id
.
'][proximaturma]'
,
$c
->
proximaturma
);
$mform
->
addElement
(
'text'
,
'featured['
.
$c
->
id
.
'][cargahoraria]'
,
get_string
(
'cargahoraria'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform
->
setType
(
'featured['
.
$c
->
id
.
'][cargahoraria]'
,
PARAM_INT
);
$mform
->
setDefault
(
'featured['
.
$c
->
id
.
'][cargahoraria]'
,
$c
->
cargahoraria
);
$mform
->
addElement
(
'text'
,
'featured['
.
$c
->
id
.
'][valor]'
,
get_string
(
'price'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform
->
setType
(
'featured['
.
$c
->
id
.
'][valor]'
,
PARAM_INT
);
$mform
->
setDefault
(
'featured['
.
$c
->
id
.
'][valor]'
,
$c
->
valor
);
$mform
->
addElement
(
'text'
,
'featured['
.
$c
->
id
.
'][linkprograma]'
,
get_string
(
'linkprograma'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform
->
setType
(
'featured['
.
$c
->
id
.
'][linkprograma]'
,
PARAM_URL
);
$mform
->
setDefault
(
'featured['
.
$c
->
id
.
'][linkprograma]'
,
$c
->
linkprograma
);
$mform
->
addElement
(
'text'
,
'featured['
.
$c
->
id
.
'][linkinscrever]'
,
get_string
(
'linkinscrever'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform
->
setType
(
'featured['
.
$c
->
id
.
'][linkinscrever]'
,
PARAM_URL
);
$mform
->
setDefault
(
'featured['
.
$c
->
id
.
'][linkinscrever]'
,
$c
->
linkinscrever
);
$mform
->
addElement
(
'text'
,
'featured['
.
$c
->
id
.
'][linkimagem]'
,
get_string
(
'linkimagem'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform
->
setType
(
'featured['
.
$c
->
id
.
'][linkimagem]'
,
PARAM_URL
);
$mform
->
setDefault
(
'featured['
.
$c
->
id
.
'][linkimagem]'
,
$c
->
linkimagem
);
}
// Add a new featured course
$mform
->
addElement
(
'header'
,
'add'
,
get_string
(
'addfeaturedcourse'
,
'block_featuredcourses'
));
$mform
->
addElement
(
'checkbox'
,
'doadd'
,
get_string
(
'doadd'
,
'block_featuredcourses'
));
$mform
->
addElement
(
'select'
,
'newfeatured[courseid]'
,
get_string
(
'courseid'
,
'block_featuredcourses'
),
$availablecourseslist
);
$mform
->
disabledIf
(
'newfeatured[courseid]'
,
'doadd'
,
'notchecked'
);
$mform
->
addElement
(
'text'
,
'newfeatured[proximaturma]'
,
get_string
(
'proximaturma'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingproximatuma'), 'required', null, 'client');
$mform
->
setType
(
'newfeatured[proximaturma]'
,
PARAM_TEXT
);
$mform
->
disabledIf
(
'newfeatured[proximaturma]'
,
'doadd'
,
'notchecked'
);
$mform
->
addElement
(
'text'
,
'newfeatured[cargahoraria]'
,
get_string
(
'cargahoraria'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform
->
setType
(
'newfeatured[cargahoraria]'
,
PARAM_INT
);
$mform
->
disabledIf
(
'newfeatured[cargahoraria]'
,
'doadd'
,
'notchecked'
);
$mform
->
addElement
(
'text'
,
'newfeatured[valor]'
,
get_string
(
'price'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform
->
setType
(
'newfeatured[valor]'
,
PARAM_INT
);
$mform
->
disabledIf
(
'newfeatured[valor]'
,
'doadd'
,
'notchecked'
);
$mform
->
addElement
(
'text'
,
'newfeatured[linkprograma]'
,
get_string
(
'linkprograma'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform
->
setType
(
'newfeatured[linkprograma]'
,
PARAM_URL
);
$mform
->
disabledIf
(
'newfeatured[linkprograma]'
,
'doadd'
,
'notchecked'
);
$mform
->
addElement
(
'text'
,
'newfeatured[linkinscrever]'
,
get_string
(
'linkinscrever'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform
->
setType
(
'newfeatured[linkinscrever]'
,
PARAM_URL
);
$mform
->
disabledIf
(
'newfeatured[linkinscrever]'
,
'doadd'
,
'notchecked'
);
$mform
->
addElement
(
'text'
,
'newfeatured[linkimagem]'
,
get_string
(
'linkimagem'
,
'block_featuredcourses'
));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform
->
setType
(
'newfeatured[linkimagem]'
,
PARAM_URL
);
$mform
->
disabledIf
(
'newfeatured[linkimagem]'
,
'doadd'
,
'notchecked'
);
$mform
->
addElement
(
'submit'
,
'save'
,
get_string
(
'savechanges'
));
$mform
->
closeHeaderBefore
(
'save'
);
}
}
lang/en/block_featuredcourses.php
View file @
7fc3de75
...
...
@@ -23,11 +23,20 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string
[
'blockstring'
]
=
'Block string'
;
$string
[
'descconfig'
]
=
'Description of the config section'
;
$string
[
'descfoo'
]
=
'Config description'
;
$string
[
'headerconfig'
]
=
'Config section header'
;
$string
[
'labelfoo'
]
=
'Config label'
;
$string
[
'featuredcourses:addinstance'
]
=
'Add a Featured Courses block'
;
$string
[
'featuredcourses:myaddinstance'
]
=
'Add a Featured Courses block to my moodle'
;
$string
[
'pluginname'
]
=
'Featured Courses'
;
$string
[
'editlink'
]
=
'<a href="{$a}">Click here to edit or add featured courses</a>'
;
$string
[
'editpagedesc'
]
=
'Editing the list of featured courses'
;
$string
[
'featuredcourses'
]
=
'Featured courses'
;
$string
[
'addfeaturedcourse'
]
=
'Add a new exiting course to featured list'
;
$string
[
'courseid'
]
=
'Course'
;
$string
[
'proximaturma'
]
=
'Next start date:'
;
$string
[
'cargahoraria'
]
=
'Course workload in hours:'
;
$string
[
'price'
]
=
'Price:'
;
$string
[
'linkprograma'
]
=
'Link to course summary page:'
;
$string
[
'linkinscrever'
]
=
'Link to course subscription page:'
;
$string
[
'linkimagem'
]
=
'Link to an image to be shown below course info:'
;
$string
[
'editpagetitle'
]
=
'Featured courses - editing'
;
$string
[
'featuredcourse'
]
=
'Featured course: {$a}'
;
$string
[
'doadd'
]
=
'Check to add new featured course'
;
lib.php
0 → 100644
View file @
7fc3de75
<?php
function
featuredcourses_get_all
()
{
global
$DB
;
$sql
=
"SELECT c.id, c.shortname, c.fullname,
f.id, f.proximaturma, f.cargahoraria, f.valor,
f.linkprograma, f.linkinscrever, f.linkimagem
FROM
{
course
}
c
JOIN
{
block_featuredcourses
}
f
ON (c.id = f.courseid)
WHERE c.visible = 1"
;
return
$DB
->
get_records_sql
(
$sql
);
}
settings.php
View file @
7fc3de75
...
...
@@ -24,6 +24,7 @@
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/*
$settings->add(new admin_setting_heading('sampleheader',
get_string('headerconfig', 'block_featuredcourses'),
get_string('descconfig', 'block_featuredcourses')));
...
...
@@ -32,3 +33,4 @@ $settings->add(new admin_setting_configcheckbox('featuredcourses/foo',
get_string('labelfoo', 'block_featuredcourses'),
get_string('descfoo', 'block_featuredcourses'),
'0'));
*/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment