Inheritance: extends Kohana_Kostache
Exemple #1
1
 public function action_index()
 {
     $this->view = new View_Search();
     if ($this->request->query('query') !== NULL) {
         $query = $this->request->query('query');
         $queryString = new \Elastica\Query\QueryString();
         $queryString->setDefaultOperator('AND');
         $queryString->setQuery($query);
         $elasticaQuery = new \Elastica\Query();
         $elasticaQuery->setQuery($queryString);
         $resultSet = ElasticSearch::instance()->search($elasticaQuery);
         $results = $resultSet->getResults();
         /** @var Kostache $renderer */
         $renderer = Kostache::factory();
         $out = array();
         foreach ($results as $result) {
             // Attempt to create the avatar instance.
             try {
                 $refl = new ReflectionClass('View_Search_' . ucfirst($result->getType()));
                 $view = $refl->newInstance();
                 $view->data = $result->getData();
                 $out[] = $renderer->render($view);
             } catch (ReflectionException $ex) {
                 Kohana::$log->add(LOG::ERROR, 'No search view class found for search type ":type".', array(':type' => $result->getType()));
             }
         }
         $this->view->query = $query;
         $this->view->results = $out;
     }
 }
Exemple #2
0
 public function before()
 {
     parent::before();
     // Save the old action so it can be brought back on after
     $this->_action = $this->request->action;
     // Set the current action
     $current_action = $this->request->action;
     $id = $this->request->param('id', NULL);
     // Let's guess the action based on the params
     if (!in_array($this->request->action, array('edit', 'add', 'delete')) and (!is_null($id) or !empty($id))) {
         $current_action = 'read';
     }
     if (!method_exists($this, 'action_' . $this->request->action)) {
         $model = Jelly::select(Inflector::singular($this->request->controller));
         foreach ($model->get_state() as $key => $value) {
             $param = $this->request->param($key, NULL);
             if (!is_null($param)) {
                 $model->set_state($key, $param);
             }
         }
         $this->request->response = Kostache::factory($this->request->controller . '/' . $current_action)->set_model($model);
         // Since the magic has been executed, just execute an empty action
         $this->request->action = 'default';
     }
 }
Exemple #3
0
 public function render()
 {
     $view = new View_Tabs();
     $view->tabs = $this->tabs;
     $renderer = Kostache::factory();
     return $renderer->render($view);
 }
Exemple #4
0
 public final function set_global($key, $value = NULL)
 {
     if (is_array($key) and Arr::is_assoc($key)) {
         Kostache::$globals = Arr::merge(Kostache::$globals, $key);
     } else {
         Kostache::$globals[$key] = $value;
     }
 }
Exemple #5
0
 /**
  * Get the Settings page html by appending the content views.
  *
  * @return string
  */
 public function view()
 {
     $renderer = Kostache::factory();
     $html = '';
     foreach ($this->views as $view) {
         $html .= $renderer->render($view);
     }
     return $html;
 }
Exemple #6
0
 public function render()
 {
     if (!$this->render_layout) {
         return parent::render();
     }
     $partials = $this->_partials;
     $partials[Kostache_Layout::CONTENT_PARTIAL] = $this->_template;
     $template = $this->_load($this->_layout);
     return $this->_stash($template, $this, $partials)->render();
 }
Exemple #7
0
 /**
  * Renders the body template into the layout
  */
 public function render($template = null, $view = null, $partials = null)
 {
     // Override the template location to match kohana's conventions
     if (!$this->_template) {
         $foo = explode('_', get_class($this));
         array_shift($foo);
         $this->_template = strtolower(implode('/', $foo));
     }
     $this->_partials += array('body' => $this->_template);
     // Make the layout view the child class's template
     $this->_template = $this->_layout;
     return parent::render($template, $view, $partials);
 }
Exemple #8
0
 /**
  * Check the database config, and allow the user to generate a database.php config.
  */
 public function action_database()
 {
     $this->_view = new View_Install_Database();
     $this->_view->is_writable = is_writable($this->_full_config_path());
     $config = Kohana::$config->load('database.default');
     // Overwrite the config object with the post variables.
     if ($this->request->method() == HTTP_Request::POST) {
         $config['connection']['hostname'] = $this->request->post('hostname');
         $config['connection']['database'] = $this->request->post('database');
         $config['connection']['username'] = $this->request->post('username');
         $config['connection']['password'] = $this->request->post('password');
     }
     try {
         // Attempt to connect to the database with our new config.
         $db = Database::instance('install', $config);
         $db->connect();
         // The information is correct, so just continue.
         if ($this->request->method() !== HTTP_Request::POST) {
             $this->redirect('?p=import');
         } else {
             $view = new View_Install_Download();
             $view->config = $config['connection'];
             $renderer = Kostache::factory();
             // Write to the file.
             if ($this->_view->is_writable) {
                 file_put_contents($this->_full_config_path(), $renderer->render($view));
                 $this->redirect('?p=import');
             } else {
                 // Fallback to downloading the file.
                 $this->response->body($renderer->render($view));
                 // Send the headers for downloading.
                 $this->response->send_file(TRUE, 'database.php');
             }
         }
     } catch (Database_Exception $e) {
         $this->_view->database_error = $e;
     }
 }
Exemple #9
0
 public function render()
 {
     $renderer = Kostache::factory();
     return $renderer->render($this->view);
 }
Exemple #10
0
 public function render()
 {
     $this->_parse_data();
     return parent::render();
 }
Exemple #11
0
 /**
  * Renders the pagination links.
  *
  * @param View $view View object
  * @return string Pagination output (HTML)
  */
 public function render($view = NULL)
 {
     // Automatically hide pagination whenever it is superfluous
     if ($this->config['auto_hide'] === TRUE and $this->pages() <= 1) {
         return '';
     }
     if ($view === NULL) {
         // Use the view class from config
         $refl = new ReflectionClass('View_' . $this->config['view']);
         $view = $refl->newInstanceArgs();
     }
     $view->paginate = $this;
     $renderer = Kostache::factory();
     return $renderer->render($view);
 }
Exemple #12
0
 /**
  * Get the edit view.
  *
  * @return string Html of the view
  */
 public function edit_view()
 {
     $renderer = Kostache::factory();
     return $renderer->render($this->_edit_view());
 }
Exemple #13
0
 /**
  * Returns HTML to render for the payment information.
  * 
  * To add HTML for new payment methods (paypal), modify this method.
  *
  * @return string
  */
 public function payment_form()
 {
     return Kostache::factory('authorize')->set('credit_card', $this->credit_card)->render();
 }