代码之家  ›  专栏  ›  技术社区  ›  c.holtermann

Typo3 cal(日历基)在外部扩展中使用事件对象

  •  0
  • c.holtermann  · 技术社区  · 6 年前

    我正在开发一个扩展,它取决于cal base。我通过爬行他们的网站从其他来源获取事件。

    我正在慢慢地转换到extbase,我想知道是否有可能或者如何从我的扩展中访问calbase事件。

    我知道我可以使用mapOnProperty访问表。但我也必须重写整个逻辑。

    我想知道是否可以只使用日历基的对象。

    我试着写一个测试:

    <?php
    class CalEventTest extends \TYPO3\CMS\Core\Tests\BaseTestCase {
    
        /**
          * @test
          */
        public function anInstanceOfCalEventCanBeConstructed() {
                $calEventService = & \TYPO3\CMS\Cal\Utility\Functions::getEventService ();
                // $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
                // $calEventService = $objectManager->get('TYPO3\CMS\Cal\Service\EventService');
                // $calEventService = new TYPO3\CMS\Cal\Service\EventService();
                // $events = $calEventService->findAll(array(1)); 
       }       
    }
    

    你可以看到不同的尝试被注释掉了。他们都以这样或那样的方式失败了。CalEventService看起来很有前途,但也不起作用。最后一种方法的错误是。

    Call to a member function isLoggedIn() on null in /var/www/clients/client4/web47/web/typo3conf/ext/cal/Classes/Service/NearbyEventService.php on line 27
    

    在尝试更多之前,我想知道这种方法是否可行(提到的错误似乎与测试环境上下文有关)。

    我使用的是Typo3 6.2.27和cal 1.10.1。

    3 回复  |  直到 6 年前
        1
  •  1
  •   jpsecher briankip    6 年前

    未进行喷射测试,但作为 Manual 说你应该访问 EventService 这样地:

    $storagePageID = 123;
    /** @var \TYPO3\CMS\Cal\Service\EventService $eventService **/
    $eventService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceService('tx_cal_phpicalendar', 'cal_event_model');
    $events = $eventService->findAll($storagePageID);
    
        2
  •  0
  •   c.holtermann    6 年前

    我发现cal API看起来很有前途

    /**
      * @test
      */
    public function calApiCanBeAccessed() {
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
        $calAPIPre = $objectManager->get('TYPO3\CMS\Cal\Controller\Api');
    
        $this->assertInstanceOf(TYPO3\CMS\Cal\Controller\Api::class, $calAPIPre);
        $this->assertObjectHasAttribute('prefixId', $calAPIPre);
    
        $pidList = "1095, 80";
    
        $calAPI = $calAPIPre->tx_cal_api_without($pidList);
    
        $this->assertInstanceOf(TYPO3\CMS\Cal\Controller\Api::class, $calAPI);
        $this->assertObjectHasAttribute('prefixId', $calAPI);
        $this->assertInstanceOf(TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, $calAPI->cObj);
    }
    

    并成功返回事件对象

    /**
      * @test                                                                                                  
      */
    public function calEventCanBeFoundThroughApi() {
        $pidList = "1095, 80";
        $eventUid = '2670';
    
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
        $calAPI = $objectManager->get('TYPO3\CMS\Cal\Controller\Api')->tx_cal_api_without($pidList);
    
        $event = $calAPI->findEvent($eventUid, 'tx_cal_phpicalendar', $pidList);
    
        $this->assertInstanceOf(TYPO3\CMS\Cal\Model\Eventmodel::class, $event);
    }
    

    在内部,它似乎使用模拟TSFE上下文的方法(如果没有cObj,我没有尝试 tx_cal_api_with(&$cObj, &$conf) 方法)。

        3
  •  0
  •   c.holtermann    6 年前

    读了一篇2012年的老文章( https://forum.typo3.org/index.php/t/192263/ )我在Typo3 6.2设置中实现了这一点:

    <?php
    class CalEventTest extends \TYPO3\CMS\Core\Tests\BaseTestCase {
    
        /**
          * @test
          */
        public function anInstanceOfCalEventCanBeConstructed() {
                $rightsObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry ('basic', 'rightscontroller');
                $rightsObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceService('cal_rights_model', 'rights');
                $rightsObj->setDefaultSaveToPage();
    
                $modelObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','modelcontroller');
                $modelObj = new \TYPO3\CMS\Cal\Controller\ModelController();
    
                $viewObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','viewcontroller');
                $viewObj = new \TYPO3\CMS\Cal\Controller\ViewController();
    
                $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
                $configurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface');
    
                $controller = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','controller');
                $controller = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Controller\\Controller');
    
                $cObj = &\TYPO3\CMS\Cal\Utility\Registry::Registry('basic','cobj');
                $cObj = $configurationManager->getContentObject();
                $cObj = new TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer();
    
                $GLOBALS['TSFE'] = new \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController($GLOBALS['TYPO3_CONF_VARS'], $pid, '0', 1, '', '', '', '');
                $GLOBALS['TSFE']->cObj = $cObj;
                $GLOBALS['TSFE']->sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
    
                $storagePageID = "1095, 80";
    
                $eventService = & \TYPO3\CMS\Cal\Utility\Functions::getEventService ();
    
                if ($eventService) {
                        $events = $eventService->findAll($storagePageID);
                        \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('2', $this->getDebugId()."-".__FUNCTION__, -1, array($events, $eventService->getServiceKey ()) );
                }
       }       
    }
    

    这很管用,但我觉得它非常难看。接下来我将尝试cal api。

    (这是对我的问题的编辑,但实际上是一个答案)