Exemple #1
0
 /**
  * Determines if the specified record is enabled or disabled by the current
  * contexts (means that the records is disabled if one of the enableSettings
  * are disabled for one of the current contexts)
  *
  * @param string        $table Table name
  * @param array|integer $row   Record array or an uid
  *
  * @return boolean
  */
 public static function isEnabled($table, $row)
 {
     global $TCA;
     $enableSettings = Tx_Contexts_Api_Configuration::getEnableSettings($table);
     if (!$enableSettings) {
         return true;
     }
     foreach ($enableSettings as $setting) {
         if (!self::isSettingEnabled($table, $setting, $row)) {
             return false;
         }
     }
     return true;
 }
Exemple #2
0
 /**
  * Generates a SQL WHERE statement that filters out records
  * that may not be accessed with the current context settings
  *
  * @param string $table Database table name
  * @return string SQL filter string beginning with " AND "
  */
 protected function getFilterSql($table)
 {
     global $TCA;
     $sql = '';
     foreach (Tx_Contexts_Api_Configuration::getEnableSettings($table) as $setting) {
         $flatColumns = Tx_Contexts_Api_Configuration::getFlatColumns($table, $setting);
         if (!$flatColumns) {
             t3lib_div::devLog('Missing flat columns for setting "' . $setting . '"', 'tx_contexts', 2, array('table' => $table));
             continue;
         }
         $enableChecks = array($flatColumns[1] . " = ''");
         $disableChecks = array();
         foreach (Tx_Contexts_Context_Container::get() as $context) {
             /* @var $context Tx_Contexts_Context_Abstract */
             $enableChecks[] = $GLOBALS['TYPO3_DB']->listQuery($flatColumns[1], $context->getUid(), $table);
             $disableChecks[] = 'NOT ' . $GLOBALS['TYPO3_DB']->listQuery($flatColumns[0], $context->getUid(), $table);
         }
         $sql = ' AND (' . implode(' OR ', $enableChecks) . ')';
         if (count($disableChecks)) {
             $sql .= ' AND (' . $flatColumns[0] . " = ''" . ' OR (' . implode(' AND ', $disableChecks) . ')' . ')';
         }
     }
     return $sql;
 }