Example #1
0
 /**
  * Função visualizarJobs / showJobs
  *
  * Visualiza todos os jobs do banco de dados, se for passado um parâmetro jobID, retornará as informações desse job
  *
  * @author Henrique Ramos <*****@*****.**>
  * @version 0.1.0
  * @since 0.1.0
  *
  * @param array[] $params Array com parâmetros passados através do F3.
  *
  * @throws Exception Senão encontrar nenhum resultado no banco de dados
  *
  * @return array[]
  */
 public function showJobs($params = NULL)
 {
     global $connectDB, $logger;
     try {
         if (empty($params)) {
             throw new \Exception(__("Fill the \$params parameter."));
         }
         if (empty($params['jobID']) or !is_numeric($params['jobID'])) {
             $jobsSQL = $connectDB->query("SELECT `j`.`job_id`, `j`.`job_name`, `j`.`job_date`, `j`.`job_cron`, `j`.`job_path`, `j`.`job_type`, `j`.`job_author`, `j`.`job_status`, `j`.`job_comment` FROM `jobs` AS `j`", \PDO::FETCH_ASSOC);
             if ($jobsSQL->rowCount() == 0) {
                 if ($jobsSQL->errorCode() != 00) {
                     $logger->addError(sprintf(__("MySQL Error when we tried to retrieve jobs\r\n#############################\r\nError#############################\r\n%s\r\n#############################\r\n\r\n"), var_export($jobsSQL->errorInfo(), true)));
                 }
                 throw new \Exception(__("Not found any job matching this parameters."));
             }
             return array('jobs' => $jobsSQL->fetchAll());
         }
         $jobID = $params['jobID'];
         $jobsSQL = $connectDB->prepare("SELECT `j`.`job_id`, `j`.`job_name`, `j`.`job_date`, `j`.`job_cron`, `j`.`job_path`, `j`.`job_type`, `j`.`job_author`, `j`.`job_status`, `j`.`job_comment` FROM `jobs` AS `j` WHERE `j`.`job_id`=:jobID");
         $jobsSQL->bindValue(":jobID", $jobID, \PDO::PARAM_INT);
         $jobsSQL->execute();
         if ($jobsSQL->errorCode() != 00) {
             $logger->addError(sprintf(__("MySQL Error when we tried to retrieve job %s\r\n#############################\r\nError#############################\r\n%s\r\n#############################\r\n\r\n"), $jobID, var_export($jobsSQL->errorInfo(), true)));
             throw new \Exception(__("Not found any job matching this parameters."));
         }
         $finalArray = array('job' => $jobsSQL->fetch(\PDO::FETCH_ASSOC));
         $alert = new \Ramos\Zeus\Alert();
         $finalArray = array_merge($finalArray['job'], array('alerts' => $alert->viewAlertsByJob($jobID)));
         return $finalArray;
     } catch (Exception $e) {
         throw $e;
     }
 }