Esempio n. 1
0
 /**
  * Retrieve the widget id
  *
  * @param  boolean $autoGenerate automatically generate the id if none is
  *                               already set
  * @return string
  */
 public function getId($autoGenerate = true)
 {
     if (!$this->id && $autoGenerate) {
         $this->id = self::ID_PREFIX . WidgetId::get();
     }
     return $this->id;
 }
 public function setUp()
 {
     $config = ['defaultNamespace' => 'Arrilot\\Widgets\\Test\\Dummies'];
     $app = new TestApplicationWrapper();
     $this->factory = new WidgetFactory($config, $app);
     WidgetId::reset();
 }
 /**
  * Set class properties and instantiate a widget object.
  *
  * @param $params
  *
  * @throws InvalidWidgetClassException
  */
 protected function instantiateWidget(array $params = [])
 {
     WidgetId::increment();
     $this->widgetName = $this->parseFullWidgetNameFromString(array_shift($params));
     $this->widgetFullParams = $params;
     $this->widgetConfig = (array) array_shift($params);
     $this->widgetParams = $params;
     $rootNamespace = $this->app->config('laravel-widgets.default_namespace', $this->app->getNamespace() . 'Widgets');
     $fqcn = $rootNamespace . '\\' . $this->widgetName;
     $widgetClass = class_exists($fqcn) ? $fqcn : $this->widgetName;
     if (!is_subclass_of($widgetClass, 'Arrilot\\Widgets\\AbstractWidget')) {
         throw new InvalidWidgetClassException('Class "' . $widgetClass . '" must extend "Arrilot\\Widgets\\AbstractWidget" class');
     }
     $this->widget = new $widgetClass($this->widgetConfig);
 }
Esempio n. 4
0
 public function tearDown()
 {
     WidgetId::reset();
 }
 /**
  * Set class properties and instantiate a widget object.
  *
  * @param $params
  *
  * @throws InvalidWidgetClassException
  */
 protected function instantiateWidget(array $params = [])
 {
     WidgetId::increment();
     $this->widgetName = $this->parseFullWidgetNameFromString(array_shift($params));
     $this->widgetFullParams = $params;
     $this->widgetConfig = (array) array_shift($params);
     $this->widgetParams = $params;
     $widgetClass = class_exists($this->widgetName) ? $this->widgetName : $this->config['defaultNamespace'] . '\\' . $this->widgetName;
     $widget = new $widgetClass($this->widgetConfig);
     if ($widget instanceof AbstractWidget === false) {
         throw new InvalidWidgetClassException();
     }
     $this->widget = $widget;
 }
 public function let(LaravelApplicationWrapper $wrapper)
 {
     $this->beConstructedWith($this->config, $wrapper);
     WidgetId::reset();
 }
 /**
  * Construct ajax call with jquery.
  *
  * @param string $url
  *
  * @return string
  */
 protected function constructJqueryAjaxCall($url)
 {
     $id = WidgetId::get();
     return "var widgetTimer{$id} = setInterval(function() {" . 'if (window.$) {' . "\$('#{$this->getContainerId()}').load('{$url}');" . "clearInterval(widgetTimer{$id});" . '}' . '}, 100);';
 }
 /**
  * Get the current widget container id.
  *
  * @return string
  */
 public function getContainerId()
 {
     return 'arrilot-widget-container-' . WidgetId::get();
 }
 /**
  * Set some specials variables to modify the workflow of the widget factory.
  *
  * @param Request $request
  */
 protected function prepareGlobals(Request $request)
 {
     WidgetId::set($request->input('id', 1) - 1);
     AbstractWidgetFactory::$skipWidgetContainer = true;
 }