Пример #1
0
 function createQueryResultTable($records, $rowNum)
 {
     $table = "<table id='query_results' class='" . getTableClass() . "'>\n";
     //call shared recusive function above for header printing
     $table .= "<tr><th>&nbsp;</th><th>";
     if ($records[0] instanceof SObject) {
         $table .= implode("</th><th>", $this->getQueryResultHeaders($records[0]));
     } else {
         $table .= implode("</th><th>", $this->getQueryResultHeaders(new SObject($records[0])));
     }
     $table .= "</th></tr>\n";
     //Print the remaining rows in the body
     foreach ($records as $record) {
         //call shared recusive function above for row printing
         $table .= "<tr><td>" . $rowNum++ . "</td><td>";
         if ($record instanceof SObject) {
             $row = $this->getQueryResultRow($record);
         } else {
             $row = $this->getQueryResultRow(new SObject($record));
         }
         for ($i = 0; $i < count($row); $i++) {
             if ($row[$i] instanceof QueryResult && !is_array($row[$i])) {
                 $row[$i] = array($row[$i]);
             }
             if (isset($row[$i][0]) && $row[$i][0] instanceof QueryResult) {
                 foreach ($row[$i] as $qr) {
                     $table .= $this->createQueryResultTable($qr->records, 1);
                     if ($qr != end($row[$i])) {
                         $table .= "</td><td>";
                     }
                 }
             } else {
                 $table .= $row[$i];
             }
             if ($i + 1 != count($row)) {
                 $table .= "</td><td>";
             }
         }
         $table .= "</td></tr>\n";
     }
     $table .= "</table>";
     return $table;
 }
Пример #2
0
function displaySearchResult($records, $searchTimeElapsed)
{
    //Check if records were returned
    if ($records) {
        if (WorkbenchConfig::get()->value("areTablesSortable")) {
            addFooterScript("<script type='text/javascript' src='" . getPathToStaticResource('/script/sortable.js') . "></script>");
        }
        try {
            print "<a name='sr'></a><div style='clear: both;'><br/><h2>Search Results</h2>\n";
            print "<p>Returned " . count($records) . " total record";
            if (count($records) !== 1) {
                print 's';
            }
            print " in ";
            printf("%01.3f", $searchTimeElapsed);
            print " seconds:</p>";
            $searchResultArray = array();
            foreach ($records as $record) {
                $recordObject = new Sobject($record->record);
                $searchResultArray[$recordObject->type][] = $recordObject;
            }
            foreach ($searchResultArray as $recordSetName => $records) {
                echo "<h3>{$recordSetName}</h3>";
                print "<table id='" . $recordSetName . "_results' class='" . getTableClass() . "'>\n";
                //Print the header row on screen
                $record0 = $records[0];
                print "<tr><th></th>";
                //If the user queried for the Salesforce ID, this special method is nessisary
                //to export it from the nested SOAP message. This will always be displayed
                //in the first column regardless of search order
                if (isset($record0->Id)) {
                    print "<th>Id</th>";
                }
                if ($record0->fields) {
                    foreach ($record0->fields->children() as $field) {
                        print "<th>";
                        print htmlspecialchars($field->getName(), ENT_QUOTES);
                        print "</th>";
                    }
                } else {
                    print "</td></tr>";
                }
                print "</tr>\n";
                //Print the remaining rows in the body
                $rowNum = 1;
                foreach ($records as $record) {
                    print "<tr><td>{$rowNum}</td>";
                    $rowNum++;
                    //Another check if there are ID columns in the body
                    if (isset($record->Id)) {
                        print "<td>" . addLinksToIds($record->Id) . "</td>";
                    }
                    //Print the non-ID fields
                    if (isset($record->fields)) {
                        foreach ($record->fields as $datum) {
                            print "<td>";
                            if ($datum) {
                                print localizeDateTimes(addLinksToIds(htmlspecialchars($datum, ENT_QUOTES)));
                            } else {
                                print "&nbsp;";
                            }
                            print "</td>";
                        }
                        print "</tr>\n";
                    } else {
                        print "</td></tr>\n";
                    }
                }
                print "</table>&nbsp;<p/>";
            }
            print "</div>\n";
        } catch (Exception $e) {
            $errors = null;
            $errors = $e->getMessage();
            print "<p />";
            displayError($errors, false, true);
        }
    } else {
        print "<p><a name='sr'>&nbsp;</a></p>";
        displayError("Sorry, no records returned.");
    }
    include_once 'footer.php';
}