flexible list title

Status
Not open for further replies.

susannanam

Member
hi all,

i have a list where i would like to have the title, based on the content of two fields. the table behind the list will be filled differently, every time the list is called. therefore it would be great if i can have a flexible title that grabs the value of the two fields (they have the same value for all rows) and uses it as title. i could use list plugin phpevents and there the OnLoadData event i assume. but i'm not sure, how to address the title. did someone do that yet?

susanne
 
You might be able to do it in the plugin, by setting (I think) $model->table->label.

Or you could create a custom template, and use your own title. Around line 30 in the bootstrap template's default.php.

-- hugh
 
You might be able to do it in the plugin, by setting (I think) $model->table->label.

Or you could create a custom template, and use your own title. Around line 30 in the bootstrap template's default.php.

-- hugh

sorry Hugh, how would i do the first one, setting it in the plugin?
 
OK, first thing is you'll need to update from github. I'd forgotten that the table and label are 'private', so can't be modified directly from another class. So I've added a table model method, setLabel(), which does it.

https://github.com/Fabrik/fabrik/commit/c56f4a084d2ba8567c1e9cf267447151a60d5af7

Then you just need to do something like ...

Code:
$model->setLabel($model->data[0][0]->yourtable___some_element . ' ' . $model->data[0][0]->yourtable___some_other_element) ;

... but obviously modify which elements in $model->data[0][0] you are using, and how you format them. Remembering that data[0] is the first "group" (in the sense of list grouping, not form groups), and data[0][0] is the first row in that first group, which is an object, consisting of element full names.

You might want to wrap that in a test to make sure data[0][0] exists, to avoid it throwing an error if the list has no data in it.

-- hugh
 
sorry Hugh, i just cant get it right... i tried with a simple text and i put the error message i got below as comment

Code:
$titel = 'testtitel';
$model->setLabel($model->data[0][0]->@titel) ;
 
//Parse error: syntax error, unexpected '@', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /home/netsbvgo/public_html/plugins/fabrik_list/php_events/php_events.php(215) : eval()'d code on line 5
 
What's the @ for?

As per my example, just use the full element name, no @ sign.

-- hugh
ahi thanks Hugh, i was blind...lol... it was supposed to be a $ of course. just for testing, i take that variable.. now i get this error:
Fatal error: Cannot access protected property FabrikFEModelList::$data in /home/...../plugins/fabrik_list/php_events/php_events.php(215) : eval()'d code on line 5
 
supposed to be a $
No, here it's really just the full element name which you want to include into the title.
So (I didn't test, only following Hugh's logic)
Code:
$titel = $model->data[0][0]->yourtable___some_element;
$model->setLabel($titel);
 
No, here it's really just the full element name which you want to include into the title.
So (I didn't test, only following Hugh's logic)
Code:
$titel = $model->data[0][0]->yourtable___some_element;
$model->setLabel($titel);

thanks troester :)
i have now tried, with and without the brackets but still get the error (i commented it out below the code):
Code:
$titel = $model->data[0][0]->{sh2m8_assessment_entry___courseid};
$model->setLabel($model->data[0][0]->$titel) ;
//Fatal error: Cannot access protected property FabrikFEModelList::$data in /home/netsbvgo/public_html/plugins/fabrik_list/php_events/php_events.php(215) : eval()'d code on line 4
 
Try
$titel = $model->data[0][0]->sh2m8_assessment_entry___courseid;
$model->setLabel($titel) ;
 
Sorry, was having a blonde moment. That was why I went and added that addLabel() method in the first place, earlier in thisthread, was so you can just do exactly that.

-- hugh
 
Hmm, but this is no "flexible" list titel, you could just alter the list label directly.
cheesegrits: how to access any list data?

i actually made a sql query and the result is instead of 'abc':
Code:
$db = JFactory::getDbo();
$user = JFactory::getUser();
$id_user = $user->get('id');
 
$query = $db->getQuery(true);
$sql = "select cours... from .... where userid = $id_user
  and order_col = 2 LIMIT 1,1 ";
//var_dump($sql);
$db->setQuery($sql);
$results = $db->loadObjectList();
foreach ($results AS $result) {
$courseid = $result -> courseid;
$lecturer = $result -> lecturer; }
 
$model->setLabel($courseid . ' / ' . $lecturer);

there might be other ways but it works :)
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top