Example #1
0
 /**
  * @param $dc
  */
 public function callbackInitialize($dc)
 {
     $table = get_class($dc) == 'DcGeneral\\DC_General' ? $dc->getTable() : $dc->table;
     $model = ModelFactory::byDc($dc, true);
     $controller = $controller = DcaTools::getInstance($table);
     $controller->initialize($model);
 }
 /**
  * Toggle state of a value
  *
  * @param Event\GenerateEvent $objEvent
  * @param array $arrConfig
  * @param $intId
  *
  * @param $blnVisible
  */
 protected static function toggleState(Event\GenerateEvent $objEvent, array $arrConfig, $intId, $blnVisible)
 {
     // Check permissions to edit
     \Input::setGet('id', $intId);
     \Input::setGet('act', 'toggle');
     // trigger permission checking
     $name = $objEvent->getModel()->getProviderName();
     $objEvent->getDispatcher()->dispatch(sprintf('dcatools.%s.check-permission', $name));
     /** @var \BackendUser $objUser */
     $objUser = \BackendUser::getInstance();
     if (isset($arrConfig['inverted'])) {
         $blnVisible = !$blnVisible;
     }
     $strTable = isset($arrConfig['table']) ? $arrConfig['table'] : $name;
     $strProperty = isset($arrConfig['property']) ? $arrConfig['property'] : 'published';
     // Check permissions to publish
     if (!$objUser->isAdmin && !$objUser->hasAccess($strTable . '::' . $strProperty, 'alexf')) {
         $strError = 'Not enough permissions to toggle state of item ID "' . $intId . '"';
         $strError = Permissions::prepareErrorMessage($arrConfig, $strError);
         DcaTools::error($strError);
     }
     $objVersions = new \Versions($strTable, $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA'][$strTable]['propertys'][$strProperty]['save_callback'])) {
         foreach ($GLOBALS['TL_DCA'][$strTable]['propertys'][$strProperty]['save_callback'] as $callback) {
             $objCallback = new $callback[0]();
             $blnVisible = $objCallback->{$callback}[1]($blnVisible, $objEvent);
         }
     }
     // Update the database
     \Database::getInstance()->prepare("UPDATE {$strTable} SET tstamp=" . time() . ", {$strProperty} ='" . ($blnVisible ? 1 : '') . "' WHERE id=?")->execute($intId);
     $objVersions->create();
 }