Skip to content

Commit

Permalink
Merge pull request #3 from TAMULib/sprint10_02511
Browse files Browse the repository at this point in the history
Sprint10 02511
  • Loading branch information
jsavell committed Aug 18, 2015
2 parents 7cc93c5 + a7a30db commit aa0716d
Show file tree
Hide file tree
Showing 11 changed files with 532 additions and 12 deletions.
67 changes: 67 additions & 0 deletions newresources/admin/classes/domain/Downtime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

class Downtime extends DatabaseObject {

protected function defineRelationships() {}

protected function overridePrimaryKeyName() {}

public function load() {

//This is a custom load method that joins the downtime type name into the attributes

//if exists in the database
if (isset($this->primaryKey)) {
$query = "SELECT d.*, dt.name, i.subjectText
FROM Downtime d
LEFT JOIN DowntimeType dt ON dt.downtimeTypeID=d.downtimeTypeID
LEFT JOIN Issue i ON i.issueID=d.issueID
WHERE d.downtimeID={$this->primaryKey}";

$result = $this->db->processQuery($query, 'assoc');

foreach (array_keys($result) as $attributeName) {
$this->addAttribute($attributeName);
$this->attributes[$attributeName] = $result[$attributeName];
}

}else{
// Figure out attributes from existing database
$query = "SELECT COLUMN_NAME FROM information_schema.`COLUMNS` WHERE table_schema = '";
$query .= $this->db->config->database->name . "' AND table_name = '$this->tableName'";// MySQL-specific
foreach ($this->db->processQuery($query) as $result) {
$attributeName = $result[0];
$this->addAttribute($attributeName);
}
}
}

public function save() {

//We have added the name attribute after the fact, and here, we are cleaning it up
unset($this->attributes["name"]);
unset($this->attributesNames["name"]);

unset($this->attributes["subjectText"]);
unset($this->attributesNames["subjectText"]);

parent::save();
}

public function getDowntimeTypesArray() {
$query = "SELECT dt.*
FROM DowntimeType dt";

$result = $this->db->processQuery($query, "assoc");
$names = array();

foreach ($result as $name) {
array_push($names, $name);
}

return $names;
}

}

?>
53 changes: 53 additions & 0 deletions newresources/admin/classes/domain/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,35 @@ public function getIssues($archivedOnly=false) {
return $objects;
}

public function getDowntime($archivedOnly=false) {
$query = "SELECT d.*
FROM Downtime d
WHERE d.entityID={$this->primaryKey}
AND d.entityTypeID=1";

if ($archivedOnly) {
$query .= " AND d.endDate < CURDATE()";
} else {
$query .= " AND d.endDate >= CURDATE()";
}
$query .= " ORDER BY d.dateCreated DESC";

$result = $this->db->processQuery($query, 'assoc');

$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['downtimeID'])) {
$object = new Downtime(new NamedArguments(array('primaryKey' => $result['downtimeID'])));
array_push($objects, $object);
} else {
foreach ($result as $row) {
$object = new Downtime(new NamedArguments(array('primaryKey' => $row['downtimeID'])));
array_push($objects, $object);
}
}
return $objects;
}

public function getExportableIssues($archivedOnly=false) {
$orgDB = $this->db->config->settings->organizationsDatabaseName;
$query = "SELECT i.*,(SELECT GROUP_CONCAT(CONCAT(sc.name,' - ',sc.emailAddress) SEPARATOR ', ')
Expand Down Expand Up @@ -108,6 +137,30 @@ public function getExportableIssues($archivedOnly=false) {
return $result;
}
}

public function getExportableDowntimes($archivedOnly=false){

$query = "SELECT d.*
FROM Downtime d
WHERE d.entityID={$this->primaryKey} AND d.entityTypeID=1";
if ($archivedOnly) {
$query .= " AND d.endDate < CURDATE()";
} else {
$query .= " AND d.endDate >= CURDATE()";
}
$query .= " ORDER BY d.dateCreated DESC";

$result = $this->db->processQuery($query, 'assoc');

$objects = array();

//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['downtimeID'])){
return array($result);
}else{
return $result;
}
}
}

?>
52 changes: 52 additions & 0 deletions newresources/admin/classes/domain/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,34 @@ public function getIssues($archivedOnly=false){
return $objects;
}

public function getDowntime($archivedOnly=false){
$query = "SELECT d.*
FROM Downtime d
WHERE d.entityID={$this->resourceID} AND d.entityTypeID=2";
if ($archivedOnly) {
$query .= " AND d.endDate < CURDATE()";
} else {
$query .= " AND d.endDate >= CURDATE()";
}
$query .= " ORDER BY d.dateCreated DESC";

$result = $this->db->processQuery($query, 'assoc');

$objects = array();

//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['downtimeID'])){
$object = new Downtime(new NamedArguments(array('primaryKey' => $result['downtimeID'])));
array_push($objects, $object);
}else{
foreach ($result as $row) {
$object = new Downtime(new NamedArguments(array('primaryKey' => $row['downtimeID'])));
array_push($objects, $object);
}
}
return $objects;
}

public function getExportableIssues($archivedOnly=false){
$orgDB = $this->db->config->settings->organizationsDatabaseName;
$query = "SELECT i.*,(SELECT GROUP_CONCAT(CONCAT(sc.name,' - ',sc.emailAddress) SEPARATOR ', ')
Expand Down Expand Up @@ -835,6 +863,30 @@ public function getExportableIssues($archivedOnly=false){
}
}

public function getExportableDowntimes($archivedOnly=false){

$query = "SELECT d.*
FROM Downtime d
WHERE d.entityID={$this->resourceID} AND d.entityTypeID=2";
if ($archivedOnly) {
$query .= " AND d.endDate < CURDATE()";
} else {
$query .= " AND d.endDate >= CURDATE()";
}
$query .= " ORDER BY d.dateCreated DESC";

$result = $this->db->processQuery($query, 'assoc');

$objects = array();

//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['downtimeID'])){
return array($result);
}else{
return $result;
}
}

//returns array of attachments objects
public function getAttachments(){

Expand Down
102 changes: 102 additions & 0 deletions newresources/ajax_forms/getNewDowntimeForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
$util = new utility();

$resourceID = $_GET["resourceID"];

$resource = new Resource(new NamedArguments(array('primaryKey' => $resourceID)));
$issues = $resource->getIssues();

$organizationArray = $resource->getOrganizationArray();
$organizationData = $organizationArray[0];

if ($organizationData['organizationID']) {

$organization = new Organization(new NamedArguments(array('primaryKey' => $organizationData['organizationID'])));

$orgIssues = $organization->getIssues();

foreach ($orgIssues as $issue) {
array_push($issues, $issue);
}

$downtimeObj = new Downtime();
$downtimeTypeNames = $downtimeObj->getDowntimeTypesArray();

$organizationContactsArray = $resource->organizationContactsArray($organizationData['organizationID']);
$organizationResourcesArray = $resource->getSiblingResourcesArray($organizationData['organizationID']);

$defaultStart = date("Y-m-d\TH:i");
$defaultEnd = date("Y-m-d\TH:i", strtotime("+1 day"));

?>

<form id='newDowntimeForm'>
<input type="hidden" name="sourceOrganizationID" value="<?php echo $organizationData['organizationID'];?>" />
<input type="hidden" name="sourceResourceID" value="<?php echo $resourceID;?>" />
<table class="thickboxTable" style="width:98%;background-image:url('images/title.gif');background-repeat:no-repeat;">
<tr>
<td colspan="2">
<h1> Resource Downtime Report</h1>
</td>
</tr>
<tr>
<td><label>Downtime Start:</label></td>
<td>
<input value="<?php echo $defaultStart; ?>" type="datetime-local" name="startDate" id="startDate" />
<span id='span_error_contactName' class='smallDarkRedText'>
</td>
</tr>
<tr>
<td><label>Downtime Resolution:</label></td>
<td>
<input value="<?php echo $defaultEnd; ?>" type="datetime-local" name="endDate" id="endDate" />
<span id='span_error_contactName' class='smallDarkRedText'>
</td>
</tr>
<tr>
<td><label>Problem Type:</label></td>
<td>
<select class="downtimeType" name="downtimeType">
<?php
foreach ($downtimeTypeNames as $downtimeType) {
echo "<option value=".$downtimeType["downtimeTypeID"].">".$downtimeType["name"]."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td><label>Link to open issue:</label></td>
<td>
<select class="issueID" name="issueID">
<option value="">none</option>
<?php
foreach ($issues as $issue) {
echo "<option value=".$issue->issueID.">".$issue->subjectText."</option>";
}
?>
</select>
</td>
</tr>
</table>

<table class='noBorderTable' style='width:125px;'>
<tr>
<td style='text-align:left'><input type='button' value='submit' name='submitNewDowntime' id='submitNewDowntime'></td>
<td style='text-align:right'><input type='button' value='cancel' onclick="tb_remove();"></td>
</tr>
</table>

</form>

<?php
} else {
echo '
<p>
Opening an issue requires a resource to be associated with an organization.
</p>
<input type="button" value="cancel" onclick="tb_remove();">';
}
?>


82 changes: 82 additions & 0 deletions newresources/ajax_htmldata/getDowntimeList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
$resourceID = $_GET['resourceID'];
$archivedFlag = (!empty($_GET['archived']) && $_GET['archived'] == 1) ? true:false;

$resource = new Resource(new NamedArguments(array('primaryKey' => $resourceID)));
$util = new Utility();


//shared html template for organization and resource downtimes
function generateDowntimeHTML($downtime,$associatedEntities=null) {

$html = "
<div class=\"downtime\">";

$html .= "
<dl>
<dt>Type:</dt>
<dd>{$downtime->name}</dd>
<dt>Downtime Start:</dt>
<dd>{$downtime->startDate}</dd>
<dt>Downtime Resolved:</dt>
<dd>{$downtime->endDate}</dd>";

if($downtime->subjectText) {
$html .= "
<dt>Linked issue:</dt>
<dd>{$downtime->subjectText}</dd>";
}

$html .= "
</dl>
</div>";

return $html;
}

//display any organization level downtimes for the resource
$organizationArray = $resource->getOrganizationArray();

if (count($organizationArray) > 0) {
echo '<h3 class="text-center">Organizational</h3>';

$downtimedOrgs = array();
foreach ($organizationArray as $orgData) {
if (!in_array($orgData['organizationID'],$downtimedOrgs)) {
$organization = new Organization(new NamedArguments(array('primaryKey' => $orgData['organizationID'])));

$orgDowntimes = $organization->getDowntime($archivedFlag);

if(count($orgDowntimes) > 0) {
foreach ($orgDowntimes as $downtime) {
echo generateDowntimeHTML($downtime,array(array("name"=>$orgData['organization'],"id"=>$organization->organizationID,"entityType"=>1)));
}
} else {
echo "<br><p>There are no organization level downtimes.</p><br>";
}

$orgDowntimes = null;
$downtimedOrgs[] = $orgData['organizationID'];
}
}
}

//display any resource level downtimes for the resource (shows any other resources associated with the downtime, too)
$resourceDowntimes = $resource->getDowntime($archivedFlag);
echo '<h3 class="text-center">Resources</h3>';
if(count($resourceDowntimes) > 0) {
foreach ($resourceDowntimes as $downtime) {
$associatedEntities = array();
if ($associatedResources = $downtime->getAssociatedResources()) {
foreach ($associatedResources as $resource) {
$associatedEntities[] = array("name"=>$resource->titleText,"id"=>$resource->resourceID,"entityType"=>2);
}
}
echo generateDowntimeHTML($downtime,$associatedEntities);
}
} else {
echo "<br><p>There are no resource level downtimes.</p><br>";
}
?>
Loading

0 comments on commit aa0716d

Please sign in to comment.