Overview

Namespaces

  • DcGeneral
    • Clipboard
    • Contao
      • Callback
      • Compatibility
      • DataDefinition
        • Definition
      • Dca
        • Builder
          • Legacy
        • Definition
        • Palette
        • Populator
      • Event
      • View
        • Contao2BackendView
          • Event
    • Controller
    • Data
    • DataDefinition
      • Builder
      • Definition
        • Properties
        • View
          • Panel
      • ModelRelationship
      • Palette
        • Builder
          • Event
        • Condition
          • Palette
          • Property
    • EnvironmentPopulator
    • Event
    • Exception
    • Factory
      • Event
    • Panel
    • View
      • Event

Classes

  • DataDefinitionContainer
  • DC_General
  • DcGeneral
  • DefaultEnvironment

Interfaces

  • ContainerAwareInterface
  • DataContainerInterface
  • DataDefinitionContainerInterface
  • EnvironmentAwareInterface
  • EnvironmentInterface
  • InputProviderInterface
  • ModelAwareInterface
  • ViewAwareInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * PHP version 5
  4:  * @package    generalDriver
  5:  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  6:  * @author     Stefan Heimes <stefan_heimes@hotmail.com>
  7:  * @copyright  The MetaModels team.
  8:  * @license    LGPL.
  9:  * @filesource
 10:  */
 11: 
 12: namespace DcGeneral;
 13: 
 14: use ContaoCommunityAlliance\Translator\Contao\LangArrayTranslator;
 15: use ContaoCommunityAlliance\Translator\TranslatorChain;
 16: use DcGeneral\Contao\Callback\Callbacks;
 17: use DcGeneral\Controller\Ajax2X;
 18: use DcGeneral\Controller\Ajax3X;
 19: use DcGeneral\Controller\ControllerInterface;
 20: use DcGeneral\Data\ModelInterface;
 21: use DcGeneral\Event\EventPropagator;
 22: use DcGeneral\Exception\DcGeneralRuntimeException;
 23: use DcGeneral\Factory\DcGeneralFactory;
 24: use DcGeneral\Factory\Event\PopulateEnvironmentEvent;
 25: use DcGeneral\View\ViewInterface;
 26: 
 27: /**
 28:  * This class is only present so Contao can instantiate a backend properly as it needs a \DataContainer descendant.
 29:  *
 30:  * @package DcGeneral
 31:  */
 32: // @codingStandardsIgnoreStart - Class is not in camelCase as Contao does not allow us to.
 33: class DC_General
 34: // @codingStandardsIgnoreEnd
 35:     extends \DataContainer
 36:     implements DataContainerInterface
 37: {
 38:     /**
 39:      * The environment attached to this DC.
 40:      *
 41:      * @var EnvironmentInterface
 42:      */
 43:     protected $objEnvironment;
 44: 
 45:     /**
 46:      * DCA configuration.
 47:      *
 48:      * @var array
 49:      */
 50:     protected $arrDCA = null;
 51: 
 52:     /**
 53:      * A list with all field for this dca.
 54:      *
 55:      * @var array
 56:      */
 57:     protected $arrFields = array();
 58: 
 59:     /**
 60:      * Create a new instance.
 61:      *
 62:      * @param string $strTable          The table name.
 63:      *
 64:      * @param array  $arrDCA            The Dca array.
 65:      *
 66:      * @param bool   $blnOnloadCallback Fire the onload callback.
 67:      */
 68:     public function __construct($strTable, array &$arrDCA = null, $blnOnloadCallback = true)
 69:     {
 70:         parent::__construct();
 71: 
 72:         $strTable = $this->getTablenameCallback($strTable);
 73: 
 74:         // In contao 3 the second constructor parameter is the backend module array.
 75:         // Therefore we have to check if the passed argument is indeed a valid DCA.
 76:         if ($arrDCA != null && $arrDCA['config'])
 77:         {
 78:             $this->arrDCA = $arrDCA;
 79:         }
 80:         else
 81:         {
 82:             $this->arrDCA = &$GLOBALS['TL_DCA'][$strTable];
 83:         }
 84: 
 85:         $dispatcher = $GLOBALS['container']['event-dispatcher'];
 86:         /** @var \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher */
 87:         $dispatcher->addListener(PopulateEnvironmentEvent::NAME, array($this, 'handlePopulateEnvironment'), 4800);
 88:         $propagator = new EventPropagator($dispatcher);
 89: 
 90:         $translator = new TranslatorChain();
 91:         $translator->add(new LangArrayTranslator($dispatcher));
 92: 
 93:         $factory = new DcGeneralFactory();
 94:         // We definitely want to get rid of this again when dropping all the callback handlers.
 95:         // See also implementation of: ExtendedLegacyDcaPopulator::populateCallback().
 96:         // FIXME: transporting the current instance via $GLOBALS is needed to tell the callback handler about this class.
 97:         $GLOBALS['objDcGeneral'] = $this;
 98: 
 99:         $factory
100:             ->setContainerName($strTable)
101:             ->setEventPropagator($propagator)
102:             ->setTranslator($translator)
103:             ->createDcGeneral();
104:         unset($GLOBALS['objDcGeneral']);
105:         $dispatcher->removeListener(PopulateEnvironmentEvent::NAME, array($this, 'handlePopulateEnvironment'));
106: 
107:         // Switch user for FE / BE support.
108:         switch (TL_MODE)
109:         {
110:             case 'FE':
111:                 $this->import('FrontendUser', 'User');
112:                 break;
113: 
114:             default:
115:             case 'BE':
116:                 $this->import('BackendUser', 'User');
117:                 break;
118:         }
119: 
120:         // Check for force mode.
121:         if ($this->arrDCA['config']['forceEdit'])
122:         {
123:             $this->blnForceEdit = true;
124:             $this->intId        = 1;
125:         }
126: 
127:         // Load the clipboard.
128:         $this->getEnvironment()->getClipboard()
129:             ->loadFrom($this->getEnvironment());
130: 
131:         // Execute AJAX request, called from Backend::getBackendModule
132:         // we have to do this here, as otherwise the script will exit as it only checks for DC_Table and DC_File
133:         // derived classes.
134:         // FIXME: dependency injection.
135:         if ($_POST && \Environment::getInstance()->isAjaxRequest)
136:         {
137:             $this->getViewHandler()->handleAjaxCall();
138: 
139:             // Fallback to Contao for ajax requests we do not know.
140:             if (version_compare(VERSION, '3.0', '>='))
141:             {
142:                 $objHandler = new Ajax3X();
143:             }
144:             else
145:             {
146:                 $objHandler = new Ajax2X();
147:             }
148:             $objHandler->executePostActions($this);
149:         }
150:     }
151: 
152:     /**
153:      * Callback coming from the environment populator.
154:      *
155:      * This is used to get to know the environment here in the DC.
156:      * See the implementation in constructor and ExtendedLegacyDcaPopulator::populateCallback().
157:      *
158:      * @param PopulateEnvironmentEvent $event The event.
159:      *
160:      * @return void
161:      */
162:     public function handlePopulateEnvironment(PopulateEnvironmentEvent $event)
163:     {
164:         $this->objEnvironment = $event->getEnvironment();
165:     }
166: 
167:     /**
168:      * Call the table name callback.
169:      *
170:      * @param string $strTable The current table name.
171:      *
172:      * @return string New name of current table.
173:      */
174:     protected function getTablenameCallback($strTable)
175:     {
176:         if (array_key_exists('tablename_callback', $GLOBALS['TL_DCA'][$strTable]['config'])
177:             && is_array($GLOBALS['TL_DCA'][$strTable]['config']['tablename_callback']))
178:         {
179:             foreach ($GLOBALS['TL_DCA'][$strTable]['config']['tablename_callback'] as $callback)
180:             {
181:                 $strCurrentTable = Callbacks::call($callback, $strTable, $this);
182: 
183:                 if ($strCurrentTable != null)
184:                 {
185:                     $strTable = $strCurrentTable;
186:                 }
187:             }
188:         }
189: 
190:         return $strTable;
191:     }
192: 
193:     /**
194:      * Magic getter.
195:      *
196:      * @param string $name Name of the property to retrieve.
197:      *
198:      * @return mixed
199:      *
200:      * @throws DcGeneralRuntimeException If an invalid key is requested.
201:      *
202:      * @deprecated magic access is deprecated.
203:      */
204:     public function __get($name)
205:     {
206:         switch ($name)
207:         {
208:             case 'table':
209:                 return $this->getEnvironment()->getDataDefinition()->getName();
210:             default:
211:         }
212: 
213:         throw new DcGeneralRuntimeException('Unsupported getter function for \'' . $name . '\' in DC_General.');
214:     }
215: 
216:     /**
217:      * Retrieve the DCA.
218:      *
219:      * @return array
220:      */
221:     public function getDCA()
222:     {
223:         return $this->arrDCA;
224:     }
225: 
226:     /**
227:      * Retrieve the name of the data container.
228:      *
229:      * @return string
230:      */
231:     public function getName()
232:     {
233:         return $this->getEnvironment()->getDataDefinition()->getName();
234:     }
235: 
236:     /**
237:      * Retrieve the environment.
238:      *
239:      * @return EnvironmentInterface
240:      *
241:      * @throws DcGeneralRuntimeException When no environment has been set.
242:      */
243:     public function getEnvironment()
244:     {
245:         if (!$this->objEnvironment)
246:         {
247:             throw new DcGeneralRuntimeException('No Environment set.');
248:         }
249: 
250:         return $this->objEnvironment;
251:     }
252: 
253:     /**
254:      * Retrieve the view.
255:      *
256:      * @return ViewInterface
257:      */
258:     public function getViewHandler()
259:     {
260:         return $this->getEnvironment()->getView();
261:     }
262: 
263:     /**
264:      * Retrieve the controller.
265:      *
266:      * @return ControllerInterface
267:      */
268:     public function getControllerHandler()
269:     {
270:         return $this->getEnvironment()->getController();
271:     }
272: 
273:     /**
274:      * Delegate all calls directly to current view.
275:      *
276:      * @param string $name      Name of the method.
277:      *
278:      * @param array  $arguments Array of arguments.
279:      *
280:      * @return mixed
281:      */
282:     public function __call($name, $arguments)
283:     {
284:         return call_user_func_array(array($this->getViewHandler(), $name), $arguments);
285:     }
286: 
287:     /**
288:      * Do not use.
289:      *
290:      * @deprecated Only here as requirement of \editable
291:      *
292:      * @return string
293:      */
294:     public function copy()
295:     {
296:         return $this->getViewHandler()->copy();
297:     }
298: 
299:     /**
300:      * Do not use.
301:      *
302:      * @deprecated Only here as requirement of \editable
303:      *
304:      * @return string
305:      */
306:     public function create()
307:     {
308:         return $this->getViewHandler()->create();
309:     }
310: 
311:     /**
312:      * Do not use.
313:      *
314:      * @deprecated Only here as requirement of \editable
315:      *
316:      * @return string
317:      */
318:     public function cut()
319:     {
320:         return $this->getViewHandler()->cut();
321:     }
322: 
323:     /**
324:      * Do not use.
325:      *
326:      * @deprecated Only here as requirement of \listable
327:      *
328:      * @return string
329:      */
330:     public function delete()
331:     {
332:         return $this->getViewHandler()->delete();
333:     }
334: 
335:     /**
336:      * Do not use.
337:      *
338:      * @deprecated Only here as requirement of \editable
339:      *
340:      * @return string
341:      */
342:     public function edit()
343:     {
344:         return $this->getViewHandler()->edit();
345:     }
346: 
347:     /**
348:      * Do not use.
349:      *
350:      * @deprecated Only here as requirement of \editable
351:      *
352:      * @return string
353:      */
354:     public function move()
355:     {
356:         return $this->getViewHandler()->move();
357:     }
358: 
359:     /**
360:      * Do not use.
361:      *
362:      * @deprecated Only here as requirement of \listable
363:      *
364:      * @return string
365:      */
366:     public function show()
367:     {
368:         return $this->getViewHandler()->show();
369:     }
370: 
371:     /**
372:      * Do not use.
373:      *
374:      * @deprecated Only here as requirement of \listable
375:      *
376:      * @return string
377:      */
378:     public function showAll()
379:     {
380:         return $this->getViewHandler()->showAll();
381:     }
382: 
383:     /**
384:      * Do not use.
385:      *
386:      * @deprecated Only here as requirement of \listable
387:      *
388:      * @return string
389:      */
390:     public function undo()
391:     {
392:         return $this->getViewHandler()->undo();
393:     }
394: }
395: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0