/**
  * Method to get experiments of a particular time range
  * @param $inputs
  * @return array
  */
 public static function get_experiments_of_time_range($inputs)
 {
     $experimentStatistics = AdminUtilities::get_experiment_execution_statistics(strtotime($inputs["from-date"]) * 1000, strtotime($inputs["to-date"]) * 1000);
     $experiments = array();
     if ($inputs["status-type"] == "ALL") {
         $experiments = $experimentStatistics->allExperiments;
     } else {
         if ($inputs["status-type"] == "COMPLETED") {
             $experiments = $experimentStatistics->completedExperiments;
         } elseif ($inputs["status-type"] == "FAILED") {
             $experiments = $experimentStatistics->failedExperiments;
         } else {
             if ($inputs["status-type"] == "CANCELED") {
                 $experiments = $experimentStatistics->cancelledExperiments;
             }
         }
     }
     $expContainer = array();
     $expNum = 0;
     foreach ($experiments as $experiment) {
         $expValue = ExperimentUtilities::get_experiment_values($experiment, ProjectUtilities::get_project($experiment->projectID), true);
         $expContainer[$expNum]['experiment'] = $experiment;
         $expValue["editable"] = false;
         $expContainer[$expNum]['expValue'] = $expValue;
         $expNum++;
     }
     return $expContainer;
 }
echo '<h3>' . $project->name . ' <a href="edit?projId=' . $project->projectID . '" title="Edit"><span class="glyphicon glyphicon-pencil"></span></a></h3>';
echo "<p>{$project->description}</p>";
echo '</div>';
$experiments = ProjectUtilities::get_experiments_in_project($project->projectID);
echo '<div class="table-responsive">';
echo '<table class="table">';
echo '<tr>';
echo '<th>Name</th>';
echo '<th>Application</th>';
echo '<th>Compute Resource</th>';
echo '<th>Last Modified Time</th>';
echo '<th>Experiment Status</th>';
echo '<th>Job Status</th>';
echo '</tr>';
foreach ($experiments as $experiment) {
    $expValues = ExperimentUtilities::get_experiment_values($experiment, ProjectUtilities::get_project($experiment->projectId), true);
    $expValues["jobState"] = ExperimentUtilities::get_job_status($experiment);
    $applicationInterface = AppUtilities::get_application_interface($experiment->executionId);
    echo '<tr>';
    echo '<td>' . $experiment->experimentName . '</td>';
    echo "<td>{$applicationInterface->applicationName}</td>";
    echo '<td>';
    try {
        $cr = CRUtilities::get_compute_resource($experiment->userConfigurationData->computationalResourceScheduling->resourceHostId);
        if (!empty($cr)) {
            echo $cr->hostName;
        }
    } catch (Exception $ex) {
        //Error while retrieving the CR
    }
    echo '</td>';
 public function cloneExperiment()
 {
     if (isset($_GET['expId'])) {
         $cloneId = ExperimentUtilities::clone_experiment($_GET['expId']);
         $experiment = ExperimentUtilities::get_experiment($cloneId);
         $project = ProjectUtilities::get_project($experiment->projectId);
         $expVal = ExperimentUtilities::get_experiment_values($experiment, $project);
         $expVal["jobState"] = ExperimentUtilities::get_job_status($experiment);
         return Redirect::to('experiment/edit?expId=' . $cloneId);
     }
 }
    /**
     * Get results of the user's all experiments with pagination.
     * Results are ordered creation time DESC
     * @return array|null
     */
    public static function get_all_user_experiments_with_pagination($limit, $offset)
    {
        $experiments = array();

        try {
            $experiments = Airavata::getAllUserExperimentsWithPagination(
                Session::get('gateway_id'), Session::get('username'), $limit, $offset
            );
        } catch (InvalidRequestException $ire) {
            CommonUtilities::print_error_message('InvalidRequestException!<br><br>' . $ire->getMessage());
        } catch (AiravataClientException $ace) {
            CommonUtilities::print_error_message('AiravataClientException!<br><br>' . $ace->getMessage());
        } catch (AiravataSystemException $ase) {
            if ($ase->airavataErrorType == 2) // 2 = INTERNAL_ERROR
            {
                CommonUtilities::print_info_message('<p>You have not created any experiments yet, so no results will be returned!</p>
                                <p>Click <a href="create_experiment.php">here</a> to create an experiment, or
                                <a href="create_project.php">here</a> to create a new project.</p>');
            } else {
                CommonUtilities::print_error_message('There was a problem with Airavata. Please try again later or report a bug using the link in the Help menu.');
                //print_error_message('AiravataSystemException!<br><br>' . $ase->airavataErrorType . ': ' . $ase->getMessage());
            }
        } catch (TTransportException $tte) {
            CommonUtilities::print_error_message('TTransportException!<br><br>' . $tte->getMessage());
        }

        //get values of all experiments
        $expContainer = array();
        $expNum = 0;
        foreach ($experiments as $experiment) {
            $expValue = ExperimentUtilities::get_experiment_values($experiment, ProjectUtilities::get_project($experiment->projectId), true);
            $expContainer[$expNum]['experiment'] = $experiment;
            if ($expValue["experimentStatusString"] == "FAILED")
                $expValue["editable"] = false;
            $expContainer[$expNum]['expValue'] = $expValue;
            $expNum++;
        }

        return $expContainer;
    }
echo '<h3>' . $project->name . ' <a href="edit?projId=' . $project->projectID . '" title="Edit"><span class="glyphicon glyphicon-pencil"></span></a></h3>';
echo "<p>{$project->description}</p>";
echo '</div>';
$experiments = ProjectUtilities::get_experiments_in_project($project->projectID);
echo '<div class="table-responsive">';
echo '<table class="table">';
echo '<tr>';
echo '<th>Name</th>';
echo '<th>Application</th>';
echo '<th>Compute Resource</th>';
echo '<th>Last Modified Time</th>';
echo '<th>Experiment Status</th>';
echo '<th>Job Status</th>';
echo '</tr>';
foreach ($experiments as $experiment) {
    $expValues = ExperimentUtilities::get_experiment_values($experiment, $project, true);
    $expValues["jobState"] = ExperimentUtilities::get_job_status($experiment);
    $applicationInterface = AppUtilities::get_application_interface($experiment->executionId);
    switch ($expValues["experimentStatusString"]) {
        case 'CANCELING':
        case 'CANCELED':
        case 'UNKNOWN':
            $textClass = 'text-warning';
            break;
        case 'FAILED':
            $textClass = 'text-danger';
            break;
        case 'COMPLETED':
            $textClass = 'text-success';
            break;
        default:
 public function editView()
 {
     $queueDefaults = array("queueName" => Config::get('pga_config.airavata')["queue-name"], "nodeCount" => Config::get('pga_config.airavata')["node-count"], "cpuCount" => Config::get('pga_config.airavata')["total-cpu-count"], "wallTimeLimit" => Config::get('pga_config.airavata')["wall-time-limit"]);
     $experiment = ExperimentUtilities::get_experiment($_GET['expId']);
     $project = ProjectUtilities::get_project($experiment->projectId);
     $expVal = ExperimentUtilities::get_experiment_values($experiment, $project);
     $expVal["jobState"] = ExperimentUtilities::get_job_status($experiment);
     $computeResources = CRUtilities::create_compute_resources_select($experiment->applicationId, $expVal['scheduling']->resourceHostId);
     $experimentInputs = array("disabled" => ' ', "experimentName" => $experiment->name, "experimentDescription" => $experiment->description, "application" => $experiment->applicationId, "allowedFileSize" => Config::get('pga_config.airavata')["server-allowed-file-size"], 'experiment' => $experiment, "queueDefaults" => $queueDefaults, 'project' => $project, 'expVal' => $expVal, 'cloning' => true, 'advancedOptions' => Config::get('pga_config.airavata')["advanced-experiment-options"], 'computeResources' => $computeResources, "resourceHostId" => $expVal['scheduling']->resourceHostId, 'project' => $project, 'expVal' => $expVal, 'cloning' => true, 'advancedOptions' => Config::get('pga_config.airavata')["advanced-experiment-options"]);
     return View::make("experiment/edit", array("expInputs" => $experimentInputs));
 }