Moodle applicable_formats for quiz attempt pages - block

How can I create and set a block to show on all quiz attempt pages?
I have the following code in a custom Moodle block:
public function applicable_formats() {
return array(
'all' => true,
);
}
My objective is to display my block on all course quiz attempt pages such as: http://www.mymoodle.com/mod/quiz/attempt.php?attempt=61
However the options only allow for setting on the current quiz.
All the other quiz pages don't show my block.

You can make this work as adminstrator on the site itself by changing some settings:
Turn block editing on.
Go under "configure [yourblock]".
Now the configuration page of you block appears.
Under the tab "Where this block appears":
Choose in "Display on page types" the configuration that is right for you. For example choose "Any Quiz module Page".
Save.
That's it. :-)

Related

block redirect link to login in joomla and add a popup instead of that

In joomla the default function if a guest clicks a link with a registered access level, is to redirect guest to the login page.
Is there a way to show a popup instead, for all of registered access level links?
For example it redirects to
your.com/login.html
But i want to show a login-button before the guest is redirected.
I found another template where it works like this, but it wont work in my own template. How can I do it in my template?
if(JFactory::getUser()->guest) {
//do user logged out stuff
}
else {
//do user logged in stuff
}
There is no simple fix. The problem is that when it is added, you dont really have information about where a link leads to. If you create an article that is public, and you add a link to an article that is restricted, then joomla does not check this when you add the link.
In the event that joomla can know this beforehand, like restricted menu items, or listing of article links in a category, restricted links will not be displayed to a guest user.
If you want to try to change the behaviour like you want to, then I would consider in what situation this actually happens. If it is links in articles that is the main problem, then the best would be if the editors, when adding links to restricted content, also added a predefined class or something to this link. Then use JQuery to disable the link and display a popup on click. A similar approach could be used in other contexts.

How does Opencart Module saves its settings?

Hey guys I ran into a bit of a problem with module I am developing for OpenCart v1.5.6.4. This is what I have in Admin section for module settings.
As you can see I built in extra tabs where I want to give user the ability to specify extra options which will be used to build out a prescription form on the Catalog side.
Problem is how do I go about Save extra data from each additional tab to a custom table when user click on Save button?
Is there a special function that gets called when Save button is clicked that I could implement myself?
Eh, I guess I was a bit tired last night to realise that this section of code defined in index() handles saving of module setting to the database:
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
//save module settings
$this->model_setting_setting->editSetting('prescripts', $this->request->post);
//mark of success
$this->session->data['success'] = $this->language->get('text_success');
//redirect back to module page
$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
}
So all i need to do is stuff my custom code in here and I am done with Admin controller.

Sitecore - Prevent access to a page, but still show it in the navigation

In Sitecore I have denied access to a particular page for the anonymous user.
This works correctly, but it also means that the page does not appear in the navigation menus and sitemap (both XSLT).
What I would like is for the user to be able to see the link, but be redirected to a Register/Login page when they click on it.
You'd need to allow anonymous users to view the page for it to be visible in the menu and sitemap.
What you could do though is override the Sitecore.Pipelines.HttpRequest.HttpRequestProcessor to check if the page requires a login (by adding a RequiresLogin True/False to the template for example), then check if the user is logged in if not redirect to your login page.
Theres an example of overriding the HttpRequestProcessor here
You could wrap the rendering logic in the menus in a SecurityDisabler, so it would render all item links, even if the user "cant see" them.
using (SecurityDisabler disabler = new SecurityDisabler())
{
foreach (Item item in Sitecore.Context.Item.Children)
{
... render the link ...
}
}

Yii CAPTCHA url is broken

I want to create an AJAX-registration form on my Yii-project. So on every page I have a login-button, which shows a popup if the user isn't authorized. In that popup he can see registration form with email field, password field, and CAPTCHA (default Yii captcha).
So, my model for user's registration is User. There is a validation rule:
array('code', 'captcha', 'allowEmpty'=>!Yii::app()->user->isGuest),
My controller, where all user's actions are, is User (url: site.url/user/) and I added there captcha action:
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
'foreColor'=>0x000000,
),
In my next code:
$this->widget('CCaptcha', array(
'clickableImage' => true,
'showRefreshButton' => false,
))
And here is a problem:( Being inside a popup, which can be shown on every page (index page, for example, which belongs Main controller) captcha wants to load an image from that controller (from /main/captcha, not /user/captcha).
Adding captcha in every controller is bad idea, so I added
'captchaAction' => '/user/captcha',
But after that captcha wants to load from an url
http://site.loc/user/captcha/v/4fe99aca1bbed
User-friendly url's crashed captcha and I can't avoid it (as I think, not being a yii-expert, it's because of common path-config).
Is there an easy solution to solve this? Should I repair URL's or re-configure CAPTCHA?
So, while I was waiting for help, I solved the problem by myself :)
In my project i separated my controllers into the next hierarchy:
/frontend
/backend
All controllers for common users are (of course) in Frontend section, including UserController and MainController.
Yes, I wrote some configs to hide /frontend/ in URL's like this:
'<c:\w+>/<a:\w+>' => 'frontend/<c>/<a>',
And i was sure, that string in my CAPTCHA config ('captchaAction' => '/user/captcha') knows where to go (and it was almost so!), but NO!
I should write FULL PATH to my controller and action like below:
'captchaAction' => '/frontend/main/captcha',
As I said in question, I placed my CAPTCHA action in UserController, but now you can see it is located in MainController (i deleted it from UserController)
And I got an error:
CCaptchaValidator.action "captcha" is invalid. Unable to find such an action in the current controller.
So, to solve this, I just had to use a property captchaAction of CCaptchaValidator in my User MODEL! Code:
array('code', 'captcha', 'captchaAction'=>'/frontend/main/captcha', 'allowEmpty'=>!Yii::app()->user->isGuest)
So, now my AJAX Captcha validation works correctly where I want.
Good luck with Yii's default CAPTCHA, dear community!

Implementing a menu's "selected" links in Yii

I have two templates to integrate into yii - my front end website and my CMS.
My front end website has top menu that is generated by CMS (database)
CMS top menu which is static menu by me. ("Manage pages", "Manage users", "Manage products") although this menu is static I still want to assign a selected class to the appropriate top menu item.
Eg: If I'm managing some pages on the site the "Mange pages" link should be highlighted and selected. How would I go about this? Something I need to code myself or is there a existing function in yii that i need to refer to?
Thanks in advance
Yii newbie
What I do is have multiple "menu" functions in my Controller (AdminController extends Controller) class. Each one builds the array the CMenu needs, and I set the active one based on what I passed in to the function. For instance:
protected function getAdminMenu($activeTitle) {
return array(
array('label'=>'Manage pages', 'url'=>array('/user/purchase'),'active'=>($activeTitle=='Manage pages')?true:false),
array('label'=>'Manage users', 'url'=>array('/user/index'),'active'=>($activeTitle=='Manage users')?true:false),
);
}
You could do this where it looks like the Controller or Action or URL request and sets the appropriate menu item active as well. This is just an example.
Then in my view, if I want to render the menu with "Manage pages" active, I set my layout's Menu using the function in my Controller class:
$this->menu=$this->getAdminMenu('Manage pages');
(This assumes that you have public $menu=array(); declared in your Controller, and as well. Look at the Blog example to see how this works:
$this->widget('zii.widgets.CMenu', array(
'items'=>$this->menu,
));
)
I hope this gives you some direction!
Make a css class that changes the background of the object to highlight it.
In your views for the various pages just make the menu item have that particular class.