0

Live page can be seen here

I'm aiming to apply a specific class to each list item in the second UL based upon the list it appears on. The second json call returns an ID that matches the ID and name pair which can be found in the first list.

I'd like to have each listID assigned to a $variable called $listID with the value that is the name of that list.

eg $514fc8993f53cfb366006851 = "To Do";

I could then use an if statement to assign a class based upon a series of if statements in the second block of PHP.

Any help generating these variables would be greatly appreciated.

The relevant code is as follows:

<p>The sample board contains the following lists:</p>
<ul>
    <?
        $lists_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/lists?key=9ee57574e9f968cedf9ac9964d2f7c4e");
        $lists = json_decode($lists_enc, true);
        $testing = array();

        foreach ($lists as $list) {
            $id = $list["id"];
            $name = $list["name"];

            echo "<li>".$name." (".$id.")</li>\n";
        }
        echo "</ul>";
    ?>

<p>The sample board contains the following cards:</p>
<ul>
    <?
        $cards_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/cards?fields=name,idList&key=9ee57574e9f968cedf9ac9964d2f7c4e");      
        $cards = json_decode($cards_enc, true);

        foreach ($cards as $card) {
        echo "<li class=".$status.">".$card["name"]."</li>\n";
      }  

    ?>
</ul>
Bryce York
  • 956
  • 1
  • 15
  • 35
  • The goal is to have 3 variables created from this json - https://api.trello.com/1/board/514fc8993f53cfb366006850/lists?key=9ee57574e9f968cedf9ac9964d2f7c4e which allows me to convert the id (which is included in the other json output) to the name (which is only in this json output) – Bryce York Mar 25 '13 at 23:48

2 Answers2

1
<?php
//Reference the trello API's
$lists_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/lists?key=9ee57574e9f968cedf9ac9964d2f7c4e");
$lists = json_decode($lists_enc, true);
$cards_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/cards?fields=name,idList&key=9ee57574e9f968cedf9ac9964d2f7c4e");      
$cards = json_decode($cards_enc, true);
//Go through every card
foreach ($cards as $card) {
    $idCard = $card['id'];

    //Go through all lists
    foreach ($lists as $list) {
        $idList = $list['id'];

        //If card is related to list, then create an associative variable
        //with the id of list
        if ($card['id'] == $list['id'] {
            $idList[$idList][] = $idCard;
        }
    }
    //gone through all lists
}
//-- gone through all cards
?>

Now you will have like $idList[514fc8993f53cfb366006851], $idList[514fc8993f53cfb366006852] and $idList[514fc8993f53cfb366006853] and these should contain the cards related to the lists. I have not test the code though, but I hope you get the picture...

bestprogrammerintheworld
  • 5,417
  • 7
  • 43
  • 72
0
<?
  // Create array $convert[] to allow translation of listID into listName
    for ($i=0; $i < count($lists); $i++) { 
      $convert[$lists[$i][id]]=$lists[$i][name];
    }

  // iterate over all cards, create list item for each with class that has a slug equivalent of the list name  
    foreach ($cards as $card) {
       $id = $card[idList];
       echo "<li class=".slug($convert[$id]).">".$card["name"]."</li>\n";
    }  

?>
Bryce York
  • 956
  • 1
  • 15
  • 35