Exemplo n.º 1
0
 private function GetDataSetItems($displayId, $text)
 {
     $db =& $this->db;
     // Extra fields for data sets
     $dataSetId = $this->GetOption('datasetid');
     $upperLimit = $this->GetOption('upperLimit');
     $lowerLimit = $this->GetOption('lowerLimit');
     $filter = $this->GetOption('filter');
     $ordering = $this->GetOption('ordering');
     Debug::LogEntry('audit', 'Then template for each row is: ' . $text);
     // Combine the column id's with the dataset data
     $matches = '';
     preg_match_all('/\\[(.*?)\\]/', $text, $matches);
     $columnIds = array();
     foreach ($matches[1] as $match) {
         // Get the column id's we are interested in
         Debug::LogEntry('audit', 'Matched column: ' . $match);
         $col = explode('|', $match);
         $columnIds[] = $col[1];
     }
     // Get the dataset results
     Kit::ClassLoader('dataset');
     $dataSet = new DataSet($db);
     $dataSetResults = $dataSet->DataSetResults($dataSetId, implode(',', $columnIds), $filter, $ordering, $lowerLimit, $upperLimit, $displayId, true);
     $items = array();
     foreach ($dataSetResults['Rows'] as $row) {
         // For each row, substitute into our template
         $rowString = $text;
         foreach ($matches[1] as $sub) {
             // Pick the appropriate column out
             $subs = explode('|', $sub);
             $rowString = str_replace('[' . $sub . ']', $row[$subs[0]], $rowString);
         }
         $items[] = $rowString;
     }
     return $items;
 }
Exemplo n.º 2
0
 public function DataSetTableHtml($displayId = 0, $isPreview = true)
 {
     $db =& $this->db;
     // Show a preview of the data set table output.
     $dataSetId = $this->GetOption('datasetid');
     $upperLimit = $this->GetOption('upperLimit');
     $lowerLimit = $this->GetOption('lowerLimit');
     $filter = $this->GetOption('filter');
     $ordering = $this->GetOption('ordering');
     $columnIds = $this->GetOption('columns');
     $showHeadings = $this->GetOption('showHeadings');
     $rowsPerPage = $this->GetOption('rowsPerPage');
     if ($columnIds == '') {
         return 'No columns';
     }
     // Set an expiry time for the media
     $media = new Media();
     $layout = new Layout();
     $expires = time() + $this->GetOption('updateInterval', 3600) * 60;
     // Create a data set view object, to get the results.
     $dataSet = new DataSet($db);
     if (!($dataSetResults = $dataSet->DataSetResults($dataSetId, $columnIds, $filter, $ordering, $lowerLimit, $upperLimit, $displayId))) {
         return;
     }
     $rowCount = 1;
     $rowCountThisPage = 1;
     $totalRows = count($dataSetResults['Rows']);
     if ($rowsPerPage > 0) {
         $totalPages = $totalRows / $rowsPerPage;
     } else {
         $totalPages = 1;
     }
     $table = '<div id="DataSetTableContainer" totalRows="' . $totalRows . '" totalPages="' . $totalPages . '">';
     foreach ($dataSetResults['Rows'] as $row) {
         if ($rowsPerPage > 0 && $rowCountThisPage >= $rowsPerPage || $rowCount == 1) {
             // Reset the row count on this page
             $rowCountThisPage = 0;
             if ($rowCount > 1) {
                 $table .= '</tbody>';
                 $table .= '</table>';
             }
             // Output the table header
             $table .= '<table class="DataSetTable">';
             if ($showHeadings == 1) {
                 $table .= '<thead>';
                 $table .= ' <tr class="HeaderRow">';
                 foreach ($dataSetResults['Columns'] as $col) {
                     $table .= '<th class="DataSetColumnHeaderCell">' . $col['Text'] . '</th>';
                 }
                 $table .= ' </tr>';
                 $table .= '</thead>';
             }
             $table .= '<tbody>';
         }
         $table .= '<tr class="DataSetRow DataSetRow' . ($rowCount % 2 ? 'Odd' : 'Even') . '" id="row_' . $rowCount . '">';
         // Output each cell for these results
         for ($i = 0; $i < count($dataSetResults['Columns']); $i++) {
             // Pull out the cell for this row / column
             $replace = $row[$i];
             // What if this column is an image column type?
             if ($dataSetResults['Columns'][$i]['DataTypeID'] == 4) {
                 // Download the image, alter the replace to wrap in an image tag
                 $file = $media->addModuleFileFromUrl(str_replace(' ', '%20', htmlspecialchars_decode($replace)), 'datasetview_' . md5($dataSetId . $dataSetResults['Columns'][$i]['DataSetColumnID'] . $replace), $expires);
                 // Tag this layout with this file
                 $layout->AddLk($this->layoutid, 'module', $file['mediaId']);
                 $replace = $isPreview ? '<img src="index.php?p=module&mod=image&q=Exec&method=GetResource&mediaid=' . $file['mediaId'] . '" />' : '<img src="' . $file['storedAs'] . '" />';
             }
             $table .= '<td class="DataSetColumn" id="column_' . ($i + 1) . '"><span class="DataSetCellSpan" id="span_' . $rowCount . '_' . ($i + 1) . '">' . $replace . '</span></td>';
         }
         $table .= '</tr>';
         $rowCount++;
         $rowCountThisPage++;
     }
     $table .= '</tbody>';
     $table .= '</table>';
     $table .= '</div>';
     return $table;
 }
Exemplo n.º 3
0
 private function GetDataSetItems($displayId, $isPreview, $text)
 {
     $db =& $this->db;
     // Extra fields for data sets
     $dataSetId = $this->GetOption('datasetid');
     $upperLimit = $this->GetOption('upperLimit');
     $lowerLimit = $this->GetOption('lowerLimit');
     $filter = $this->GetOption('filter');
     $ordering = $this->GetOption('ordering');
     Debug::LogEntry('audit', 'Then template for each row is: ' . $text);
     // Set an expiry time for the media
     $media = new Media();
     $layout = new Layout();
     $expires = time() + $this->GetOption('updateInterval', 3600) * 60;
     // Combine the column id's with the dataset data
     $matches = '';
     preg_match_all('/\\[(.*?)\\]/', $text, $matches);
     $columnIds = array();
     foreach ($matches[1] as $match) {
         // Get the column id's we are interested in
         Debug::LogEntry('audit', 'Matched column: ' . $match);
         $col = explode('|', $match);
         $columnIds[] = $col[1];
     }
     // Get the dataset results
     $dataSet = new DataSet($db);
     if (!($dataSetResults = $dataSet->DataSetResults($dataSetId, implode(',', $columnIds), $filter, $ordering, $lowerLimit, $upperLimit, $displayId))) {
         return;
     }
     // Create an array of header|datatypeid pairs
     $columnMap = array();
     foreach ($dataSetResults['Columns'] as $col) {
         $columnMap[$col['Text']] = $col;
     }
     Debug::Audit(var_export($columnMap, true));
     $items = array();
     foreach ($dataSetResults['Rows'] as $row) {
         // For each row, substitute into our template
         $rowString = $text;
         foreach ($matches[1] as $sub) {
             // Pick the appropriate column out
             $subs = explode('|', $sub);
             // The column header
             $header = $subs[0];
             $replace = $row[$header];
             // Check in the columns array to see if this is a special one
             if ($columnMap[$header]['DataTypeID'] == 4) {
                 // Download the image, alter the replace to wrap in an image tag
                 $file = $media->addModuleFileFromUrl(str_replace(' ', '%20', htmlspecialchars_decode($replace)), 'ticker_dataset_' . md5($dataSetId . $columnMap[$header]['DataSetColumnID'] . $replace), $expires);
                 // Tag this layout with this file
                 $layout->AddLk($this->layoutid, 'module', $file['mediaId']);
                 $replace = $isPreview ? '<img src="index.php?p=module&mod=image&q=Exec&method=GetResource&mediaid=' . $file['mediaId'] . '" />' : '<img src="' . $file['storedAs'] . '" />';
             }
             $rowString = str_replace('[' . $sub . ']', $replace, $rowString);
         }
         $items[] = $rowString;
     }
     return $items;
 }
Exemplo n.º 4
0
 public function DataSetTableHtml($displayId = 0)
 {
     $db =& $this->db;
     // Show a preview of the data set table output.
     $dataSetId = $this->GetOption('datasetid');
     $upperLimit = $this->GetOption('upperLimit');
     $lowerLimit = $this->GetOption('lowerLimit');
     $filter = $this->GetOption('filter');
     $ordering = $this->GetOption('ordering');
     $columnIds = $this->GetOption('columns');
     $showHeadings = $this->GetOption('showHeadings');
     $rowsPerPage = $this->GetOption('rowsPerPage');
     if ($columnIds == '') {
         return 'No columns';
     }
     // Create a data set view object, to get the results.
     Kit::ClassLoader('dataset');
     $dataSet = new DataSet($db);
     $dataSetResults = $dataSet->DataSetResults($dataSetId, $columnIds, $filter, $ordering, $lowerLimit, $upperLimit, $displayId);
     $rowCount = 1;
     $rowCountThisPage = 1;
     $totalRows = count($dataSetResults['Rows']);
     if ($rowsPerPage > 0) {
         $totalPages = $totalRows / $rowsPerPage;
     } else {
         $totalPages = 1;
     }
     $table = '<div id="DataSetTableContainer" totalRows="' . $totalRows . '" totalPages="' . $totalPages . '">';
     foreach ($dataSetResults['Rows'] as $row) {
         if ($rowsPerPage > 0 && $rowCountThisPage >= $rowsPerPage || $rowCount == 1) {
             // Reset the row count on this page
             $rowCountThisPage = 0;
             if ($rowCount > 1) {
                 $table .= '</tbody>';
                 $table .= '</table>';
             }
             // Output the table header
             $table .= '<table class="DataSetTable">';
             if ($showHeadings == 1) {
                 $table .= '<thead>';
                 $table .= ' <tr class="HeaderRow">';
                 foreach ($dataSetResults['Columns'] as $col) {
                     $table .= '<th class="DataSetColumnHeaderCell">' . $col . '</th>';
                 }
                 $table .= ' </tr>';
                 $table .= '</thead>';
             }
             $table .= '<tbody>';
         }
         $table .= '<tr class="DataSetRow DataSetRow' . ($rowCount % 2 ? 'Odd' : 'Even') . '" id="row_' . $rowCount . '">';
         for ($i = 0; $i < count($dataSetResults['Columns']); $i++) {
             $table .= '<td class="DataSetColumn" id="column_' . ($i + 1) . '"><span class="DataSetCellSpan" id="span_' . $rowCount . '_' . ($i + 1) . '">' . $row[$i] . '</span></td>';
         }
         $table .= '</tr>';
         $rowCount++;
         $rowCountThisPage++;
     }
     $table .= '</tbody>';
     $table .= '</table>';
     $table .= '</div>';
     return $table;
 }