Step 1:
In AppGini software select option list for the table field and put any value like "1;;2"
Step 2:
After compiling and installing the app goto hooks/table_name.php and insert below code block for the init function
Code: Select all
function COVID_cases_init(&$options, $memberInfo, &$args) {
$PeriodWeekly = 5;
$PeriodDaily = 5;
$PeriodHalfDaily = 5;
$PeriodMonthly = 5;
$PeriodBiMonthly = 5;
$PeriodQuarterly = 5;
$PeriodSixMonthly = 5;
$PeriodAnnualy = 5;
$mode = 2;
$file = '.\hooks\Table_name.field_name.csv';
file_put_contents('.\hooks\Table_name.field_name.csv', "");
if ($mode == 1) {
$TDate = date("Y-m-d");
for($i=0; $i<=$PeriodHalfDaily;$i++){
$morning = date("Y-m-d", strtotime($TDate. ' - '.$i.' days'))." - Morning";
$evening = date("Y-m-d", strtotime($TDate. ' - '.$i.' days'))." - Evening";
$current = $morning . ";;" . $evening . ";;";
$current = file_get_contents($file);
$current .= $morning . ";;" . $evening . ";;";
file_put_contents($file, $current);
}
}
if ($mode == 2) {
$TDate = date("Y-m-d");
for($i=0; $i<=$PeriodDaily;$i++){
$current = date("Y-m-d", strtotime($TDate. ' - '.$i.' days')) . ";;";
$current = file_get_contents($file);
$current .= date("Y-m-d", strtotime($TDate. ' - '.$i.' days')) . ";;";
file_put_contents($file, $current);
}
}
if ($mode == 3) {
$monday = strtotime("last monday");
$monday = date('w', $monday)==date('w') ? $monday+7*86400 : $monday;
$sunday = strtotime(date("Y-m-d",$monday)." +6 days");
for($i=0; $i<=$PeriodWeekly;$i++){
$n = $i*7;
$start_date = date("Y-m-d",strtotime(date("Y-m-d",$monday)." -$n days"));
$end_date = date("Y-m-d",strtotime(date("Y-m-d",$sunday)." -$n days"));
$current = $start_date . " to " . $end_date . ";;";
$current = file_get_contents($file);
$current .= $start_date . " to " . $end_date . ";;";
file_put_contents($file, $current);
}
}
if ($mode == 4) {
$TDate = date("Y-m-d");
for($i=0; $i<=$PeriodMonthly;$i++){
$current = date("Y, M", strtotime($TDate. ' - '.$i.' months')) . ";;";
$current = file_get_contents($file);
$current .= date("Y, M", strtotime($TDate. ' - '.$i.' months')) . ";;";
file_put_contents($file, $current);
}
}
if ($mode == 5) {
if((date("m")%2)>0){
$TDate = date("Y-m-01");
$TDate = date("Y-m-01", strtotime($TDate. ' + 1 months'));
}else{
$TDate = date("Y-m-01");
}
for($i=1; $i<=$PeriodBiMonthly;$i++){
$current = date("Y, M", strtotime($TDate. ' - '.(($i*2)-1).' months')). " to " . date("Y, M", strtotime($TDate. ' - '.(($i*2)-2).' months')) . ";;";
$current = file_get_contents($file);
$current .= date("Y, M", strtotime($TDate. ' - '.(($i*2)-1).' months')). " to " . date("Y, M", strtotime($TDate. ' - '.(($i*2)-2).' months')) . ";;";
file_put_contents($file, $current);
}
}
if ($mode == 6) {
if((date("m")%3)>0){
$TDate = date("Y-m-01");
$csoun=3-(date("m")%3);
$TDate = date("Y-m-01", strtotime($TDate. ' + '.$csoun.' months'));
}else{
$TDate = date("Y-m-01");
}
for($i=1; $i<=$PeriodQuarterly;$i++){
$current = date("Y, M", strtotime($TDate. ' - '.(($i*3)-1).' months')). " to " . date("Y, M", strtotime($TDate. ' - '.(($i*3)-3).' months')) . ";;";
$current = file_get_contents($file);
$current .= date("Y, M", strtotime($TDate. ' - '.(($i*3)-1).' months')). " to " . date("Y, M", strtotime($TDate. ' - '.(($i*3)-3).' months')) . ";;";
file_put_contents($file, $current);
}
}
if ($mode == 7) {
if((date("m")%6)>0){
$TDate = date("Y-m-01");
$csoun=6-(date("m")%6);
$TDate = date("Y-m-01", strtotime($TDate. ' + '.$csoun.' months'));
}else{
$TDate = date("Y-m-01");
}
for($i=1; $i<=$PeriodSixMonthly;$i++){
$current = date("Y, M", strtotime($TDate. ' - '.(($i*6)-1).' months')). " to " . date("Y, M", strtotime($TDate. ' - '.(($i*6)-6).' months')) . ";;";
$current = file_get_contents($file);
$current .= date("Y, M", strtotime($TDate. ' - '.(($i*6)-1).' months')). " to " . date("Y, M", strtotime($TDate. ' - '.(($i*6)-6).' months')) . ";;";
file_put_contents($file, $current);
}
}
if ($mode == 8) {
$TDate = date("Y-m-01");
for($i=1; $i<=$PeriodAnnualy;$i++){
$current = date("Y", strtotime($TDate. ' - '.($i-1).' years')) . ";;";
$current = file_get_contents($file);
$current .= date("Y", strtotime($TDate. ' - '.($i-1).' years')) . ";;";
file_put_contents($file, $current);
}
}
return TRUE;
}
Replace "Table_name.field_name" with your desired values
$mode --> select dates, weeks based on the value
1 = twice daily
2 = daily
3 = weekly
4 = monthly
5 = bimonthly
6 = quartery
7 = six monthly
8 = yearly
$PeriodWeekly like variables --> gives the number of options
Step 3:
To make the dates descending change the common.js.php below section
"return b.text > a.text;" instead of "return a.text > b.text;"
If you want you can remove the below code block
Code: Select all
/* function to sort select2 search results by relevence */
AppGini.sortSelect2ByRelevence = function(res, cont, qry) {
return res.sort(function(a, b) {
if(qry.term) {
var aStart = a.text.match(new RegExp("^" + qry.term, "i")) !== null;
var bStart = b.text.match(new RegExp("^" + qry.term, "i")) !== null;
if(aStart && !bStart) return false;
if(!aStart && bStart) return true;
}
return b.text > a.text;
});
}
One drawback, if you have an exiting record with a date selected that is not available in the newly created list (as it is already older than 5 weeks), the data will still be displayed in the tableview, but not in the detailview, as the reference to the possible selections will not be available any more.