Exemple #1
0
 public function index($current = 'node')
 {
     // si llega una pregunta  ?q=70
     if (isset($_GET['q'])) {
         $current = null;
         $show = $_GET['q'];
     } else {
         $show = null;
     }
     $page = Page::get('faq');
     $faqs = array();
     $sections = Model\Faq::sections();
     $colors = Model\Faq::colors();
     foreach ($sections as $id => $name) {
         $qs = Model\Faq::getAll($id);
         if (empty($qs)) {
             if ($id == $current && $current != 'node') {
                 throw new \Goteo\Core\Redirection('/faq');
             }
             unset($sections[$id]);
             continue;
         }
         $faqs[$id] = $qs;
         foreach ($faqs[$id] as &$question) {
             $question->description = nl2br(str_replace(array('%SITE_URL%'), array(SITE_URL), $question->description));
             if (isset($show) && $show == $question->id) {
                 $current = $id;
             }
         }
     }
     return new View('view/faq.html.php', array('faqs' => $faqs, 'current' => $current, 'sections' => $sections, 'colors' => $colors, 'show' => $show));
 }
Exemple #2
0
 public static function process($action = 'list', $id = null, $filters = array())
 {
     $sections = Model\Faq::sections();
     if (!isset($sections[$filters['section']])) {
         unset($filters['section']);
     }
     $errors = array();
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         // instancia
         $faq = new Model\Faq(array('id' => $_POST['id'], 'node' => \GOTEO_NODE, 'section' => $_POST['section'], 'title' => $_POST['title'], 'description' => $_POST['description'], 'order' => $_POST['order'], 'move' => $_POST['move']));
         if ($faq->save($errors)) {
             switch ($_POST['action']) {
                 case 'add':
                     Message::Info('Pregunta añadida correctamente');
                     break;
                 case 'edit':
                     Message::Info('Pregunta editado correctamente');
                     break;
             }
         } else {
             Message::Error(implode('<br />', $errors));
             return new View('view/admin/index.html.php', array('folder' => 'faq', 'file' => 'edit', 'action' => $_POST['action'], 'faq' => $faq, 'filter' => $filter, 'sections' => $sections));
         }
     }
     switch ($action) {
         case 'up':
             Model\Faq::up($id);
             throw new Redirection('/admin/faq');
             break;
         case 'down':
             Model\Faq::down($id);
             throw new Redirection('/admin/faq');
             break;
         case 'add':
             $next = Model\Faq::next($filters['section']);
             return new View('view/admin/index.html.php', array('folder' => 'faq', 'file' => 'edit', 'action' => 'add', 'faq' => (object) array('section' => $filters['section'], 'order' => $next, 'cuantos' => $next), 'sections' => $sections));
             break;
         case 'edit':
             $faq = Model\Faq::get($id);
             $cuantos = Model\Faq::next($faq->section);
             $faq->cuantos = $cuantos - 1;
             return new View('view/admin/index.html.php', array('folder' => 'faq', 'file' => 'edit', 'action' => 'edit', 'faq' => $faq, 'sections' => $sections));
             break;
         case 'remove':
             Model\Faq::delete($id);
             break;
     }
     $faqs = Model\Faq::getAll($filters['section']);
     return new View('view/admin/index.html.php', array('folder' => 'faq', 'file' => 'list', 'faqs' => $faqs, 'sections' => $sections, 'filters' => $filters));
 }