Post

2 followers Follow
0
Avatar

Using in_array()

Hi

I have an app with a lot of items, and one of the fields for each item is a date field called "Deadline".

Using GlobiFlow I need to output a PDF with a complete list of those items, but I need the list to be "grouped" by months. So if I have 3 items with "Deadline" set in May, then I need a header saying "May" and below this header the 3 items, and then the items for "June" with their own header etc.

My idea is to:

  1. Define an empty array to hold year+month for later sanity checks
  2. Loop all items and compare the date with the array from 1)
  3. If date of item does not exist in array, then add to array for later test + output a header

But it seems like the following test is always true

in_array([(Variable) yearmonth_current], [(Variable) yearmonth_array])

I have triple-checked all variable names, and all is good there. 

Suggestions? 

Bo Dudek

Please sign in to leave a comment.

1 comment

0
Avatar

Hi Bo,

in Globiflow you can't create an array in one variable and use it in another variable, it must all be done in one variable using a function with this syntax:

foo(); function foo() {
calculate something
}


I would recommend this way:
Step 1: Create a view in your app where all items are in whose deadline you want in the PDF. 
Step 2: the flow

Get view from your app
Then create 2 empty variables:
deadlines = ""
yearMonth = ""
for each Ref item from the view
dates = [(Variable) deadlines].",".date("Y-m-d", strtotime([(Ref.item] Deadline]))
yearMonth = [(Variable) yearMonth].",".date("Y-m", strtotime([(Ref.item] Deadline]))
continue
deadlines = trim([(Variable) deadlines],",")
yearMonth = trim([(Variable) yearMonth],",")
yearMonthUnique = array_unique([(Variable) yearMonth])

 

yearMonthUniqueSorted =
foo(); function foo() {
$arr = explode(",",[(Variable) yearMonthUnique];
for ($i = 1; $i < sizeof($arr); $i++){
      for ($j = 0; $j < $i; $j++){
            if ($arr[$i] < $arr[$j]) {
                $temp = $arr[$i];
                $arr[$i] = $arr[$j];
                $arr[$j] = $temp;
           }
     }
}
return implode(",",$arr); 
}

 

deadlinesSorted =
foo(); function foo() {
$arr = explode(",",[(Variable) deadlines];
for ($i = 1; $i < sizeof($arr); $i++){
      for ($j = 0; $j < $i; $j++){
            if ($arr[$i] < $arr[$j]) {
                $temp = $arr[$i];
                $arr[$i] = $arr[$j];
                $arr[$j] = $temp;
           }
     }
}
return implode(",",$arr); 
}

 

listBuilder = 
foo(); function foo() {
$yearMonthArr = explode(",", [(Variable) yearMonthUniqueSorted]);
$deadlineArr = explode(",",[(Variable) deadlinesSorted]);
$list = array();
for($i = 0; $i < sizeof($yearMonthArr); $i++){;
     $monthArr = array();
     $mName = date("F",strtotime($yearMonthArr[$i]));
     $monthList = "";
     for($j = 0; $j < sizeof($deadlineArr); $j++){;
         $deadlineMonth = date("Y-m", strtotime($deadlineArr[$j]));
         if($deadlineMonth == $yearMonthArr[$i]){
            $monthArr[] = date("m/d/Y", strtotime($deadlineArr[$j]));
        }
       $monthList = "<strong>".$mName."</strong><br />".implode("<br />",$monthArr);
   }
  $list[] = $monthList;
}
return implode("<br /><br />",$list);
}

Then put the var listBuilder into the PDF maker.

One tip: Log into Globiflow, click Help and in the Help Menu click "Join our workspace on Podio" - there you get many many infos about how to use Globiflow and always an answer to your questions. It's a great community.

Rainer

Rainer Grabowski 0 votes