Exemplo n.º 1
0
 /**
  * Get count of templates
  *
  * @return int
  */
 public function getCount()
 {
     return Table\Templates::findAll()->count();
 }
Exemplo n.º 2
0
 /**
  * Edit action method
  *
  * @param  int $id
  * @return void
  */
 public function edit($id)
 {
     $template = new Model\Template();
     $template->getById($id);
     if (!isset($template->id)) {
         $this->redirect(BASE_PATH . APP_URI . '/templates');
     }
     $this->prepareView('templates/edit.phtml');
     $this->view->title = 'Templates';
     $this->view->template_name = $template->name;
     $fields = $this->application->config()['forms']['Phire\\Templates\\Form\\Template'];
     $templates = Table\Templates::findAll();
     foreach ($templates->rows() as $tmpl) {
         if ($tmpl->id != $id) {
             $fields[0]['template_parent_id']['value'][$tmpl->id] = $tmpl->name;
         }
     }
     if (null !== $template->history) {
         $history = json_decode($template->history, true);
         //$fields[0]['template_history'] = [
         $tmplHistory = ['type' => 'select', 'label' => 'Select Revision', 'value' => ['0' => '(Current)'], 'attributes' => ['onchange' => 'phire.changeTemplateHistory(this);']];
         krsort($history);
         foreach ($history as $timestamp => $value) {
             $tmplHistory['value'][$timestamp] = date('M j, Y H:i:s', $timestamp);
         }
         $fields[0] = array_slice($fields[0], 0, 3, true) + ['template_history' => $tmplHistory] + array_slice($fields[0], 3, count($fields[0]) - 3, true);
     }
     $fields[1]['name']['attributes']['onkeyup'] = 'phire.changeTitle(this.value);';
     $this->view->form = new Form\Template($fields);
     $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($template->toArray());
     if ($this->request->isPost()) {
         $this->view->form->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
             $template = new Model\Template();
             $template->update($this->view->form->getFields(), $this->application->module('phire-templates')->config()['history']);
             $this->view->id = $template->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect(BASE_PATH . APP_URI . '/templates/edit/' . $template->id);
         }
     }
     $this->send();
 }