/**
  * This method is used to initialize new Elements with the default
  *
  * @param unknown_type $status
  * @param unknown_type $table
  * @param unknown_type $id
  * @param unknown_type $fieldArray
  * @param unknown_type $reference
  */
 public function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, &$reference)
 {
     if (in_array($table, tx_languagevisibility_visibilityService::getSupportedTables())) {
         /**
          * Now we set the default visibility for elements which did not get a defaultvisibility array.
          * This can happen, if a user creates a new element AND the user has no access for the languagevisibility_field
          */
         if ($status == 'new') {
             $row['uid'] = $reference->substNEWwithIDs[$id];
             if ($fieldArray['pid'] == '-1') {
                 $row = t3lib_BEfunc::getWorkspaceVersionOfRecord($fieldArray['t3ver_wsid'], $table, $row['uid'], $fields = '*');
             }
             require_once t3lib_extMgm::extPath("languagevisibility") . 'class.tx_languagevisibility_beservices.php';
             $newdata = array('tx_languagevisibility_visibility' => serialize(tx_languagevisibility_beservices::getDefaultVisibilityArray()));
             $where = "tx_languagevisibility_visibility = '' AND uid=" . $row['uid'];
             $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $where, $newdata);
         }
         tx_languagevisibility_cacheManager::getInstance()->flushAllCaches();
     }
 }
 /**
  * Method to check if records of a given table support the languagevisibility feature
  *
  * @param string $table
  * @return boolean
  */
 public static function isSupportedTable($table)
 {
     $supported = tx_languagevisibility_visibilityService::getSupportedTables();
     if (in_array($table, $supported)) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Every element can be tested if it is visible for a given language. In addition a
  * description can be delivered why an element is visible or not.
  *
  * @param void
  * @return void
  * @author Timo Schmidt <*****@*****.**>
  * @test
  */
 public function canGetCorrectVisiblityDescriptionForElementWithInheritedVisibility()
 {
     $this->importDataSet(dirname(__FILE__) . '/fixtures/canGetCorrectVisiblityDescriptionForElementWithInheritedVisibility.xml');
     $language = $this->_getLang(1);
     $service = new tx_languagevisibility_visibilityService();
     $service->setUseInheritance();
     $dao = new tx_languagevisibility_daocommon();
     $factory = new tx_languagevisibility_elementFactory($dao);
     /* @var $element tx_languagevisibility_pageelement*/
     $element = $factory->getElementForTable('pages', 7);
     $visibilityDescription = $service->getVisibilityDescription($language, $element);
     $this->assertEquals('force to no (inherited from uid 5)', $visibilityDescription, 'invalid visibility description of element with inheritance');
 }
 /**
  * We have the same situation as before but in this
  * testcase we test the visibility of page c and change
  * the pid afterward. Because the visibility is forced
  * to no by inheritance, it should normaly be visible,
  * but the result of the visibility is chached in
  * that situation and the visibility will only change afterwards
  * when the cache was flushed.
  *
  * @param void
  * @return void
  * @author Timo Schmidt <*****@*****.**>
  * @test
  */
 public function changeOfPidDoesNotInfluenceCachedResult()
 {
     $cacheManager = tx_languagevisibility_cacheManager::getInstance();
     $isCacheEnabled = $cacheManager->isCacheEnabled();
     $this->assertTrue($isCacheEnabled, 'Cache needs to be enabled to perform this test');
     $this->importDataSet(dirname(__FILE__) . '/fixtures/canDetermineInheritedVisibility.xml');
     $fixtureLanguageRow = array('uid' => 1, 'tx_languagevisibility_defaultvisibility' => 't');
     $fixtureLanguage = new tx_languagevisibility_language();
     $fixtureLanguage->setData($fixtureLanguageRow);
     $dao = new tx_languagevisibility_daocommon();
     $elementFactory = new tx_languagevisibility_elementFactory($dao);
     $fixtureElement = $elementFactory->getElementForTable('pages', 3);
     $visibilityService = new tx_languagevisibility_visibilityService();
     $visibilityResult = true;
     $visibilityResult = $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
     $this->assertFalse($visibilityResult, 'The element should not be visibile because of the inherited force to no setting');
     $db = $GLOBALS['TYPO3_DB'];
     /* @var  $db t3lib_db */
     $db->exec_UPDATEquery('pages', 'pid=2', array('pid' => 0));
     $visibilityResult = $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
     $this->assertFalse($visibilityResult, 'The element should not still not be visible because the visibility result is cached');
     tx_languagevisibility_cacheManager::getInstance()->flushAllCaches();
     $visibilityResult = $visibilityService->isVisible($fixtureLanguage, $fixtureElement);
     $this->assertTrue($visibilityResult, 'Now the element should be visible because the cache was flushed');
 }
 /**
  * Function to configure the visibilityService to use inherited settings.
  *
  * @param boolean $useInheritance
  */
 public static function setUseInheritance($useInheritance = true)
 {
     self::$useInheritance = $useInheritance;
 }