/** * * @param Ajde_Controller $controller * @return Ajde_View */ public static function fromController(Controller $controller) { $base = MODULE_DIR . $controller->getModule() . '/'; $action = $controller->getRoute()->getController() ? $controller->getRoute()->getController() . '/' . $controller->getAction() : $controller->getAction(); $format = $controller->hasFormat() ? $controller->getFormat() : 'html'; return new self($base, $action, $format); }
public function process() { switch ($this->_attributeParse()) { case 'list': $options = issetor($this->attributes['options'], array()); $crud = new AjdeCrud($this->attributes['model'], $options); $crud->setAction('list'); return $crud; break; case 'edit': $options = issetor($this->attributes['options'], array()); $id = issetor($this->attributes['id'], null); $crud = new AjdeCrud($this->attributes['model'], $options); $crud->setId($id); $crud->setAction('edit/layout'); return $crud; break; case 'mainfilter': $controller = Controller::fromRoute(new Route('_core/crud:mainfilter')); $controller->setCrud($this->attributes['crud']); $controller->setRefresh(issetor($this->attributes['refresh'], false)); return $controller->invoke(); } // TODO: throw new Exception(); }
public static function getImageTag($filename, $width = null, $height = null, $crop = true, $class = '', $lazy = false, $absoluteUrl = false) { $image = new AjdeResourceImage($filename); $image->setWidth($width); $image->setHeight($height); $image->setCrop($crop); $controller = Controller::fromRoute(new Route('_core/component:image')); $controller->setImage($image); $controller->setExtraClass($class); $controller->setLazy($lazy); $controller->setAbsoluteUrl($absoluteUrl); return $controller->invoke(); }
public function process() { switch ($this->_attributeParse()) { case 'html': $qr = new AjdeResourceQrcode($this->attributes['text']); $controller = Controller::fromRoute(new Route('_core/component:qrcode')); $controller->setQrcode($qr); return $controller->invoke(); break; } // TODO: throw new Exception('Missing required attributes for component call'); }
public function getRevisionsHtml($crud = null) { if (!$this->getPK()) { return; } $revisions = new RevisionCollection(); $revisions->addFilter(new Where('model', Filter::FILTER_EQUALS, $this->getModelName())); $revisions->addFilter(new Where('foreignkey', Filter::FILTER_EQUALS, $this->getPK())); $revisions->orderBy('time', 'DESC'); $revisions->limit(self::DEFAULT_LIMIT); $controller = Controller::fromRoute(new Route('_core/crud:revisions')); $controller->setRevisions($revisions); $controller->setModel($this); $controller->setCrud($crud); return $controller->invoke(); }
public function process() { switch ($this->_attributeParse()) { case 'render': $image = new Image($this->attributes['filename']); $image->setWidth($this->attributes['width']); $image->setHeight($this->attributes['height']); $image->setCrop(String::toBoolean($this->attributes['crop'])); $controller = Controller::fromRoute(new Route('_core/component:imageBase64')); $controller->setImage($image); $controller->setWidth(issetor($this->attributes['width'], null)); $controller->setHeight(issetor($this->attributes['height'], null)); $controller->setExtraClass(issetor($this->attributes['class'], '')); return $controller->invoke(); break; } // TODO: throw new Exception('Missing required attributes for component call'); }
public function process() { switch ($this->_attributeParse()) { case 'form': $controller = Controller::fromRoute(new Route('_core/component:form')); $controller->setFormAction($this->attributes['route']); $controller->setFormId(issetor($this->attributes['id'], spl_object_hash($this))); $controller->setExtraClass(issetor($this->attributes['class'], '')); $controller->setInnerXml($this->innerXml); return $controller->invoke(); break; case 'ajax': $controller = Controller::fromRoute(new Route('_core/component:formAjax')); $formAction = new Route($this->attributes['route']); $formAction->setFormat(issetor($this->attributes['format'], 'json')); $controller->setFormAction($formAction->__toString()); $controller->setFormFormat(issetor($this->attributes['format'], 'json')); $controller->setFormId(issetor($this->attributes['id'], spl_object_hash($this))); $controller->setExtraClass(issetor($this->attributes['class'], '')); $controller->setInnerXml($this->innerXml); return $controller->invoke(); break; case 'upload': $controller = Controller::fromRoute(new Route('_core/component:formUpload')); if (!isset($this->attributes['options']) || !isset($this->attributes['options']['saveDir']) || !isset($this->attributes['options']['extensions'])) { // TODO: throw new Exception('Options saveDir and extensions must be set for AC.Form.Upload'); } $controller->setName($this->attributes['name']); $controller->setOptions($this->attributes['options']); $controller->setInputId(issetor($this->attributes['id'], spl_object_hash($this))); $controller->setExtraClass(issetor($this->attributes['class'], '')); return $controller->invoke(); break; case 'embed': $controller = Controller::fromRoute(new Route('form/view.html')); $controller->setId($this->attributes['id']); return $controller->invoke(); break; } // TODO: throw new Exception(); }
public static function dieOnRoute($route) { ob_get_clean(); // We start a mini app here to display the route // Copied from Ajde_Application $route = new Route($route); $document = Document::fromRoute($route); // replace document in Ajde_Application Ajde::app()->setDocument($document); // replace route in Ajde_Application Ajde::app()->setRoute($route); $controller = Controller::fromRoute($route); $actionResult = $controller->invoke(); $document->setBody($actionResult); if (!$document->hasLayout()) { $layout = new Layout(Config::get("layout")); $document->setLayout($layout); } echo $document->render(); die; }
public function output() { $controller = Controller::fromRoute(new Route('_core/crud:' . $this->getOperation())); $controller->setCrudInstance($this); return $controller->invoke(); }
public function run() { // For debugger $this->addTimer('<i>Application</i>'); // Create fresh response $timer = $this->addTimer('Create response'); $response = new Response(); $this->setResponse($response); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterResponseCreated'); // Bootstrap init $timer = $this->addTimer('Run bootstrap queue'); $bootstrap = new Bootstrap(); $bootstrap->run(); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterBootstrap'); // Get request $timer = $this->addTimer('Read in global request'); $request = Request::fromGlobal(); $this->setRequest($request); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterRequestCreated'); // Get route $timer = $this->addTimer('Initialize route'); $route = $request->initRoute(); $this->setRoute($route); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterRouteInitialized'); // Load document $timer = $this->addTimer('Create document'); $document = Document::fromRoute($route); $this->setDocument($document); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterDocumentCreated'); // Load controller $timer = $this->addTimer('Load controller'); $controller = Controller::fromRoute($route); $this->setController($controller); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterControllerCreated'); // Invoke controller action $timer = $this->addTimer('Invoke controller'); $actionResult = $controller->invoke(); $document->setBody($actionResult); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterControllerInvoked'); // Get document contents $timer = $this->addTimer('Render document'); $contents = $document->render(); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterDocumentRendered'); // Let the cache handle the contents and have it saved to the response $timer = $this->addTimer('Save to response'); $cache = Cache::getInstance(); $cache->setContents($contents); $cache->saveResponse(); $this->endTimer($timer); Dispatcher::trigger($this, 'onAfterResponseCreated'); // Output the buffer $response->send(); Dispatcher::trigger($this, 'onAfterResponseSent'); }