Set the default value for views 3 in drupal 7 - view

so I have this exposed from and I want to change the default value when the view is displayed. I did search and found many articles on it but either they are for older versions of views or seem to be incomplete or maybe I am wrong somewhere.
Ref articles:
drupal.org/node/635242
https://drupal.stackexchange.com/questions/1812/change-the-default-selection-for-a-views-2-exposed-filter
Most of them suggest using hook_form_alter but I think as we are using views hook form alter is called too late. Any help will be much appreciated.
function modulename_form_alter(&$form, $form_state, $form_id) {
if($form['#id'] == 'name-of-the-views-form-displayed') {
if (empty($_GET['label-of-the-filter'])) {
$form_state['input']['label-of-the-filter'] = 'default-value-for-filter';
}
}
}

your function declaration line is missing one &
function modulename_form_alter(&$form, &$form_state, $form_id) {
without it, your changes to the $form_state array get ignored

Related

Laravel Debugger showing duplicated queries

Does any one has an idea about this. I don't know why it is showing duplicated queries. I searched a lot, found one answer on stackoverflow, but didn't get proper answer. If anyone faced the same error then please let me know. Thank you
protected $_param;
public function __construct(Utility $utility)
{
$league = $utility->checkDomainController();
view()->share('league', $league);
$this->league = $league;
}
This is the code in controller. which shares league to all the views. But there is only one query in $league = $utility->checkDomainController();
Here is the checkDomainController
if(\Request::server('HTTP_HOST') == env('MAIN_DOMAIN'))
{
$leagueSlug = Route::current()->getParameter('league');
$league = League::where('url', $leagueSlug)->first();
}
else
{
$league = League::where('custom_domain', \Request::server('HTTP_HOST'))->first();
}
if(!$league)
{
//error page
}
return $league;
Anytime you call a property which relies on a related model in blade, Laravel executes a new query, unless you eager load and pass from the controller to the view the preloaded data.
This example you posted seems to me as a loop somewhere within your blade code. Maybe if you can share a bit more of the code related to the front-end, I can help you figure it out.

Moodle theme change based on user type

I am using a Single Sign On technique from a Wordpress website,once the user logs on, they are automatically directed to the Moodle LMS namely 'courses/view.php?id=*relevant_id*'.
The $USER object already has the user type (called 'department' in this case) set up.
I want to do a theme switch based on this user type.
Something like:
if($USER->department == 'redTeam') {
$theme = 'RedteamTheme';
}
My question is:
Where would I place this code snippet?
Does anyone know the exact syntax?
I have looked around Google for hours and I cannot get the syntax
I have found how to do it in code.
In the lib folder you will need to amend 2 files:
pagelib and weblib. The pagelib file is a lengthy extension so I won't paste that code here. If anyone wants it, they can contact me, I will happily share.
the weblib needs to have this added to it for theme switching to work:
//create the function
function _setTheme(){
global $DB,$USER, $CFG, $THEME, $COURSE;//open abstraction layers
//set the criteria for te switch in this case I used the department field, it can also //be roles
$getRole = $USER->department;
if(!empty($getRole)) { //If the variable is not empty proceed with the switch
switch($getRole){
case 'role1':
$val = 'sky_high';
break;
case 'role2':
$val = 'leatherbound';
break;
}
} else {
//default theme
return 'leatherbound';
}
return $val;
}

How to override save() method in a component

Where and how I am overriding the save method in Joomla 3.0 custom component ?
Current situation:
Custom administrator component.
I have a list view that displays all people stored in table.
Clicking on one entry I get to the detailed view where a form is loaded and it's fields can be edited.
On save, the values are stored in the database. This all works fine.However, ....
When hitting save I wish to modify a field before storing it into the database. How do I override the save function and where? I have been searching this forum and googled quiet a bit to find ways to implement this. Anyone who give me a simple example or point me into the right direction ?
Thanks.
Just adding this for anyone who wants to know the answer to the question itself - this works if you explicitly wish to override the save function. However, look at the actual solution of how to manipulate values!
You override it in the controller, like this:
/**
* save a record (and redirect to main page)
* #return void
*/
function save()
{
$model = $this->getModel('hello');
if ($model->store()) {
$msg = JText::_( 'Greeting Saved!' );
} else {
$msg = JText::_( 'Error Saving Greeting' );
}
// Check the table in so it can be edited.... we are done with it anyway
$link = 'index.php?option=com_hello';
$this->setRedirect($link, $msg);
}
More details here: Joomla Docs - Adding Backend Actions
The prepareTable in the model (as mentioned above) is intended for that (prepare and sanitise the table prior to saving). In case you want to us the ID, though, you should consider using the postSaveHook in the controller:
protected function postSaveHook($model, $validData) {
$item = $model->getItem();
$itemid = $item->get('id');
}
The postSaveHook is called after save is done, thus allowing for newly inserted ID's to be used.
You can use the prepareTable function in the model file (administrator/components/yourComponent/models/yourComponent.php)
protected function prepareTable($table)
{
$table->fieldname = newvalue;
}

how to integrate SMF with CodeIgniter?

I am working on a project that will solely use the SMF member system. Meaning that SMF is the only member system that I am using to have logins, not my own system along with SMF, just plain SMF. However, I am running into one problem... I need to be able to get information from SMF based on a given ID_MEMBER. My article database uses SMF's ID_MEMBER field as the author information. Seeing that CodeIgniter is MVC and uses classes, I searched for a general SMF class all over the internet, but could not find one. I decided to write my own, but cannot get it to work correctly... I don't have much experience with OOP.
<?php
class smf {
var $context;
var $memberContext;
function __construct($who){
include('/../../forums/SSI.php');
$this->context = $context;
}
function user_context(){
return $this->context['user'];
}
function member_context($id = NULL){
loadMemberData($id);
loadMemberContext($id);
return $memberContext[$id];
}
}
The user_context function works fine, but not the member_context function. In the SSI.php file, the LoadmemberContext function compiles all of the information into an array called $memberContext[$id]. When I call the method from my CodeIgniter controller, I get an error saying that the $memberContext variable is undefined. Why is this happening?
I stumbled upon this question too and managed to fix it. Try this, it worked for me:
function member_context($id = NULL) {
loadMemberData($id);
loadMemberContext($id);
global $user_profile;
return $user_profile[$id];
}

joomla 1.5 multiple models, problem with default view

I'm developing a view that need to reuse a model, I'm following this documentation http://docs.joomla.org/Using_multiple_models_in_an_MVC_component. But that reference do the trick just (at least as far as I understand) when I use the parameter get task. if I use the view, joomla get me null data.
more clearly
controller.php - the task I named as the view I need
function viewdowhatIneed(){
$view = & $this->getView('viewdowhatIneed',html);
$view->setModel( $this->getModel( 'thenotdefaultmodelthatIneed' ), true );
$view->display();
}
model - thenotdefaultmodelthatIneed.php
class BLAModelthenotdefaultmodelthatIneed extends Jmodel{
function getReusableData0(){...}
function getReusableData1(){...}
}
view - view.html.php
class BLAViewviewdowhatIneed extends JView{
function display($tpl=null){
$dataneedit0 = $this->get('ReusableData0');
$dataneedit1 = $this->get('ReusableData1');
$this->assignRef('dataneedit0',$dataneedit0);
$this->assignRef('dataneedit1',$dataneedit1);
parent::display($tpl);
}
}
SO, what happen to me is:
example.com/index.php?option=com_BLA&view=viewdowhatIneed -> variables(datadataneedit0,dataneedit1) == NULL
example.com/index.php?option=com_BLA&task=viewdowhatIneed -> variables(datadataneedit0,dataneedit1) == Get me right data
then, my question is, is there a way to do the same thing, by using view parameter without task parameter (btw, I know this could be not a important problem, but I'm not an expert and on this reference http://docs.joomla.org/How_Joomla_pieces_work_together, it says:
The task part may or may not exist. Remember that if you omit it you are defaulting to task=display
so I really want to know that. In other words, can my view force to check the controller or vice versa.
Thanks in advance, excuse my english

Resources