What is the best way to filter data in hooks

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
ayussuf
Veteran Member
Posts: 39
Joined: 2021-01-20 17:15

What is the best way to filter data in hooks

Post by ayussuf » 2021-01-28 05:52

Hi,

I've made some filter in Hooks and it works. But I think there are other ways that are more simple using more concise code.

Any suggestion?

I code is like this

Code: Select all

	function Pelajar_init(&$options, $memberInfo, &$args) {
		
		$TableAndGroup = $memberInfo['group'];
		$RecID = sqlValue("select id FROM ".$TableAndGroup." WHERE milik = '".$memberInfo['username']."'");

		if ($TableAndGroup=="Penyelia"){
			$pelajar = sql("SELECT pelajar FROM Seliaan WHERE penyelia='{$RecID}'", $eo);
			while ($row = db_fetch_assoc($pelajar)) {
				   $array[] = $row;
			}

			$num_rows = db_num_rows($pelajar);

			for ($i = 0; $i < $num_rows;) {
				   //echo $array[$i]['pelajar']."<br>";
				   addFilter($i+1, 'or', 1, 'equal-to', $array[$i]['pelajar']);
				   $i ++;
			}

		}
	}
AppGini 5.92 - Upgraded to 5.94

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: What is the best way to filter data in hooks

Post by onoehring » 2021-01-28 09:15

Hi,

I am not sure what you are asking for / want to accomplish.
I am replying to hint to to a bug that still exists in 5.94 in the datatypes.php and which caused ma a lot of headache working with a custom filter. Please see here for a description and a quick fix from Ahmed ( viewtopic.php?f=11&t=4143 ).

Olaf

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: What is the best way to filter data in hooks

Post by pbottcher » 2021-01-28 19:49

Hi,

you could try to shorten the code a little bit, but other than that it is just fine.

Code: Select all

	function Pelajar_init(&$options, $memberInfo, &$args) {

		if ($memberInfo['group']=="Penyelia"){
			$pelajar = sql("SELECT pelajar FROM Seliaan WHERE penyelia=(select id FROM ".$memberInfo['group']." WHERE milik = '".$memberInfo['username']."')", $eo);
			$i=1;
			while ($row = db_fetch_assoc($pelajar)) {
				   addFilter($i, 'or', 1, 'equal-to', $row['pelajar']);
				   $i++;
			}
		}
	}
Code is not tested and may have syntax errors
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Post Reply