Page 1 of 1

QueryFieldsTV - help needed

Posted: 2016-07-04 08:12
by henewidi
The following code works for me:

Code: Select all

	function invoices_init(&$options, $memberInfo, &$args){
		// modify the status field of the table view query to display 'Due' invoices in bold red
		$oldArray=$options->QueryFieldsTV;
		$options->QueryFieldsTV='';
		foreach($oldArray as $field => $caption){
			if($field=='`invoices`.`status`'){
				$options->QueryFieldsTV['IF(`invoices`.`status`=\'Due\', \'<b style="color: red;">Due</b>\', IF(`invoices`.`status`=\'Paid\', \'<b style="color: green;">Paid</b>\', `invoices`.`status`))']=$caption;
			}else{
				$options->QueryFieldsTV[$field]=$caption;
			}
		}
	
		return TRUE;
	}
How would the code look like if I need to color three options in a field, e.g. Due, Paid and Cancelled?
It doesn't seem to work if I add another IF.... in the "$options->QueryFieldsTV['IF(`invoices`...." line.
Also, how would the code look like, if I want to color an additional field, invoices.status and invoices.somethingelse?

Thanks in advance for any help. Much appreciated.
I am on AppGini 5.51

Re: QueryFieldsTV - help needed

Posted: 2016-07-05 05:45
by henewidi
Never mind, I figured it out, here the code if anyone else is interested:

Code: Select all

	function escalations_init(&$options, $memberInfo, &$args){
		$oldArray=$options->QueryFieldsTV;
		$options->QueryFieldsTV='';
		foreach($oldArray as $field => $caption){
			if($field=='`escalations`.`status`'){
				$options->QueryFieldsTV['IF(`escalations`.`status`=\'Medium\', \'<b style="color: #e8af00;">Medium</b>\', 
										 IF(`escalations`.`status`=\'Urgent\', \'<b style="color: #ff2d2d;">Urgent</b>\',
										 IF(`escalations`.`status`=\'Normal\', \'<b style="color: green;">Normal</b>\', `escalations`.`status`)))']=$caption;
			}else{
				$options->QueryFieldsTV[$field]=$caption;
			}
		}
		$oldArray=$options->QueryFieldsTV;
		$options->QueryFieldsTV='';
		foreach($oldArray as $field => $caption){
			if($field=='`escalations`.`severity`'){
				$options->QueryFieldsTV['IF(`escalations`.`severity`=\'Impaired\', \'<b style="color: #e8af00;">Impaired</b>\', 
										 IF(`escalations`.`severity`=\'Down\', \'<b style="color: #ff2d2d;">Down</b>\',
										 IF(`escalations`.`severity`=\'Operational\', \'<b style="color: green;">Operational</b>\', `escalations`.`status`)))']=$caption;
			}else{
				$options->QueryFieldsTV[$field]=$caption;
			}
		}
	
		return TRUE;
	}