Skip to content

Commit

Permalink
[#431] Address some PHP warnings in tasks page.
Browse files Browse the repository at this point in the history
(Merge pull request #438 from Igalia/i431-php-warnings-tasks-page)
  • Loading branch information
jaragunde authored Feb 25, 2019
2 parents 060e65b + d036911 commit aa71d45
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 99 deletions.
18 changes: 12 additions & 6 deletions model/dao/ExtraHourDAO/PostgreSQLExtraHourDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ protected function setValues($row)
*/
public function getById($extraHourId) {
if (!is_numeric($extraHourId))
throw new SQLIncorrectTypeException($extraHourId);
throw new SQLIncorrectTypeException($extraHourId);
$sql = "SELECT * FROM extra_hour WHERE id=".$extraHourId;
$result = $this->execute($sql);
return $result[0];
$result = $this->execute($sql);

if (empty($result))
return NULL;
return $result[0];
}

/** Extra Hours retriever by User id for PostgreSQL.
Expand Down Expand Up @@ -120,10 +123,13 @@ public function getByUserId($userId) {
*/
public function getLastByUserId($userId, DateTime $nowadays) {
if (!is_numeric($userId))
throw new SQLIncorrectTypeException($userId);
throw new SQLIncorrectTypeException($userId);
$sql = "SELECT * FROM extra_hour WHERE usrid=" . $userId . " AND _date <=" . DBPostgres::formatDate($nowadays) . " ORDER BY _date DESC LIMIT 1";
$result = $this->execute($sql);
return $result[0];
$result = $this->execute($sql);

if (empty($result))
return NULL;
return $result[0];
}

/** Extra Hours retriever for PostgreSQL.
Expand Down
33 changes: 20 additions & 13 deletions model/dao/TaskDAO/PostgreSQLTaskDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,13 @@ protected function setValues($row)
*/
public function getById($taskId) {
if (!is_numeric($taskId))
throw new SQLIncorrectTypeException($taskId);
throw new SQLIncorrectTypeException($taskId);
$sql = "SELECT * FROM task WHERE id=".$taskId;
$result = $this->execute($sql);
return $result[0];
$result = $this->execute($sql);

if (empty($result))
return NULL;
return $result[0];
}

/** Tasks retriever by User id for PostgreSQL.
Expand Down Expand Up @@ -383,7 +386,7 @@ public function getFiltered($filterStartDate = NULL, $filterEndDate = NULL,
/** Tasks report generator for PostgreSQL.
*
* This function generates a report of the hours users have worked in Tasks related to an element <var>$reportObject</var>,
* which may be a {@link UserVO}, {@link TaskVO} or {@link CustomerVO}. Two optional dates can also be passed, <var>$initDate</var>
* which may be a {@link UserVO}, {@link ProjectVO} or {@link CustomerVO}. Two optional dates can also be passed, <var>$initDate</var>
* and <var>$endDate</var>, to limit the dates of the tasks retrieved (if they are not passed, it returns the result for tasks of any date),
* and two group fields, <var>$groupField1</var> and <var>$groupField2</var>, that only are used for making groups with the
* results if they are passed.
Expand Down Expand Up @@ -451,12 +454,14 @@ public function getTaskReport($reportObject, DateTime $initDate = NULL, DateTime

if ($res == NULL) throw new SQLQueryErrorException(pg_last_error());

if(pg_num_rows($res) > 0) {
for($i = 0; $i < pg_num_rows($res); $i++)
{
$rows[$i] = @pg_fetch_array($res);
}
$rows = array();
if(pg_num_rows($res) > 0) {
for($i = 0; $i < pg_num_rows($res); $i++) {
$rows[$i] = @pg_fetch_array($res);
}
}
else
return NULL;

return $rows;

Expand Down Expand Up @@ -637,11 +642,13 @@ public function getVacations(UserVO $userVO, DateTime $initDate = NULL, DateTime
$res = pg_query($this->connect, $sql);
if ($res == NULL) throw new SQLQueryErrorException(pg_last_error());

for($i = 0; $i < pg_num_rows($res); $i++)
{
$result = array();
for($i = 0; $i < pg_num_rows($res); $i++) {
$result[$i] = @pg_fetch_array($res);
}
}

if (empty($result))
return NULL;
return $result[0];

}
Expand All @@ -666,7 +673,7 @@ public function partialUpdate(DirtyTaskVO $taskVO) {
}

// If the query returned a row then update
if(sizeof($currTaskVO) > 0) {
if(isset($currTaskVO)) {

$sql = "UPDATE task SET ";

Expand Down
3 changes: 3 additions & 0 deletions model/dao/UserGoalDAO/PostgreSQLUserGoalDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ public function getUserGoalsForCurrentDate($userId, DateTime $date) {
AND end_date >= " . DBPostgres::formatDate($date) . ";";

$result = $this->execute($sql);

if (empty($result))
return NULL;
return $result[0];
}
}
2 changes: 1 addition & 1 deletion web/services/createTasksService.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
$string = "<return service='createTasks'><success>false</success><error id='1'>There was some error while creating the tasks</error></return>";


if (!$string)
if (!isset($string))
{

$string = "<return service='createTasks'><success>true</success><ok>Operation Success!</ok><tasks>";
Expand Down
2 changes: 1 addition & 1 deletion web/services/getOpenTaskStoriesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
include_once(PHPREPORT_ROOT . '/web/services/WebServicesFunctions.php');
include_once(PHPREPORT_ROOT . '/model/facade/CoordinationFacade.php');

$sid = $_GET['sid'];
$sid = $_GET['sid'] ?? NULL;

$projectId = $_GET['pid'];

Expand Down
22 changes: 6 additions & 16 deletions web/services/getPersonalSummaryByDateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,15 @@ function formatHours ($time, $journey, $limit) {
return $formatedHours;
}

$date = $_GET['date'];
$dateString = $_GET['date'] ?? NULL;

$dateFormat = $_GET['dateFormat'];
$dateFormat = $_GET['dateFormat'] ?? "Y-m-d";

$sid = $_GET['sid'];
$sid = $_GET['sid'] ?? NULL;

if ($dateFormat=="")
$dateFormat = "Y-m-d";

if ($date == "")
$date = new DateTime();
else
{
$dateParse = date_parse_from_format($dateFormat, $date);

$date = "{$dateParse['year']}-{$dateParse['month']}-{$dateParse['day']}";

$date = date_create($date);
}
$date = new DateTime();
if ($dateString)
$date = DateTime::createFromFormat($dateFormat, $dateString);

do {
/* We check authentication and authorization */
Expand Down
51 changes: 12 additions & 39 deletions web/services/getProjectsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,56 +31,29 @@
include_once(PHPREPORT_ROOT . '/model/facade/ProjectsFacade.php');
include_once(PHPREPORT_ROOT . '/model/vo/ProjectVO.php');

$sid = $_GET['sid'];
$login = $_GET['login'];
$order = 'id';
$sid = $_GET['sid'] ?? NULL;
$login = $_GET['login'] ?? NULL;
$order = $_GET['order'] ?? 'id';


// In case some filtering args are set, retrieve them
$description = NULL;
$description = $_GET['description'] ?? NULL;
$filterStartDate = NULL;
$filterEndDate = NULL;
$activation = NULL;
$areaId = NULL;
$type = NULL;
$customerId = NULL;
$cname = NULL;
$active = false;
$returnExtendedInfo = False;

if (isset($_GET['description'])) {
$description = $_GET['description'];
}
$activation = $_GET['activation'] ?? NULL;
$areaId = $_GET['areaId'] ?? NULL;
$type = $_GET['type'] ?? NULL;
$customerId = $_GET['customerId'] ?? NULL;
$cname = $_GET['cname'] ?? NULL;
$active = $_GET['active'] ?? false;
$returnExtendedInfo = $_GET['returnExtendedInfo'] ?? false;

if (isset($_GET['filterStartDate'])) {
$filterStartDate = DateTime::createFromFormat("Y-m-d", $_GET['filterStartDate']);
}
if (isset($_GET['filterEndDate'])) {
$filterEndDate = DateTime::createFromFormat("Y-m-d", $_GET['filterEndDate']);
}
if (isset($_GET['activation'])) {
$activation = $_GET['activation'];
}
if (isset($_GET['areaId'])) {
$areaId = $_GET['areaId'];
}
if (isset($_GET['type'])) {
$type = $_GET['type'];
}
if (isset($_GET['order'])) {
$order = $_GET['order'];
}
if (isset($_GET['customerId'])) {
$customerId = $_GET['customerId'];
}
if (isset($_GET['cname'])) {
$cname = $_GET['cname'];
}
if (isset($_GET['returnExtendedInfo'])) {
$returnExtendedInfo = $_GET['returnExtendedInfo'];
}
if (isset($_GET['active'])) {
$active = $_GET['active'];
}

do {
/* We check authentication and authorization */
Expand Down
29 changes: 7 additions & 22 deletions web/services/getUserTasksService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,17 @@
include_once(PHPREPORT_ROOT . '/model/facade/TasksFacade.php');
include_once(PHPREPORT_ROOT . '/model/vo/UserVO.php');

$userLogin = $_GET['uid'];
$userLogin = $_GET['uid'] ?? $_GET['login'] ?? NULL;

$date = $_GET['date'];
$dateString = $_GET['date'] ?? NULL;

$dateFormat = $_GET['dateFormat'];
$dateFormat = $_GET['dateFormat'] ?? "Y-m-d";

$login = $_GET['login'];
$sid = $_GET['sid'] ?? NULL;

if ($userLogin=="")
$userLogin= $login;

$sid = $_GET['sid'];

if ($dateFormat=="")
$dateFormat = "Y-m-d";

if ($date == "")
$date = new DateTime();
else
{
$dateParse = date_parse_from_format($dateFormat, $date);

$date = "{$dateParse['year']}-{$dateParse['month']}-{$dateParse['day']}";

$date = date_create($date);
}
$date = new DateTime();
if ($dateString)
$date = DateTime::createFromFormat($dateFormat, $dateString);

do {
/* We check authentication and authorization */
Expand Down
2 changes: 1 addition & 1 deletion web/services/getUserTemplatesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
include_once(PHPREPORT_ROOT . '/model/facade/TemplatesFacade.php');
include_once(PHPREPORT_ROOT . '/model/vo/TemplateVO.php');

$sid = $_GET['sid'];
$sid = $_GET['sid'] ?? NULL;

do {
/* We check authentication and authorization */
Expand Down

0 comments on commit aa71d45

Please sign in to comment.