Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
bfceabab
Commit
bfceabab
authored
Apr 07, 2015
by
Dan Poltawski
Browse files
Merge branch 'MDL-41608-master' of
git://github.com/jethac/moodle
parents
fee0ba1f
263fb9d1
Changes
11
Hide whitespace changes
Inline
Side-by-side
lib/classes/output/notification.php
0 → 100644
View file @
bfceabab
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 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/>.
/**
* Notification renderable component.
*
* @package core
* @copyright 2015 Jetha Chan
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
core\output
;
use
stdClass
;
/**
* Data structure representing a notification.
*
* @copyright 2015 Jetha Chan
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.9
* @package core
* @category output
*/
class
notification
implements
\
renderable
,
\
templatable
{
/**
* A generic message.
*/
const
NOTIFY_MESSAGE
=
'message'
;
/**
* A message notifying the user of a successful operation.
*/
const
NOTIFY_SUCCESS
=
'success'
;
/**
* A message notifying the user that a problem occurred.
*/
const
NOTIFY_PROBLEM
=
'problem'
;
/**
* A message to display during a redirect..
*/
const
NOTIFY_REDIRECT
=
'redirect'
;
/**
* @var string Message payload.
*/
private
$message
=
''
;
/**
* @var string Message type.
*/
private
$messagetype
=
self
::
NOTIFY_PROBLEM
;
/**
* Notification constructor.
*
* @param string $message the message to print out
* @param string $messagetype normally NOTIFY_PROBLEM or NOTIFY_SUCCESS.
*/
public
function
__construct
(
$message
,
$messagetype
=
self
::
NOTIFY_PROBLEM
)
{
$this
->
message
=
clean_text
(
$message
);
$this
->
messagetype
=
$messagetype
;
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output typically, the renderer that's calling this function
* @return stdClass data context for a mustache template
*/
public
function
export_for_template
(
\
renderer_base
$output
)
{
$data
=
new
stdClass
();
$data
->
type
=
$this
->
messagetype
;
$data
->
message
=
$this
->
message
;
return
$data
;
}
}
lib/outputrenderers.php
View file @
bfceabab
...
...
@@ -2848,7 +2848,108 @@ EOD;
* @return string the HTML to output.
*/
public
function
notification
(
$message
,
$classes
=
'notifyproblem'
)
{
return
html_writer
::
tag
(
'div'
,
clean_text
(
$message
),
array
(
'class'
=>
renderer_base
::
prepare_classes
(
$classes
)));
$classmappings
=
array
(
'notifyproblem'
=>
\
core\output\notification
::
NOTIFY_PROBLEM
,
'notifytiny'
=>
\
core\output\notification
::
NOTIFY_PROBLEM
,
'notifysuccess'
=>
\
core\output\notification
::
NOTIFY_SUCCESS
,
'notifymessage'
=>
\
core\output\notification
::
NOTIFY_MESSAGE
,
'redirectmessage'
=>
\
core\output\notification
::
NOTIFY_REDIRECT
);
// Identify what type of notification this is.
$type
=
\
core\output\notification
::
NOTIFY_PROBLEM
;
$classarray
=
explode
(
' '
,
self
::
prepare_classes
(
$classes
));
if
(
count
(
$classarray
)
>
0
)
{
foreach
(
$classarray
as
$class
)
{
if
(
isset
(
$classmappings
[
$class
]))
{
$type
=
$classmappings
[
$class
];
break
;
}
}
}
$n
=
new
\
core\output\notification
(
$message
,
$type
);
return
$this
->
render
(
$n
);
}
/**
* Output a notification at a particular level - in this case, NOTIFY_PROBLEM.
*
* @param string $message the message to print out
* @return string HTML fragment.
*/
public
function
notify_problem
(
$message
)
{
$n
=
new
\
core\output\notification
(
$message
,
\
core\output\notification
::
NOTIFY_PROBLEM
);
return
$this
->
render
(
$n
);
}
/**
* Output a notification at a particular level - in this case, NOTIFY_SUCCESS.
*
* @param string $message the message to print out
* @return string HTML fragment.
*/
public
function
notify_success
(
$message
)
{
$n
=
new
\
core\output\notification
(
$message
,
\
core\output\notification
::
NOTIFY_SUCCESS
);
return
$this
->
render
(
$n
);
}
/**
* Output a notification at a particular level - in this case, NOTIFY_MESSAGE.
*
* @param string $message the message to print out
* @return string HTML fragment.
*/
public
function
notify_message
(
$message
)
{
$n
=
new
notification
(
$message
,
notification
::
NOTIFY_MESSAGE
);
return
$this
->
render
(
$n
);
}
/**
* Output a notification at a particular level - in this case, NOTIFY_REDIRECT.
*
* @param string $message the message to print out
* @return string HTML fragment.
*/
public
function
notify_redirect
(
$message
)
{
$n
=
new
\
core\output\notification
(
$message
,
\
core\output\notification
::
NOTIFY_REDIRECT
);
return
$this
->
render
(
$n
);
}
/**
* Render a notification (that is, a status message about something that has
* just happened).
*
* @param \core\output\notification $notification the notification to print out
* @return string the HTML to output.
*/
protected
function
render_notification
(
\
core\output\notification
$notification
)
{
$data
=
$notification
->
export_for_template
(
$this
);
$templatename
=
''
;
switch
(
$data
->
type
)
{
case
\
core\output\notification
::
NOTIFY_MESSAGE
:
$templatename
=
'core/output/notification_message'
;
break
;
case
\
core\output\notification
::
NOTIFY_SUCCESS
:
$templatename
=
'core/output/notification_success'
;
break
;
case
\
core\output\notification
::
NOTIFY_PROBLEM
:
$templatename
=
'core/output/notification_problem'
;
break
;
case
\
core\output\notification
::
NOTIFY_REDIRECT
:
$templatename
=
'core/output/notification_redirect'
;
break
;
default
:
$templatename
=
'core/output/notification_message'
;
break
;
}
return
self
::
render_from_template
(
$templatename
,
$data
);
}
/**
...
...
lib/templates/output/notification_message.mustache
0 → 100644
View file @
bfceabab
{{
!
This
file
is
part
of
Moodle
-
http
:
//
moodle
.
org
/
Moodle
is
free
software
:
you
can
redistribute
it
and
/
or
modify
it
under
the
terms
of
the
GNU
General
Public
License
as
published
by
the
Free
Software
Foundation
,
either
version
3
of
the
License
,
or
(
at
your
option
)
any
later
version.
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
/
>
.
}}
{{
!
Moodle
notification
template.
The
purpose
of
this
template
is
to
render
a
message
notification.
Classes
required
for
JS
:
*
none
Data
attributes
required
for
JS
:
*
none
Context
variables
required
for
this
template
:
*
message
A
cleaned
string
(
use
clean_text
())
to
display.
}}
<div
class=
"alert alert-info"
>
{{{
message
}}}
</div>
\ No newline at end of file
lib/templates/output/notification_problem.mustache
0 → 100644
View file @
bfceabab
{{
!
This
file
is
part
of
Moodle
-
http
:
//
moodle
.
org
/
Moodle
is
free
software
:
you
can
redistribute
it
and
/
or
modify
it
under
the
terms
of
the
GNU
General
Public
License
as
published
by
the
Free
Software
Foundation
,
either
version
3
of
the
License
,
or
(
at
your
option
)
any
later
version.
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
/
>
.
}}
{{
!
Moodle
notification
template.
The
purpose
of
this
template
is
to
render
a
problem
notification.
Classes
required
for
JS
:
*
none
Data
attributes
required
for
JS
:
*
none
Context
variables
required
for
this
template
:
*
message
A
cleaned
string
(
use
clean_text
())
to
display.
}}
<div
class=
"alert alert-error"
>
{{{
message
}}}
</div>
\ No newline at end of file
lib/templates/output/notification_redirect.mustache
0 → 100644
View file @
bfceabab
{{
!
This
file
is
part
of
Moodle
-
http
:
//
moodle
.
org
/
Moodle
is
free
software
:
you
can
redistribute
it
and
/
or
modify
it
under
the
terms
of
the
GNU
General
Public
License
as
published
by
the
Free
Software
Foundation
,
either
version
3
of
the
License
,
or
(
at
your
option
)
any
later
version.
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
/
>
.
}}
{{
!
Moodle
notification
template.
The
purpose
of
this
template
is
to
render
a
message
notification.
Classes
required
for
JS
:
*
none
Data
attributes
required
for
JS
:
*
none
Context
variables
required
for
this
template
:
*
message
A
cleaned
string
(
use
clean_text
())
to
display.
}}
<div
class=
"alert alert-block alert-info"
>
{{{
message
}}}
</div>
\ No newline at end of file
lib/templates/output/notification_success.mustache
0 → 100644
View file @
bfceabab
{{
!
This
file
is
part
of
Moodle
-
http
:
//
moodle
.
org
/
Moodle
is
free
software
:
you
can
redistribute
it
and
/
or
modify
it
under
the
terms
of
the
GNU
General
Public
License
as
published
by
the
Free
Software
Foundation
,
either
version
3
of
the
License
,
or
(
at
your
option
)
any
later
version.
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
/
>
.
}}
{{
!
Moodle
notification
template.
The
purpose
of
this
template
is
to
render
a
success
notification.
Classes
required
for
JS
:
*
none
Data
attributes
required
for
JS
:
*
none
Context
variables
required
for
this
template
:
*
message
A
cleaned
string
(
use
clean_text
())
to
display.
}}
<div
class=
"alert alert-success"
>
{{{
message
}}}
</div>
\ No newline at end of file
theme/base/templates/core/output/notification_message.mustache
0 → 100644
View file @
bfceabab
{{
!
This
file
is
part
of
Moodle
-
http
:
//
moodle
.
org
/
Moodle
is
free
software
:
you
can
redistribute
it
and
/
or
modify
it
under
the
terms
of
the
GNU
General
Public
License
as
published
by
the
Free
Software
Foundation
,
either
version
3
of
the
License
,
or
(
at
your
option
)
any
later
version.
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
/
>
.
}}
{{
!
Moodle
notification
template.
The
purpose
of
this
template
is
to
render
a
message
notification.
Classes
required
for
JS
:
*
none
Data
attributes
required
for
JS
:
*
none
Context
variables
required
for
this
template
:
*
message
A
cleaned
string
(
use
clean_text
())
to
display.
}}
<div
class=
"notifymessage"
>
{{{
message
}}}
</div>
\ No newline at end of file
theme/base/templates/core/output/notification_problem.mustache
0 → 100644
View file @
bfceabab
{{
!
This
file
is
part
of
Moodle
-
http
:
//
moodle
.
org
/
Moodle
is
free
software
:
you
can
redistribute
it
and
/
or
modify
it
under
the
terms
of
the
GNU
General
Public
License
as
published
by
the
Free
Software
Foundation
,
either
version
3
of
the
License
,
or
(
at
your
option
)
any
later
version.
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
/
>
.
}}
{{
!
Moodle
notification
template.
The
purpose
of
this
template
is
to
render
a
problem
notification.
Classes
required
for
JS
:
*
none
Data
attributes
required
for
JS
:
*
none
Context
variables
required
for
this
template
:
*
message
A
cleaned
string
(
use
clean_text
())
to
display.
}}
<div
class=
"notifyproblem"
>
{{{
message
}}}
</div>
\ No newline at end of file
theme/base/templates/core/output/notification_redirect.mustache
0 → 100644
View file @
bfceabab
{{
!
This
file
is
part
of
Moodle
-
http
:
//
moodle
.
org
/
Moodle
is
free
software
:
you
can
redistribute
it
and
/
or
modify
it
under
the
terms
of
the
GNU
General
Public
License
as
published
by
the
Free
Software
Foundation
,
either
version
3
of
the
License
,
or
(
at
your
option
)
any
later
version.
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
/
>
.
}}
{{
!
Moodle
notification
template.
The
purpose
of
this
template
is
to
render
a
message
notification.
Classes
required
for
JS
:
*
none
Data
attributes
required
for
JS
:
*
none
Context
variables
required
for
this
template
:
*
message
A
cleaned
string
(
use
clean_text
())
to
display.
}}
<div
class=
"redirectmessage"
>
{{{
message
}}}
</div>
\ No newline at end of file
theme/base/templates/core/output/notification_success.mustache
0 → 100644
View file @
bfceabab
{{
!
This
file
is
part
of
Moodle
-
http
:
//
moodle
.
org
/
Moodle
is
free
software
:
you
can
redistribute
it
and
/
or
modify
it
under
the
terms
of
the
GNU
General
Public
License
as
published
by
the
Free
Software
Foundation
,
either
version
3
of
the
License
,
or
(
at
your
option
)
any
later
version.
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
/
>
.
}}
{{
!
Moodle
notification
template.
The
purpose
of
this
template
is
to
render
a
success
notification.
Classes
required
for
JS
:
*
none
Data
attributes
required
for
JS
:
*
none
Context
variables
required
for
this
template
:
*
message
A
cleaned
string
(
use
clean_text
())
to
display.
}}
<div
class=
"notifysuccess"
>
{{{
message
}}}
</div>
\ No newline at end of file
theme/bootstrapbase/renderers/core_renderer.php
View file @
bfceabab
...
...
@@ -27,29 +27,6 @@ class theme_bootstrapbase_core_renderer extends core_renderer {
/** @var custom_menu_item language The language menu if created */
protected
$language
=
null
;
/*
* This renders a notification message.
* Uses bootstrap compatible html.
*/
public
function
notification
(
$message
,
$classes
=
'notifyproblem'
)
{
$message
=
clean_text
(
$message
);
$type
=
''
;
if
((
$classes
==
'notifyproblem'
)
||
(
$classes
==
'notifytiny'
))
{
$type
=
'alert alert-error'
;
}
if
(
$classes
==
'notifysuccess'
)
{
$type
=
'alert alert-success'
;
}
if
(
$classes
==
'notifymessage'
)
{
$type
=
'alert alert-info'
;
}
if
(
$classes
==
'redirectmessage'
)
{
$type
=
'alert alert-block alert-info'
;
}
return
"<div class=
\"
$type
\"
>
$message
</div>"
;
}
/*
* This renders the navbar.
* Uses bootstrap compatible html.
...
...
@@ -247,34 +224,4 @@ class theme_bootstrapbase_core_renderer extends core_renderer {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
theme_bootstrapbase_core_renderer_maintenance
extends
core_renderer_maintenance
{
/**
* Renders notifications for maintenance scripts.
*
* We need to override this method in the same way we do for the core_renderer maintenance method
* found above.
* Please note this isn't required of every function, only functions used during maintenance.
* In this case notification is used to print errors and we want pretty errors.
*
* @param string $message
* @param string $classes
* @return string
*/
public
function
notification
(
$message
,
$classes
=
'notifyproblem'
)
{
$message
=
clean_text
(
$message
);
$type
=
''
;
if
((
$classes
==
'notifyproblem'
)
||
(
$classes
==
'notifytiny'
))
{
$type
=
'alert alert-error'
;
}
if
(
$classes
==
'notifysuccess'
)
{
$type
=
'alert alert-success'
;
}
if
(
$classes
==
'notifymessage'
)
{
$type
=
'alert alert-info'
;
}
if
(
$classes
==
'redirectmessage'
)
{
$type
=
'alert alert-block alert-info'
;
}
return
"<div class=
\"
$type
\"
>
$message
</div>"
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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