}
public function init($config) {
+ $this->initSessionCache();
$this->appCfg = $this->Application->getModule('configuration')->getApplicationConfig();
}
* API REQUESTS METHODS (get, set, create, delete)
*/
- public function get(array $params) {
- $url = $this->getURL() . implode('/', $params);
- $this->setParamsToUrl($url);
- $ch = $this->getConnection();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->getAPIHeader(), 'Accept: application/json'));
- $result = curl_exec($ch);
- curl_close($ch);
- return $this->preParseOutput($result);
+ public function get(array $params, $use_cache = false) {
+ $cached = null;
+ $ret = null;
+ if ($use_cache === true) {
+ $cached = $this->getSessionCache($params);
+ }
+ if (!is_null($cached)) {
+ $ret = $cached;
+ } else {
+ $url = $this->getURL() . implode('/', $params);
+ $this->setParamsToUrl($url);
+ $ch = $this->getConnection();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->getAPIHeader(), 'Accept: application/json'));
+ $result = curl_exec($ch);
+ curl_close($ch);
+ $ret = $this->preParseOutput($result);
+ if ($use_cache === true && $ret->error === 0) {
+ $this->setSessionCache($params, $ret);
+ }
+ }
+ return $ret;
}
public function set(array $params, array $options) {
return $resource;
}
+
+ public function initSessionCache($force = false) {
+ if (!isset($_SESSION) || !array_key_exists('cache', $_SESSION) || !is_array($_SESSION['cache']) || $force === true) {
+ $_SESSION['cache'] = array();
+ }
+ }
+
+ private function getSessionCache(array $params) {
+ $cached = null;
+ $key = $this->getSessionKey($params);
+ if ($this->isSessionValue($key)) {
+ $cached = $_SESSION['cache'][$key];
+ }
+ return $cached;
+ }
+
+ private function setSessionCache(array $params, $value) {
+ $key = $this->getSessionKey($params);
+ $_SESSION['cache'][$key] = $value;
+ }
+
+ private function getSessionKey(array $params) {
+ $key = implode(';', $params);
+ $key = base64_encode($key);
+ return $key;
+ }
+
+ private function isSessionValue($key) {
+ $is_value = array_key_exists($key, $_SESSION['cache']);
+ return $is_value;
+ }
}
?>
public function onInit($param) {
parent::onInit($param);
+
+ if (!$this->IsPostBack && !$this->IsCallBack) {
+ $this->getModule('api')->initSessionCache(true);
+ }
+
$isConfigExists = $this->getModule('configuration')->isApplicationConfig();
if($isConfigExists === false) {
$this->goToPage('ConfigurationWizard');
$this->JobToVerifyOptions->dataSource = $verifyValues;
$this->JobToVerifyOptions->dataBind();
- $jobTasks = $this->Application->getModule('api')->get(array('jobs', 'tasks'))->output;
+ $jobTasks = $this->Application->getModule('api')->get(array('jobs', 'tasks'), true)->output;
$jobsAllDirs = array();
foreach($jobTasks as $director => $tasks) {
$this->JobToVerifyJobName->dataSource = array_combine($jobsAllDirs, $jobsAllDirs);
$this->JobToVerifyJobName->dataBind();
- $clients = $this->Application->getModule('api')->get(array('clients'))->output;
+ $clients = $this->Application->getModule('api')->get(array('clients'), true)->output;
$clientsList = array();
foreach($clients as $client) {
$clientsList[$client->clientid] = $client->name;
$this->Client->SelectedValue = $jobdata->clientid;
$this->Client->dataBind();
- $filesetsAll = $this->Application->getModule('api')->get(array('filesets'))->output;
+ $filesetsAll = $this->Application->getModule('api')->get(array('filesets'), true)->output;
$filesetsList = array();
foreach($filesetsAll as $director => $filesets) {
$filesetsList = array_merge($filesets, $filesetsList);
}
if($jobdata->filesetid != 0) {
- $selectedFileset = $this->Application->getModule('api')->get(array('filesets', $jobdata->filesetid))->output;
+ $selectedFileset = $this->Application->getModule('api')->get(array('filesets', $jobdata->filesetid), true)->output;
}
$this->FileSet->dataSource = array_combine($filesetsList, $filesetsList);
$this->FileSet->SelectedValue = @$selectedFileset->fileset;
$this->FileSet->dataBind();
- $pools = $this->Application->getModule('api')->get(array('pools'))->output;
+ $pools = $this->Application->getModule('api')->get(array('pools'), true)->output;
$poolList = array();
foreach($pools as $pool) {
$poolList[$pool->poolid] = $pool->name;
$this->Pool->SelectedValue = $jobdata->poolid;
$this->Pool->dataBind();
- $jobshow = $this->Application->getModule('api')->get(array('jobs', 'show', $jobdata->jobid))->output;
+ $jobshow = $this->Application->getModule('api')->get(array('jobs', 'show', $jobdata->jobid), true)->output;
$storageShow = $this->getResourceName('storage', $jobshow);
$storagesList = array();
$selectedStorageId = null;
- $storages = $this->Application->getModule('api')->get(array('storages'))->output;
+ $storages = $this->Application->getModule('api')->get(array('storages'), true)->output;
foreach($storages as $storage) {
if ($storage->name == $storageShow) {
$selectedStorageId = $storage->storageid;
private function getPoolByName($name) {
$pool = null;
- $pools = $this->Application->getModule('api')->get(array('pools'))->output;
+ $pools = $this->Application->getModule('api')->get(array('pools'), true)->output;
for ($i = 0; $i < count($pools); $i++) {
if ($pools[$i]->name == $name) {
$pool = $pools[$i];
private function getStorageByName($name) {
$storage = null;
- $storages = $this->Application->getModule('api')->get(array('storages'))->output;
+ $storages = $this->Application->getModule('api')->get(array('storages'), true)->output;
for ($i = 0; $i < count($storages); $i++) {
if ($storages[$i]->name == $name) {
$storage = $storages[$i];
$this->JobToVerifyOptions->dataSource = $verifyValues;
$this->JobToVerifyOptions->dataBind();
- $jobTasks = $this->Application->getModule('api')->get(array('jobs', 'tasks'))->output;
+ $jobTasks = $this->Application->getModule('api')->get(array('jobs', 'tasks'), true)->output;
$jobsAllDirs = array();
foreach($jobTasks as $director => $tasks) {
$this->JobToVerifyJobName->dataSource = array_combine($jobsAllDirs, $jobsAllDirs);
$this->JobToVerifyJobName->dataBind();
- $clients = $this->Application->getModule('api')->get(array('clients'))->output;
+ $clients = $this->Application->getModule('api')->get(array('clients'), true)->output;
$clientsList = array();
foreach($clients as $client) {
$clientsList[$client->clientid] = $client->name;
$this->Client->dataSource = $clientsList;
$this->Client->dataBind();
- $filesetsAll = $this->Application->getModule('api')->get(array('filesets'))->output;
+ $filesetsAll = $this->Application->getModule('api')->get(array('filesets'), true)->output;
$filesetsList = array();
foreach($filesetsAll as $director => $filesets) {
$filesetsList = array_merge($filesets, $filesetsList);
$this->FileSet->dataSource = array_combine($filesetsList, $filesetsList);
$this->FileSet->dataBind();
- $pools = $this->Application->getModule('api')->get(array('pools'))->output;
+ $pools = $this->Application->getModule('api')->get(array('pools'), true)->output;
$poolList = array();
foreach($pools as $pool) {
$poolList[$pool->poolid] = $pool->name;
$this->Pool->dataSource = $poolList;
$this->Pool->dataBind();
- $storages = $this->Application->getModule('api')->get(array('storages'))->output;
+ $storages = $this->Application->getModule('api')->get(array('storages'), true)->output;
$storagesList = array();
foreach($storages as $storage) {
$storagesList[$storage->storageid] = $storage->name;