Skip to content

Commit

Permalink
Merge pull request #666 from DiamondLightSource/pre-release/2023-R4.1
Browse files Browse the repository at this point in the history
Merge 2023-R4.1 into Master
  • Loading branch information
NKatti2011 authored Sep 19, 2023
2 parents 89d82b6 + ee38e05 commit fa177c3
Show file tree
Hide file tree
Showing 37 changed files with 319 additions and 185 deletions.
13 changes: 13 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**NOTE**: (PR title should be of the form ticket:short description, e.g. TICKET-123: Add more templates)

**JIRA ticket**: [TICKET-123](https://link.to.jira)

**Summary**:

A brief description of what this pull request aims to achieve

**Changes**:
- List changes made in this pull request

**To test**:
- List actions that should be taken to test that functionality works as expected
20 changes: 4 additions & 16 deletions api/assets/emails/dewar-transfer.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@

Dear local contact: <?php echo $data['LOCALCONTACT'] ?> <?php echo $data['LCEMAIL'] ?>,

Your user: <?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?> requested an internal transfer for his/her dewar(s). Please print this e-mail and affix it on the shipping case and put the dewar for the visit <?php echo $data['VISIT'] ?> on the rack outside the beamline: "to be Stored at Diamond" by the <?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?>.

Local contact for next visit: <?php echo $data['NEXTLOCALCONTACT'] ?> <?php echo $data['LCNEXTEMAIL'] ?>


Dear EHC,

Please collect the dewar from visit <?php echo $data['VISIT'] ?> <?php if($data['FACILITYCODE']): ?>(Dewar Code: <?php echo $data['FACILITYCODE'] ?>)<?php endif; ?> currently stored on the rack outside <?php echo $data['LOCATION'] ?> and transfer it to the <?php echo $data['NEXTLOCATION'] ?> rack in the MX storage room
The dewar should be ready for internal transfer by the <?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?>

Your user: <?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?> from visit <?php echo $data['VISIT'] ?> requested an internal transfer for his/her dewar(s). Please print this e-mail and affix it on the shipping case.

Information for the transfer:

Expand Down Expand Up @@ -42,14 +33,11 @@
Current dewar location
<?php echo $data['LOCATION'] ?>

New Location in storage room
<?php echo $data['NEXTLOCATION'] ?>

Pickup date:
<?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?>

Local contact email (in case of problems finding the dewar):
<?php echo $data['LOCALCONTACT'] ?> <?php echo $data['LCEMAIL'] ?>

Local contact for next visit:
<?php echo $data['NEXTLOCALCONTACT'] ?> <?php echo $data['LCNEXTEMAIL'] ?>

Comments:
<?php echo $data['COMMENTS'] ?>
21 changes: 4 additions & 17 deletions api/assets/emails/html/dewar-transfer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@ <h1 style="font-size: 16px; font-weight: normal; border-bottom: 1px solid #000;

<div class="inset" style="margin: 1%; padding: 1%; margin-bottom: 2%; border-radius: 5px; background: #82d180">
<h2>Local Contact: <?php echo $data['LOCALCONTACT'] ?> <?php echo $data['LCEMAIL'] ?></h2>
<p><?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?> requested an internal transfer for his/her dewar(s). Please print this e-mail and affix it on the shipping case and put the dewar for the visit <?php echo $data['VISIT'] ?> on the rack outside the beamline: "to be Stored at Diamond" by the <?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?></p>
<p>Local contact for next visit: <?php echo $data['NEXTLOCALCONTACT'] ?> <?php echo $data['LCNEXTEMAIL'] ?></p>
<p><?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?> from visit <?php echo $data['VISIT'] ?> requested an internal transfer for his/her dewar(s). Please print this e-mail and affix it on the shipping case.</p>
</div>

<div class="inset" style="margin: 1%; padding: 1%; margin-bottom: 2%; border-radius: 5px; background: #82d180">
<h2>EHCs</h2>
<p>Please collect the dewar from visit <?php echo $data['VISIT'] ?> <?php if($data['FACILITYCODE']): ?>(Dewar Code: <?php echo $data['FACILITYCODE'] ?>)<?php endif; ?> currently stored on the rack outside <?php echo $data['LOCATION'] ?> and transfer it to the <?php echo $data['NEXTLOCATION'] ?> rack in the MX storage room</p>
<p>The dewar should be ready for internal transfer by the <?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?></p>
</div>

<table class="details" style="background: #f4f4f4; margin: 1%">
<tbody>
<?php if ($data['FACILITYCODE']): ?>
Expand Down Expand Up @@ -40,11 +33,10 @@ <h2>EHCs</h2>
<td><?php echo $data['NEXTVISIT'] ?></td>
</tr>
<tr>
<td style="padding: 1.5%; font-weight: bold">New Location</td>
<td><?php echo $data['NEXTLOCATION'] ?></td>
<td style="padding: 1.5%; font-weight: bold">New Local Contact</td>
<td><?php echo $data['NEXTLOCALCONTACT'] ?></td>
</tr>


<tr>
<td style="padding: 1.5%; font-weight: bold">Full Name</td>
<td><?php echo $data['GIVENNAME'] ?> <?php echo $data['FAMILYNAME'] ?></td>
Expand All @@ -61,12 +53,7 @@ <h2>EHCs</h2>
<td style="padding: 1.5%; font-weight: bold">Lab / Company Name</td>
<td><?php echo $data['LABNAME'] ?></td>
</tr>

<tr>
<td style="padding: 1.5%; font-weight: bold">Pickup Date</td>
<td><?php echo $data['DELIVERYAGENT_SHIPPINGDATE'] ?></td>
</tr>


<tr>
<td style="padding: 1.5%; font-weight: bold">Comments</td>
<td><?php echo nl2br($data['COMMENTS']) ?></td>
Expand Down
32 changes: 31 additions & 1 deletion api/src/Database/DatabaseQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ class DatabaseQueryBuilder
private $query_bound_values = [];
/** @var ?string where clause column name */
private $where_columnName = Null;
/** @var ?mixed where vlause value */
/** @var ?mixed where clause value */
private $where_value = Null;
/** @var array join clauses*/
private $join_clauses = [];

/**
* @var DatabaseParent database parent to use
*/
Expand Down Expand Up @@ -104,6 +107,33 @@ public function insert($expectedTable)
return $this->db->id();
}


/**
* Add while join clauses with no processing except to remove duplicates
* ONLY USED WITH getJoins at the moment
*
* @param string $join_clause The join clause to add, e.g. JOIN table t ON t.id = s.id
* @return DatabaseQueryBuilder the builder
*/
public function joinClause($join_clause)
{
if (!in_array($join_clause, $this->join_clauses))
array_push($this->join_clauses, $join_clause);
return $this;
}

/**
* Pull back the join clauses ready to be added to a SQL statement
*
* This is a half-way house into adding join caluses to this builder
*
* @return string The join caluses as one long string
*/
public function getJoins()
{
return implode(" ", $this->join_clauses);
}

private function bindArrayAsList($values): string
{
$bound_list_sql = "";
Expand Down
6 changes: 3 additions & 3 deletions api/src/Model/Services/AssignData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getContainer($visitId, $containerId)
INNER JOIN shipping s ON s.shippingid = d.shippingid
INNER JOIN blsession bl ON bl.proposalid = s.proposalid
INNER JOIN proposal p ON s.proposalid = p.proposalid
WHERE CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), bl.visit_number) LIKE :1
WHERE CONCAT(p.proposalcode, p.proposalnumber, '-', bl.visit_number) LIKE :1
AND c.containerid=:2", array($visitId, $containerId));
}

Expand Down Expand Up @@ -65,7 +65,7 @@ function getDewar($dewarId, $proposalId, $visitId)
$arg = $proposalId;
if ($visitId)
{
$where = "CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), bl.visit_number) LIKE :1";
$where = "CONCAT(p.proposalcode, p.proposalnumber, '-', bl.visit_number) LIKE :1";
$arg = $visitId;
}

Expand Down Expand Up @@ -113,4 +113,4 @@ function getContainerBarcodesForProposal($proposalId)
INNER JOIN containerregistry_has_proposal crhp ON crhp.containerregistryid = cr.containerregistryid
WHERE crhp.proposalid = :1", array($proposalId));
}
}
}
8 changes: 4 additions & 4 deletions api/src/Model/Services/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ function getUsers($getCount, $isStaffMember, $stringMatch, $page, $sortBy = null
INNER JOIN proposal pr ON pr.proposalid = s.proposalid
LEFT OUTER JOIN session_has_person shp2 ON p.personid = shp2.personid
LEFT OUTER JOIN blsession ses ON ses.sessionid = shp2.sessionid AND ses.startdate < s.startdate';
$where .= " AND shp.remote IS NOT NULL AND CONCAT(CONCAT(CONCAT(pr.proposalcode,pr.proposalnumber), '-'), s.visit_number) LIKE :" . (sizeof($args) + 1);
$where .= " AND shp.remote IS NOT NULL AND CONCAT(pr.proposalcode, pr.proposalnumber, '-', s.visit_number) LIKE :" . (sizeof($args) + 1);
$group = 'GROUP BY p.personid, p.givenname, p.familyname, p.login';
array_push($args, $visitName);
}
else if ($pjid)
{
$join = 'INNER JOIN project_has_person php ON p.personid = php.personid';
$where .= ' AND php.projectid=:' . (sizeof($args) + 1);
$extc = "CONCAT(CONCAT(p.personid, '-'), php.projectid) as ppid,";
$extc = "CONCAT(p.personid, '-', php.projectid) as ppid,";
array_push($args, $pjid);
}

Expand Down Expand Up @@ -192,7 +192,7 @@ function getUsers($getCount, $isStaffMember, $stringMatch, $page, $sortBy = null
}
}

$rows = $this->db->paginate("SELECT $extc p.personid, p.givenname, p.familyname, CONCAT(CONCAT(p.givenname, ' '), p.familyname) as fullname, p.login, p.emailaddress, p.phonenumber, l.name as labname, l.address, l.city, '' as postcode, l.country
$rows = $this->db->paginate("SELECT $extc p.personid, p.givenname, p.familyname, CONCAT(p.givenname, ' ', p.familyname) as fullname, p.login, p.emailaddress, p.phonenumber, l.name as labname, l.address, l.city, '' as postcode, l.country
FROM person p
LEFT OUTER JOIN proposalhasperson prhp ON prhp.personid = p.personid
LEFT OUTER JOIN labcontact lc ON lc.personid = p.personid
Expand Down Expand Up @@ -253,7 +253,7 @@ function getUsersForProposal($where, $getCount, $page, $sortBy, $proposalid, $cu
}
}

$extc = "p.personid, p.givenname, p.familyname, CONCAT(CONCAT(p.givenname, ' '), p.familyname) as fullname, p.login, p.emailaddress, p.phonenumber, l.name as labname, l.address, l.city, '' as postcode, l.country";
$extc = "p.personid, p.givenname, p.familyname, CONCAT(p.givenname, ' ', p.familyname) as fullname, p.login, p.emailaddress, p.phonenumber, l.name as labname, l.address, l.city, '' as postcode, l.country";
$rows = $this->db->paginate("(SELECT $extc
FROM person p
LEFT OUTER JOIN ProposalHasPerson prhp ON prhp.personid = p.personid
Expand Down
16 changes: 8 additions & 8 deletions api/src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function auth($require_staff)
}
else
{
$rows = $this->db->pq("SELECT CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis
$rows = $this->db->pq("SELECT CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis
FROM proposal p
INNER JOIN blsession s ON p.proposalid = s.proposalid
INNER JOIN session_has_person shp ON shp.sessionid = s.sessionid
Expand Down Expand Up @@ -315,15 +315,15 @@ function auth($require_staff)

if ($table == 'datacollectiongroup')
{
$vis = $this->db->pq("SELECT p.proposalid, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis
$vis = $this->db->pq("SELECT p.proposalid, CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis
FROM blsession s
INNER JOIN proposal p ON (p.proposalid = s.proposalid)
INNER JOIN datacollectiongroup dcg ON s.sessionid = dcg.sessionid
INNER JOIN datacollection dc ON dcg.datacollectiongroupid = dc.datacollectiongroupid WHERE dc.datacollectionid = :1", array($this->arg('id')));
}
else
{
$vis = $this->db->pq("SELECT p.proposalid, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis
$vis = $this->db->pq("SELECT p.proposalid, CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis
FROM blsession s
INNER JOIN proposal p ON (p.proposalid = s.proposalid)
INNER JOIN $table dc ON s.sessionid = dc.sessionid WHERE dc.$col = :1", array($this->arg('id')));
Expand All @@ -339,7 +339,7 @@ function auth($require_staff)
{
$vis = $this->arg('visit');

$visp = $this->db->pq("SELECT p.proposalid FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) LIKE :1", array($this->arg('visit')));
$visp = $this->db->pq("SELECT p.proposalid FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) LIKE :1", array($this->arg('visit')));

if (sizeof($visp))
$this->proposalid = $visp[0]['PROPOSALID'];
Expand All @@ -348,7 +348,7 @@ function auth($require_staff)
}
else if ($this->has_arg('prop'))
{
$viss = $this->db->pq("SELECT p.proposalid, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE CONCAT(p.proposalcode, p.proposalnumber) LIKE :1", array($this->arg('prop')));
$viss = $this->db->pq("SELECT p.proposalid, CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE CONCAT(p.proposalcode, p.proposalnumber) LIKE :1", array($this->arg('prop')));

$vis = array();
foreach ($viss as $v)
Expand Down Expand Up @@ -780,8 +780,8 @@ function blsr_visits()
if (!$b)
return array();

$visits = $this->db->pq("SELECT CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as visit, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as st, TO_CHAR(s.enddate, 'DD-MM-YYYY HH24:MI') as en,s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE TIMESTAMPDIFF('DAY', s.startdate, CURRENT_TIMESTAMP) < 1 AND TIMESTAMPDIFF('DAY', CURRENT_TIMESTAMP, s.enddate) < 2 AND s.beamlinename LIKE :1 ORDER BY s.startdate", array($b));
$v = $this->db->paginate("SELECT CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as visit, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as st, TO_CHAR(s.enddate, 'DD-MM-YYYY HH24:MI') as en,s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE p.proposalcode LIKE 'cm' AND s.beamlinename LIKE :1 AND s.enddate <= CURRENT_TIMESTAMP ORDER BY s.startdate DESC", array($b, 0, 1));
$visits = $this->db->pq("SELECT CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as visit, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as st, TO_CHAR(s.enddate, 'DD-MM-YYYY HH24:MI') as en,s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE TIMESTAMPDIFF('DAY', s.startdate, CURRENT_TIMESTAMP) < 1 AND TIMESTAMPDIFF('DAY', CURRENT_TIMESTAMP, s.enddate) < 2 AND s.beamlinename LIKE :1 ORDER BY s.startdate", array($b));
$v = $this->db->paginate("SELECT CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as visit, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as st, TO_CHAR(s.enddate, 'DD-MM-YYYY HH24:MI') as en,s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE p.proposalcode LIKE 'cm' AND s.beamlinename LIKE :1 AND s.enddate <= CURRENT_TIMESTAMP ORDER BY s.startdate DESC", array($b, 0, 1));
$visits = array_merge($visits, $v);
return $visits;
}
Expand Down Expand Up @@ -1137,4 +1137,4 @@ protected function haltIfLackingPermission($permission)
{
$this->user->can($permission, $this->app);
}
}
}
4 changes: 2 additions & 2 deletions api/src/Page/Cal.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ function _export_ics() {
array_push($args, $hash['CKEY']);
}

$visits = $this->db->pq("SELECT s.beamlineoperator as lc, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis, CONCAT(p.proposalcode, p.proposalnumber) as prop, s.beamlinename as bl, TO_CHAR(s.startdate, 'DD-MM-YYYY') as d, TO_CHAR(s.enddate, 'DD-MM-YYYY') as e, TO_CHAR(s.startdate, 'HH24:MI') as st, TO_CHAR(s.enddate, 'HH24:MI') as en, s.sessionid
$visits = $this->db->pq("SELECT s.beamlineoperator as lc, CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis, CONCAT(p.proposalcode, p.proposalnumber) as prop, s.beamlinename as bl, TO_CHAR(s.startdate, 'DD-MM-YYYY') as d, TO_CHAR(s.enddate, 'DD-MM-YYYY') as e, TO_CHAR(s.startdate, 'HH24:MI') as st, TO_CHAR(s.enddate, 'HH24:MI') as en, s.sessionid
FROM blsession s
INNER JOIN proposal p ON (p.proposalid = s.proposalid)
WHERE s.startdate > TO_DATE(:1,'YYYY') $where ORDER BY s.startdate, s.beamlinename", $args);


$user_tmp = $this->db->pq("SELECT s.sessionid, pe.login, CONCAT(CONCAT(pe.givenname, ' '), pe.familyname) as fullname, shp.role
$user_tmp = $this->db->pq("SELECT s.sessionid, pe.login, CONCAT(pe.givenname, ' ', pe.familyname) as fullname, shp.role
FROM person pe
INNER JOIN session_has_person shp ON shp.personid = pe.personid
INNER JOIN blsession s ON s.sessionid = shp.sessionid
Expand Down
Loading

0 comments on commit fa177c3

Please sign in to comment.