I've resolved the column problem. However, I can't get an images to show on the page. The images in the table don't display, and I put an <img> tag in the MyReport.view. php directly, and it shows the image on the page, but the profile_Image's don't. But the same <img> tag worked on a .html file in the same directory.
I've pasted my DataTables code below.
Images not displaying
Test Image showing, with table images displaying
MyReport.php
<?php
//Step 1: Load KoolReport
require_once "../../load.koolreport.php";
//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;
protected function defaultParamValues()
{
$date=date_create("2021-07-16");
date_add($date,date_interval_create_from_date_string("-42 days"));
$sd = date_format($date,"Y-m-d");
return array(
"startDatePicker"=>date($sd . " 00:00:00"),
"endDatePicker"=>date("Y-m-d 23:59:59"),
"select"=>"",
"locationSelector"=>"",
"dealhack"=>"",
"user"=>"",
"companySelector"=>"",
);
// return array(
// "years"=>array(2003),
// "customerNames"=>array(),
// "productLines"=>array(),
// );
}
protected function bindParamsToInputs()
{
return array(
"startDatePicker",
"endDatePicker",
"select",
"locationSelector",
"dealhack",
"user",
"companySelector"
);
// return array(
// "years",
// "customerNames",
// "productLines"
// );
}
protected function settings()
{
$config = include "../../config.php";
return array(
"dataSources"=>$config
);
}
protected function setup()
{
//Debug show all param values
// var_dump($this->params); echo "<br>";
$query_params = array();
if($this->params["startDatePicker"]!=array()){
$query_params[":start"] = $this->params["startDatePicker"];
}
if($this->params["endDatePicker"]!=array()){
$query_params[":end"] = $this->params["endDatePicker"];
}
if (($this->params["select"]!="Any")){
$query_params[":tribe"] = $this->params["select"];
}
if (($this->params["dealhack"]!="Any")){
$query_params[":dealhack"] = $this->params["dealhack"];
}
if (($this->params["user"]!="")){
$query_params[":user"] = $this->params["user"];
}
if (($this->params["locationSelector"]!="Any")){
$query_params[":location"] = $this->params["locationSelector"];
}
if (($this->params["companySelector"]!="Any")){
$query_params[":company"] = $this->params["companySelector"];
}
// if (! empty($this->params["select"])){
// $query_params[":tribe"] = $this->params["select"];
// }
// $this->src('dealhackdb')
// ->query("Select
// -- tbl_dealhack.id,
// -- tbl_profile.user_id AS UserID,
// -- tblprofile.Picture
// tbl_profile.Profile_Image,
// tbl_user.firstname AS 'First Name',
// tbl_user.surname AS 'Surname',
// hack_description AS Decription,
// created_date AS 'Created',
// attachment_location AS 'Attachment Location',
// uploaded_date AS Uploaded ,
// Company,
// TribeName AS 'Tribe Name'
// From tbl_dealhack
// left join tbl_dealhack_attachments on tbl_dealhack_attachments.dealhack_id = tbl_dealhack.id
// left join tbl_profile on tbl_profile.user_id = tbl_dealhack.user_id
// Left join tbl_attachment_type on tbl_attachment_type.id = tbl_dealhack_attachments.attachment_type_id
// left join tbl_companytribe on tbl_companytribe.id = tbl_profile.TribeID
// left join tbl_category on tbl_category.id = tbl_dealhack.category_id
// left join tbl_user on tbl_profile.user_id = tbl_user.id
// WHERE 1=1
// AND attachment_type_id = 4
//
// "
// .(($this->params["startDatePicker"]!=array())?"AND uploaded_date BETWEEN (:start) ":"").""
// .(($this->params["endDatePicker"]!=array())?" AND (:end) ":"").""
// .((($this->params["select"]!='Any'))?"AND TribeName LIKE (:tribe) ":"").""
// .((($this->params["dealhack"]!='Any'))?"AND category = (:dealhack) ":"").""
// .((($this->params["locationSelector"]!='Any'))?"AND attachment_location LIKE (:location) ":"").""
// .((($this->params["companySelector"]!='Any'))?"AND Company LIKE (:company) ":"").""
// .((($this->params["user"]!=''))?"AND email = (:user) ":"").""
// )
// ->params($query_params)
// ->pipe($this->dataStore("sales"));
// // GROUP BY year, productLine, customerName
//display image from Profile table using Map (unfinished)
$this->src('dealhackdb')
->query("Select
-- tbl_dealhack.id,
-- tbl_profile.user_id AS UserID,
-- tblprofile.Picture
tbl_profile.Profile_Image AS 'Profile Image', -- get the profile image name as it is
-- tbl_profile.Profile_Image AS FileName,
tbl_user.firstname AS 'First Name',
tbl_user.surname AS 'Surname',
hack_description AS Decription,
created_date AS 'Created',
attachment_location AS 'Attachment Location',
uploaded_date AS Uploaded ,
Company,
TribeName AS 'Tribe Name'
From tbl_dealhack
left join tbl_dealhack_attachments on tbl_dealhack_attachments.dealhack_id = tbl_dealhack.id
left join tbl_profile on tbl_profile.user_id = tbl_dealhack.user_id
Left join tbl_attachment_type on tbl_attachment_type.id = tbl_dealhack_attachments.attachment_type_id
left join tbl_companytribe on tbl_companytribe.id = tbl_profile.TribeID
left join tbl_category on tbl_category.id = tbl_dealhack.category_id
left join tbl_user on tbl_profile.user_id = tbl_user.id
WHERE 1=1
AND attachment_type_id = 4
"
.(($this->params["startDatePicker"]!=array())?"AND uploaded_date BETWEEN (:start) ":"").""
.(($this->params["endDatePicker"]!=array())?" AND (:end) ":"").""
.((($this->params["select"]!='Any'))?"AND TribeName LIKE (:tribe) ":"").""
.((($this->params["dealhack"]!='Any'))?"AND category = (:dealhack) ":"").""
.((($this->params["locationSelector"]!='Any'))?"AND attachment_location LIKE (:location) ":"").""
.((($this->params["companySelector"]!='Any'))?"AND Company LIKE (:company) ":"").""
.((($this->params["user"]!=''))?"AND email = (:user) ":"").""
)
->params($query_params)
//add the Map process after the query and params methods
->pipe(new \koolreport\processes\Map(array(
"{value}" => function($row) {
$row["Profile Image"] = "<img width='25' src='/../..' " . $row["Profile Image"] . "alt='Row Image' />"; //construct the profile image img tag with src path
return $row;
}
)))
->pipe($this->dataStore("sales"));
// .((! empty($this->params["select"]))?"AND TribeName LIKE (:tribe) ":"").
// .(($this->params["startDatePicker"]!=array())?"AND created_date BETWEEN (:start) ":"").""
// .(($this->params["endDatePicker"]!=array())?" AND (:end) ":"").""
// .(($this->params["select"]!=array())?"AND TribeName LIKE (:tribe) ":"").
//
}
}
MyReport.view.php: DataTables Create Code as requested
<?php
use \koolreport\datagrid\DataTables;
use \koolreport\inputs\DateTimePicker;
use \koolreport\widgets\koolphp\Table;
use \koolreport\inputs\Select2;
use \koolreport\inputs\TextBox;
?>
<div class="report-content">
<div class="text-center">
<h1>Dealhack Links</h1>
<p class="lead">
The example demonstrate how to build dynamic reports with multiple data filters
</p>
</div>
<!-- Filters Form-->
<form method="post">
<div class="col-md-12 form-group">
<div class="row">
<div class="col-md-6">
<!-- <b>Select Years</b>-->
<b>Start Date</b>
<?php
DateTimePicker::create(array(
"name"=>"startDatePicker",
"maxDate"=>"@endDatePicker",
"format"=>"DD/MM/YYYY HH:mm",
"themeBase"=>"bs4",
));
?>
</div>
<div class="col-md-6">
<!-- <b>Select Product Lines</b>-->
<b>End Date</b>
<?php
DateTimePicker::create(array(
"name"=>"endDatePicker",
"minDate"=>"@startDatePicker",
"format"=>"DD/MM/YYYY HH:mm",
"themeBase"=>"bs4",
));
?>
</div>
</div> <!--FROM & TO DATE ROW end-->
<!-- SECOND ROW, TRIBE & LOCATION FILTERS-->
<div class="row">
<div class="col-md-6"> <!--TRIBE COL-->
<div class="form-group">
<b>Tribe</b>
<?php
Select2::create(array(
"name"=>"select",
// "dataStore"=>$this->dataStore("sales"),
"dataSource"=>$this->src("dealhackdb")->query("
select 'Any' AS 'Tribe Name'
UNION
Select distinct
TribeName AS 'Tribe Name'
From tbl_dealhack
left join tbl_dealhack_attachments on tbl_dealhack_attachments.dealhack_id = tbl_dealhack.id
left join tbl_profile on tbl_profile.user_id = tbl_dealhack.user_id
Left join tbl_attachment_type on tbl_attachment_type.id = tbl_dealhack_attachments.attachment_type_id
left join tbl_companytribe on tbl_companytribe.id = tbl_profile.TribeID
")->params(
$this->params["startDatePicker"]!=array()?
array(":start"=>$this->params["startDatePicker"]):
array(),
$this->params["endDatePicker"]!=array()?
array(":end"=>$this->params["endDatePicker"]):
array()
),
"dataBind"=>"Tribe Name",
"attributes"=>array(
"class"=>"form-control",
)
));
// place above params bit for filters to be enable
// ".( $this->params["startDatePicker"]!=array()?"WHERE created_date BETWEEN (:start) ":"")."
// ".(($this->params["endDatePicker"]!=array())?" AND (:end) ":"")."
// AND attachment_type_id = 4
// group by TribeName
?>
</div>
</div> <!--TRIBE COL end-->
<div class="col-md-6">
<B> URL Location:</B>
<?php
Select2::create(array(
//if i change this select to location, it causes the redirect error
"name"=>"locationSelector",
// "dataStore"=>$this->dataStore("sales"),
"dataSource"=>$this->src("dealhackdb")->query("
select 'Any' AS 'Attachment Location'
UNION
SELECT distinct attachment_location AS 'Attachment Location'
FROM dealhack.tbl_dealhack_attachments
WHERE attachment_type_id = 4;
")->params(
$this->params["startDatePicker"]!=array()?
array(":start"=>$this->params["startDatePicker"]):
array(),
$this->params["endDatePicker"]!=array()?
array(":end"=>$this->params["endDatePicker"]):
array()
),
"dataBind"=>"Attachment Location",
"attributes"=>array(
"class"=>"form-control",
)
));
?>
</div>
</div> <!--2nd Row end-->
<div class="row">
<!-- 3rd Row Filters-->
<div class="col-md-6">
<b> Dealhack Type:</b>
<?php
Select2::create(array(
//if i change this select to location, it causes the redirect error
"name"=>"dealhack",
// "dataStore"=>$this->dataStore("sales"),
"dataSource"=>$this->src("dealhackdb")->query("
select 'Any' AS 'Dealhack Type'
UNION
SELECT category AS 'Dealhack Type'
FROM dealhack.tbl_category;
")->params(
$this->params["startDatePicker"]!=array()?
array(":start"=>$this->params["startDatePicker"]):
array(),
$this->params["endDatePicker"]!=array()?
array(":end"=>$this->params["endDatePicker"]):
array()
),
"dataBind"=>"Dealhack Type",
"attributes"=>array(
"class"=>"form-control",
)
));
?>
</div>
<div class="col-md-6">
<b> Company:</b>
<?php
Select2::create(array(
//if i change this select to location, it causes the redirect error
"name"=>"companySelector",
// "dataStore"=>$this->dataStore("sales"),
"dataSource"=>$this->src("dealhackdb")->query("
select 'Any' AS 'Company'
UNION
SELECT distinct Company AS Company
FROM dealhack.tbl_profile;
")->params(
$this->params["startDatePicker"]!=array()?
array(":start"=>$this->params["startDatePicker"]):
array(),
$this->params["endDatePicker"]!=array()?
array(":end"=>$this->params["endDatePicker"]):
array()
),
"dataBind"=>"Company",
"attributes"=>array(
"class"=>"form-control",
)
));
?>
</div>
</div> <!-- 3rd Row filters End-->
<div class="row">
<!-- 4th Row Filters-->
<div class="col-md-6">
<b> User:</b>
<?php
TextBox::create(array(
"name"=>"user",
"attributes"=>array(
"class"=>"form-control",
"placeholder"=>"Enter Exact Email"
)
));
// Select2::create(array(
// //if i change this select to location, it causes the redirect error
// "name"=>"user",
//// "dataStore"=>$this->dataStore("sales"),
// "dataSource"=>$this->src("dealhackdb")->query("
// select '' AS 'User'
// UNION
// SELECT concat(firstname,' ', surname) AS User FROM dealhack.tbl_user WHERE firstname IS NOT NULL OR surname IS NOT NULL;
//
// ")->params(
// $this->params["startDatePicker"]!=array()?
// array(":start"=>$this->params["startDatePicker"]):
// array(),
// $this->params["endDatePicker"]!=array()?
// array(":end"=>$this->params["endDatePicker"]):
// array()
// ),
// "dataBind"=>"User",
// "attributes"=>array(
// "class"=>"form-control",
// )
// ));
?>
</div>
</div><!-- 4th Row Filters End-->
</div> <!--1st Form-Group (under post) end-->
<div class="form-group">
<button class="btn btn-primary">Submit</button>
</div>
</form>
<!-- <img src="/../../img/download.png" alt="TEST IMAGE"> -->
<!--This image displays in the page, but the images in the query do not, despite being in the same directory-->
<!-- TABLE-->
<?php
DataTables::create(array(
"dataSource"=>$this->dataStore("sales"),
"options"=>array(
"paging"=>true),
"themeBase"=>"bs4", // Optional option to work with Bootsrap 4
"cssClass"=>array(
"table"=>"table table-striped table-bordered "
)
));
?>
</div>