I think I'm doing something silly... I've been following the tutorial on overriding renderers and had a google but can't work it out. (I was hopeful when I found this other stackoverflow question but it hasn't helped)
I'm trying to override the renderer for a module (studentquiz) but it doesn't seem to be working.
Below is what I've done so far... I've just copy and pasted a function in and then deleted a few lines from it - expecting to see the changes after purging the caches but nothing is happening. Have tried various setups but nothing is working.
Any help would be greatly appreciated!
Many thanks
Ollie
/theme/THEMENAME/config.php has the line:
$THEME->rendererfactory = 'theme_overridden_renderer_factory';
/theme/THEMENAME/renderers.php is as follows:
<?php
defined('MOODLE_INTERNAL') || die;
include_once($CFG->dirroot . "/mod/studentquiz/renderer.php");
class theme_THEMENAME_mod_studentquiz_renderer extends mod_studentquiz_renderer {
// place your overridden methods (functions) here.
public function render_stat_block($report) {
...
}
}
I'm deleting the following lines from the function:
. html_writer::div($this->render_progress_bar($info2), '', array('style' => 'width:inherit'))
. html_writer::div(get_string('statistic_block_approvals', 'studentquiz')
.html_writer::span('<b>' .$userstats->questions_approved .'</b>', '',
array('style' => 'float: right;color:#28A745;')))
. html_writer::div(get_string('statistic_block_created', 'studentquiz')
.html_writer::span('<b>' .$userstats->questions_created .'</b>', '',
array('style' => 'float: right;')))
To demove the last progress bar and two lines from this:
Change the renderer factory in config.php to:
$THEME->rendererfactory = 'theme_THEMENAME_renderer_factory';
It will need to reflect the frankenstyle name of your theme
Related
I use a php-script within a plugin on a Wordpress-site to geocode an user-supplied address. After this I would like to visualize the point on a leaflet map. In order to do so I wanted to use the built-in functions from the leaflet-map plugin. I tracked down the class for this in the class.map-shortcode.php-file: Leaflet_Map_Shortcode. This class provideds the function shortcode. This is also added to the shortcode in Wordpress (Lines 135 onwards):
'leaflet-map' => array(
'file' => 'class.map-shortcode.php',
'class' => 'Leaflet_Map_Shortcode');
foreach ($this->_shortcodes as $shortcode => $details) {
include_once $shortcode_dir . $details['file'];
add_shortcode($shortcode, array($details['class'], 'shortcode'));
My Intention was using this in a straightforward way:
<?php
... some code for geocoding...
$coords = array("lng" => 11, "lat" =>43 );
$myMap= new Leaflet_Map_Shortcode;
$myMap->shortcode($coords);
?>
But nothing happens (i.e. nothing is displayed). So this leads me to several questions:
Why does this not work?
What's the best way of debugging this code?
Is there a better solution to my problem?
Turns out it is very easy due to a hint in the comments:
$mapPrint = $myMap->shortcode($coords);
echo($mapPrint);
I am currently doing a site on cakephp 2.6.2.
I use a plugin for comments, as follows: Comment plugin.
Everything works fine until I try to add a comment to a post, it then returns the following error:
Strict (2048): Declaration of Comment::afterSave() should be compatible with Model::afterSave($created, $options = Array)
[APP/Plugin/Comment/Model/Comment.php, line 2]
I do not understand why this error is raised and how I can resolve it.
I searched issues already covered but I do not understand what how I should proceed. I try several times but without success: s
I have in comment.php:
public function afterSave($created){
if ($created) {
$model = ClassRegistry::init($this->data[$this->alias]['ref']);
// Manual countercache, it's more flexible, no need to add complex relation on Comment Model
if($model->hasField('comment_count')){
$model->id = $this->data[$this->alias]['ref_id'];
$model->saveField('comment_count',$this->find('count',array(
'conditions' => array('ref'=>$this->data[$this->alias]['ref'],'ref_id'=>$this->data[$this->alias]['ref_id'])
)));
}
$this->getEventManager()->dispatch(new CakeEvent('Plugin.Comment.add', $this));
}
}
and CommentsController.php:
$this->Comment->create($this->request->data, true);
the changes I've tried to do:
$this->Comment->create($this->request->data, true);
to $this->Comment->create($this->request->data);
or $this->Comment->create(controller $this->request->data, true);
I'm sorry but i'dont understand what i exactly have to do :s
I'm running into some difficulty in using the added componenet requirelogin.php . This is the component that I've added
<?php
class RequireLogin extends CBehavior
{
public function attach($owner)
{
$owner->attachEventHandler('onBeginRequest', array($this, 'handleBeginRequest'));
}
public function handleBeginRequest($event)
{
if (Yii::app()->user->isGuest && !in_array($_GET['r'],array('site/login', 'site/index'))) {
Yii::app()->user->loginRequired();
}
}
}
?>
Note how 'site/index' is allowed in this as a page that I can visit.
Now, in my main.php I added the following
'behaviors' => array(
'onBeginRequest' => array(
'class' => 'application.components.RequireLogin'
)
),
Now, these two force me to go to site/login everytime - even though I have done as other stackoverflow answers have told me to and added
// sets the default controller action as the index page
'defaultController' => 'site/index',
Could anyone explain why this hasn't made my start page site/index?
_____________ ADDITION
I've also figured out that when I am going to the base action (i.e. mywebsite.com) it is NOT going to site/index. rather it is directly redirecting to site/login. This, however, does not occur, when I comment out the behaviors .
So, thank you darkheir for all of your work on this.
Ultimately, what happened was the $_GET['r] in the base path was simply '' because r was not point to anything in particular. As a result, when ever I looked in_array($_GET['r']) what I was getting in the very bae path was in_array('', array('site/login', 'site/account')) Now, unfortunately, '' is neither site/login or site/account so the page redirected using
Yii::app()->user->loginRequired();
The fix to this problem was
public function handleBeginRequest($event)
{
// note that '' is now one of the options in the array
if (Yii::app()->user->isGuest && !in_array($_GET['r'],array('site/login', 'site/index', '' ))) {
Yii::app()->user->loginRequired();
}
}
This should be fairly simple for anyone familiar with MediaWiki, but it's stumping me for me because being me.
I'm working on a skin, and I need to show the currently logged in user's name in a top bar - let's assume in plain text, for simplicity's sake, with changes via CSS.
Initially, I was planning on using the automatically generated one used in the personal tools bar, but since the generating line in the skin is
<?php $this->renderNavigation( 'PERSONAL' ); ?>
, it's inseparable from there. I looked in User.php and found its generation line:
public function getUserPage() {
return Title::makeTitle( NS_USER, $this->getName() );
}
So, I figure I might be able to use this function somehow, but I have very little knowledge of PHP, and am unsure how.
EDIT: It appears that this is used for the generation in the personal tools line itself, but again, I'm not sure how to adapt this.
$personal_urls['userpage'] = array(
'text' => $this->username,
'href' => &$this->userpageUrlDetails['href'],
'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
);
Could I duplicate this into a separate function, and make something like the following?
<?php $this->renderNavigation( 'USERNAME' ); ?>
You can use this code:
<?php echo htmlspecialchars($this->getSkin()->getUser()->getName()); ?>
Or, as the User class has a __ToString() magic method:
<?php echo htmlspecialchars($this->getSkin()->getUser()); ?>
Sources :
The SkinTemplate class in MediaWiki code documentation
The User class in the same documentation
CurrentUsers
http://www.mediawiki.org/wiki/Extension:CurrentUsers
GetUserName
http://www.mediawiki.org/wiki/Extension:GetUserName
Modify these extension for your needs
If you indeed just want the username inserted somewhere into the skin HTML, this should do it:
<?php echo htmlspecialchars( $this->username ); ?>
Ok i have been looking for a while now... and i wasnt able to find nothing related to jquery and cakephp when loading content to a div using the helper $this->Js->link... so i decided to post my question here in this awesome site... my first question and its so silly (i guess).
So... mechanics works fine, i mean.. it loads the content into a div called "algo" but now i try to add some effects (fadein) and im not being able to find the correct syntaxys for this! im brand new with cake... just 1 month old using it.
How do i add "fadeIn" effect when showing this damn div? i have tried lots of things but so far nothing makes the div load content with fadein effect whatsoever...
echo $this->Js->link('Categoria 1', array('controller' => 'Categories', 'action' => 'categorias1'), array('update' => '#algo'));
this perfectly loads a bunch of pictures that i have on category 1 inside the div that im asking... what should i do to add fadeIn effect? i have added some crazy things to see if they work but... nope... no luck
i have even tried this crazy one:
echo $this->Js->link('Categoria 1', array('controller' => 'Categories', 'action' => 'categorias1'), array('update' => '#algo', array('effect' =>array('fadeIn', array('speed' => 'slow'), true))));
any help will be apreciated! nobody shows examples of divs with cakephp.. or at least i wasnt able to find one that suits my needs!
great site by the way! it helped me a lot all this years!
i finally manage myself to accomplish what i was trying to do and i want to share with you guys what i did:
echo $this->Js->link('categoria 1', array('controller' => 'Categories', 'action' => 'categorias1'),array('update' => '#categorias', 'evalscripts' => true, 'before' => $this->Js->get('#algo,#categorias2')->effect('fadeOut', array('buffer' => false)), 'complete' => $this->Js->get('#categorias')->effect('fadeIn', array('buffer' => false))));
This huge piece of code is doing what i was expecting to, i also have added some editing to my jquery helper in order to pass them more than one div so i can have them all refreshed at the same time.
if you guys want to hack your helper here is the code:
cake/libs/view/helpers/jquery_engine.php
find this line:
$success .= $this-jQueryObject . '("' . $options['update'] . '").html(data);';
and have it replaced with:
if(is_array($options['update'])){
$success .= 'var temp = ' . $this->jQueryObject . '(" <div/>").html(data);';
foreach($options['update'] as $divId){
$success .= $this->jQueryObject . '("' . $divId . '").html(' . $this->jQueryObject . '("' . $divId . '", temp).html());';
}
} else {
$success .= $this->jQueryObject . '("' . $options['update'] . '").html(data);'; //linea que ya estaba
}
//termina agregado
As suggested by Dunhamzzz, I write all my jQuery by hand and never use the helpers. There doesn't seem to be any point tbh.
One useful tip, pass the base URL and any other useful cake variables into your page as a javascript variable. Add this to your layout:
<?php
$baseUrl = Router::url('/');
echo $this->Html->scriptBlock(<<<EOJS
var baseUrl = '{$baseUrl}';
EOJS
); ?>