コード例 #1
0
ファイル: FeedWidgetHandler.php プロジェクト: tlandn/akvo-web
 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 display($aAttributes)
 {
     $oDaoJsonData = new JsonDataDao();
     $sFeedSlug = $aAttributes['slug'];
     unset($aAttributes['slug']);
     $aFeed = $oDaoJsonData->fetchFeedBySlug($sFeedSlug);
     $iFeedId = $aFeed['id'];
     $aDefaultParameters = unserialize($aFeed['feed_parameters']);
     ksort($aAttributes);
     ksort($aDefaultParameters);
     $aNewKeys = array_diff($aAttributes, $aDefaultParameters);
     $aAllParams = array_merge($aDefaultParameters, $aNewKeys);
     ksort($aAllParams);
     $aAttributes = array_combine(array_keys($aAllParams), $aAttributes);
     ksort($aAttributes);
     $sSerializedParameters = serialize($aAttributes);
     $aFeedDetail = $oDaoJsonData->fetchSingleFeedQueueByParams($iFeedId, $sSerializedParameters);
     if (!$aFeedDetail) {
         $aInsertData = array();
         $aInsertData['json_data_id'] = $iFeedId;
         $aInsertData['parameters'] = $sSerializedParameters;
         $aInsertData['last_update_time'] = date('Y-m-d H:i:s');
         $aInsertData['last_display_time'] = date('Y-m-d H:i:s');
         $mStatus = $oDaoJsonData->insertJsonDataQueue($aInsertData);
         if (is_int($mStatus)) {
             $oFeed = new JsonDataFeed();
             $oFeed->updateQueue($iFeedId, $mStatus);
             $aFeedDetail = $oDaoJsonData->fetchSingleFeedQueueByParams($iFeedId, $sSerializedParameters);
         }
     }
     if ($aFeedDetail) {
         $iFeedId = $aFeedDetail['json_data_id'];
         $iFeedQueueId = $aFeedDetail['id'];
         $oDaoJsonData->updateDisplayTime($iFeedQueueId);
         $this->enqueueFrontEndCss($iFeedId, $sFeedSlug);
         $sData = file_get_contents(JsonData_Cache_Dir . DIRECTORY_SEPARATOR . $sFeedSlug . DIRECTORY_SEPARATOR . 'data-' . $iFeedQueueId . '.json');
         $aData = json_decode($sData, true);
         require JsonData_Cache_Dir . $sFeedSlug . DIRECTORY_SEPARATOR . 'template.phtml';
     }
 }