예제 #1
0
 public function editorWidget($aFormValues)
 {
     $aContent = array();
     $aContent['status'] = 'failed';
     $aContent['message'] = '';
     $aContent['isFormValid'] = false;
     $aFeedParameters = $aFormValues['textParam'];
     $oForm = new \JsonData\Admin\Form\FeedWidget(\JsonData\Admin\Form\FeedWidget::CONTEXT_SELECT_FEED, array(), array('feed_parameters' => $aFeedParameters));
     if ($oForm->isValid($aFormValues)) {
         $aContent['isFormValid'] = true;
         ksort($aFeedParameters);
         $aInsertData = array();
         $aInsertData['json_data_id'] = $aFormValues['hiddenFeedId'];
         $aInsertData['parameters'] = serialize($aFeedParameters);
         $aInsertData['last_update_time'] = date('Y-m-d H:i:s');
         $aInsertData['last_display_time'] = date('Y-m-d H:i:s');
         $oDaoJsonData = new \JsonData\Common\Model\Dao\JsonData();
         $mStatus = $oDaoJsonData->insertJsonDataQueue($aInsertData);
         if (is_int($mStatus)) {
             $aFeed = $oDaoJsonData->fetchFeed($aInsertData['json_data_id']);
             $oFeed = new JsonDataFeed();
             $oFeed->updateQueue($aInsertData['json_data_id'], $mStatus);
             $aContent['queue_id'] = $mStatus;
             $aContent['slug'] = $aFeed['feed_slug'];
             $aContent['status'] = 'success';
             $aContent['message'] = 'Data successfully saved to database';
         } else {
             $aContent['message'] = 'Failed to save data';
         }
     }
     return $aContent;
 }
예제 #2
0
파일: Feed.php 프로젝트: tlandn/akvo-web
 public function getFeed()
 {
     $aContent = array('redirect' => false);
     $sRedirectUrl = menu_page_url(\JsonData\Admin\Controller\Home::MENU_SLUG, false);
     if (!isset($_GET['id'])) {
         $aContent['redirect'] = $sRedirectUrl;
         return $aContent;
     }
     $iId = (int) $_GET['id'];
     $oDaoFeed = new JDDao\JsonData();
     $aDetail = $oDaoFeed->fetchFeed($iId);
     if (is_null($aDetail)) {
         $aContent['redirect'] = $sRedirectUrl;
         return $aContent;
     }
     $aContent['detail'] = $aDetail;
     return $aContent;
 }
예제 #3
0
파일: Feed.php 프로젝트: tlandn/akvo-web
 private function _updateSingleQueue($mFeed, $mQueue)
 {
     $oDaoJsonData = new JsonDataDao();
     if (!is_array($mFeed)) {
         $aFeed = $oDaoJsonData->fetchFeed($mFeed);
     } else {
         $aFeed = $mFeed;
     }
     if (!is_array($mQueue)) {
         $aFeedQueue = $oDaoJsonData->fetchSingleFeedQueue($mQueue);
     } else {
         $aFeedQueue = $mQueue;
     }
     $iFeedId = $aFeed['feed_slug'];
     $sDirName = $this->_sCacheDirName . DIRECTORY_SEPARATOR . $iFeedId;
     //build url for queue
     $aUrl = explode('?', $aFeed['feed_url']);
     $sRootUrl = $aUrl[0];
     $iQueueId = $aFeedQueue['id'];
     $sQueueDataFilename = $sDirName . DIRECTORY_SEPARATOR . 'data-' . $iQueueId . '.json';
     //$iFeedId = $aFeedQueue['json_data_id'];
     $aQueueParams = unserialize($aFeedQueue['parameters']);
     $sUrlParams = http_build_query($aQueueParams);
     $sQueueUrl = $sRootUrl . '?' . $sUrlParams;
     //write json to cache file
     $sJsonData = file_get_contents($sQueueUrl);
     $fQueueData = fopen($sQueueDataFilename, 'w+');
     fwrite($fQueueData, $sJsonData);
     fclose($fQueueData);
     chmod($sQueueDataFilename, 0755);
     $oDaoJsonData->updateFeedQueue(array('last_update_time' => date('Y-m-d H:i:s')), $iQueueId);
 }
예제 #4
0
 public function remove()
 {
     $aContent = array();
     $aContent['redirect'] = JDConfig::getHomeRedirectUrl();
     if (!isset($_GET['id'])) {
     }
     $iId = $_GET['id'];
     $oDaoJsonData = new JsonDataDao();
     $aDetail = $oDaoJsonData->fetchFeed($iId);
     if (!empty($aDetail)) {
         $bStatus = $oDaoJsonData->deleteFeed($iId);
         if (is_int($bStatus)) {
             $aFeedQueues = $oDaoJsonData->fetchFeedQueue($iId);
             //get all feedques with same id
             $aToBeDeleteId = array();
             foreach ($aFeedQueues as $aFeedRaw) {
                 $aToBeDeleteId[] = $aFeedRaw['id'];
             }
             array_map(array(&$oDaoJsonData, 'deleteFeedQueue'), $aToBeDeleteId);
             //delete all feed associate with id
             $oFeed = new JsonDataFeed();
             $oFeed->removeFeedDir($aDetail['feed_slug']);
             //remove files and directory
         }
     }
     //        var_dump($bStatus);
     //        var_dump(JDConfig::getHomeRedirectUrl());
     //        die();
     if ($bStatus != false) {
         $aContent['redirect'] = JDConfig::getHomeRedirectUrl();
     }
     return $aContent;
 }