Exemple #1
0
 public function getTabs()
 {
     $allContentKeys = array('resource' => array('resource_id', 'resource'), 'thread' => array('thread_id', 'thread'), 'conversation' => array('conversation_id', 'conversation'), 'project' => array('project_id', 'freeagent_project'), 'media' => array('media_id', 'xengallery_media'), 'product' => array('product_id', 'xenproduct_product'));
     $contentKeys = array();
     $params = $this->_view->getParams();
     foreach ($allContentKeys as $contentKeyId => $contentTypeInfo) {
         if (isset($params[$contentKeyId])) {
             $contentTypes[] = $contentTypeInfo[1];
             $contentIdKeys[] = $contentTypeInfo[0];
             $contentKeys[] = $contentKeyId;
         }
     }
     /* @var $tabModel Waindigo_Tabs_Model_Tab */
     $tabModel = XenForo_Model::create('Waindigo_Tabs_Model_Tab');
     $canAddExistingContentToTab = false;
     for ($i = 0; $i < isset($contentKeys) ? count($contentKeys) : 0; $i++) {
         $content = $params[$contentKeys[$i]];
         if (!isset($content['tab_id']) || !$content['tab_id']) {
             continue;
         }
         if (!$canAddExistingContentToTab) {
             $canAddExistingContentToTab = $tabModel->canAddExistingContentToTab(array('tab_id' => $content['tab_id']));
         }
         $tabContents = $tabModel->getTabContentsByTabId($content['tab_id']);
         $tabContents = $tabModel->prepareTabContents($tabContents, $contentTypes[$i], $content[$contentIdKeys[$i]], $content);
         $this->_view->setParams(array('tabContents' => $tabContents));
         break;
     }
     if (!$canAddExistingContentToTab) {
         $canAddExistingContentToTab = $tabModel->canAddExistingContentToTab(array());
     }
     $this->_view->setParams(array('canAddExistingContentToTab' => $canAddExistingContentToTab));
 }
Exemple #2
0
 public static function prepareViewParams(XenForo_ViewRenderer_Abstract $viewRenderer, XenForo_View $view)
 {
     $params = $view->getParams();
     $jobs = array();
     if (!empty($params['jobs'])) {
         foreach ($params['jobs'] as $jobId => $job) {
             $preparedJob = array();
             if (empty($job['_job_result'])) {
                 continue;
             }
             $preparedJob['_job_result'] = $job['_job_result'];
             switch ($job['_job_result']) {
                 case 'error':
                     if (empty($job['_job_error'])) {
                         continue;
                     }
                     $preparedJob['_job_error'] = $job['_job_error'];
                     break;
                 case 'message':
                     if (empty($job['_job_message'])) {
                         continue;
                     }
                     $preparedJob['_job_message'] = $job['_job_message'];
                     break;
                 case 'ok':
                     if (empty($job['_job_response'])) {
                         continue;
                     }
                     /** @var XenForo_ControllerResponse_View $response */
                     $response = $job['_job_response'];
                     $viewOutput = $viewRenderer->renderViewObject($response->viewName, 'Json', $response->params, $response->templateName);
                     if (!is_array($viewOutput)) {
                         $viewOutput = @json_decode($viewOutput, true);
                     }
                     if (is_array($viewOutput)) {
                         $preparedJob = array_merge($preparedJob, $viewOutput);
                     } elseif ($viewOutput === null) {
                         $preparedJob = array_merge($preparedJob, $response->params);
                     }
                     break;
                 default:
                     continue;
             }
             $jobs[$jobId] = $preparedJob;
         }
     }
     return array('jobs' => $jobs);
 }