Creating a Demo of your app

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Creating a Demo of your app

Post by dharbitindy » 2019-10-25 03:09

Any suggestions on the best way to make a Demo version of your app? For instance, limit the number of records that can be added to all tables.

Thanks,
David

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

Re: Creating a Demo of your app

Post by onoehring » 2019-10-25 07:33

Hi,

limit the number or records: I would probably create a new file which can be called from every /hooks/tablename.php file (use: require (...) and call the function (see below) in the tablename_before_insert function.
This new file contains a function which takes the tablename as argument.
Then the function tests how many records are in that table and rerturnd either TRUE, if the maximum record count is not reached yet or FALSE if the maximum record count in that table has been reached.
Of course, you could supply a second argument to the function which holds the maximum allowed records for that table.

Then the user will get an error when he tries to add a new record after the maximum number of records already exists.

Please make sure that your customer/demo user knows every time how many records can be placed in the table he is working on. Otherwise your application might leave a very bad impression. You could also supply a custom error (see my post here: viewtopic.php?f=7&t=1740&p=10906#p10906 ) telling why the insert did not work.

Olaf

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Creating a Demo of your app

Post by dharbitindy » 2019-10-27 00:48

Much appreciated Olaf, I'll give it a spin. Thank you!

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Creating a Demo of your app

Post by dharbitindy » 2020-08-06 03:26

Hello Olaf,

When/If you have the time, could you please provide an example of the code for the function that would limit the records? Also, I assume that the new file is a Table created with the "Required", attribute checked? If not, please explain if you would please.

Much appreciated,
David

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

Re: Creating a Demo of your app

Post by onoehring » 2020-08-06 06:10

Hi,

as I do not know how your tables are named I can not really provide a code - even if I had the time.

I want to rephrase my suggestion: You should probably notify the user that no new record can be added _before_ he attempts adding one. This means, check if the user could add one more record and already show a message then (and also if the user actually tried to add one - of course).

No, the new file is not a table, but some .php file (you can name it as you like). This shows the problem of this approach: You can not give your code to any customer those could easily change the number of allowed - and that's not what you want :-) .
The .php file should work like this: It contains a single function that can be called from every other file and receives the tablename, it's primary key field name and the number of records allowed.
All pseudo code:

Code: Select all

function check_allowed_records($tablename, $pkfield, $numrecords){
  $myreturnvalue = sqlValue("SELECT COUNT($pkfield) AS c FROM $tablename;");
  if ($myreturnvalue < $numrecords){
    $myreturnvalue = true;
  } else {
    $myreturnvalue = false;
  }
  return $myreturnvalue
}
call the function from the hooks/tablename.php function _before_insert:

Code: Select all

$myreturnvalue = function check_allowed_records(YOUR_TABLENAME, PRIMARYKEYFIELD_NAME, NUMBER_OF_ALLOWED_RECORDS)
and change the return value of hooks/tablename.php function _before_insert to:

Code: Select all

return $myreturnvalue
Olaf

dharbitindy
Veteran Member
Posts: 101
Joined: 2019-05-26 18:38

Re: Creating a Demo of your app

Post by dharbitindy » 2020-08-06 13:57

Olaf,

That's great, thank you very much for breaking it down for me. Helps a lot!

Best regards,
David

Post Reply