Example #1
0
 public function action_index($category = false)
 {
     $this->layout->scripts = array('sourcemap-core');
     $this->layout->page_title = 'Browsing supply chains';
     $cats = Sourcemap_Taxonomy::arr();
     $nms = array();
     foreach ($cats as $i => $cat) {
         $nms[Sourcemap_Taxonomy::slugify($cat->name)] = $cat;
     }
     $this->template->taxonomy = Sourcemap_Taxonomy::load_tree();
     $defaults = array('q' => false, 'p' => 1, 'l' => 20);
     $params = $_GET;
     if (strtolower(Request::$method) == 'post') {
         $params = $_POST;
     }
     $params = array_merge($defaults, $params);
     $params['recent'] = 'yes';
     $params['l'] = 20;
     if ($category && isset($nms[$category])) {
         $slug = $category;
         $category = $nms[$category];
         $this->template->category = $category;
         $params['c'] = $category->name;
         $this->layout->page_title .= ' - ' . $category->title;
     } elseif ($category) {
         Message::instance()->set('"' . $category . '" is not a valid category slug.');
         return $this->request->redirect('browse');
     } else {
         $this->template->category = false;
     }
     $r = Sourcemap_Search::find($params);
     $p = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'p'), 'total_items' => $r->hits_tot, 'items_per_page' => $r->limit, 'view' => 'pagination/basic'));
     $this->template->primary = $r;
     $this->template->pager = $p;
     $params['l'] = 1;
     $this->template->favorited = Sourcemap_Search_Simple::find($params + array('favorited' => 'yes'));
     $this->template->discussed = Sourcemap_Search_Simple::find($params + array('comments' => 'yes'));
     $this->template->interesting = Sourcemap_Search_Simple::find($params + array('favorited' => 'yes', 'comments' => 'yes'));
     $this->template->recent = Sourcemap_Search_Simple::find($params + array('recent' => 'yes'));
 }
Example #2
0
<?php

/* Copyright (C) Sourcemap 2011
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License along with this
 * program. If not, see <http://www.gnu.org/licenses/>.*/
// category options
$taxonomy = Sourcemap_Taxonomy::load_tree();
$cat_opts = array();
$cat_opts[] = array(0, 'None');
$valid_cats = array(0);
$flat_cats = Sourcemap_Taxonomy::flatten();
$_p = array();
foreach ($flat_cats as $i => $cat) {
    list($id, $nm, $title, $depth) = $cat;
    if ($depth < count($_p)) {
        while (count($_p) > $depth) {
            array_pop($_p);
        }
    }
    $_p[] = $title;
    $valid_cats[] = $id;
    if ($id) {
        $cat_opts[] = array($id, join(' / ', array_slice($_p, 1)));
Example #3
0
 public function action_index($supplychain_id = false)
 {
     if (!$supplychain_id) {
         $this->request->redirect('home');
     }
     if (!is_numeric($supplychain_id)) {
         $supplychain_id = $this->_match_alias($supplychain_id);
     }
     $supplychain = ORM::factory('supplychain', $supplychain_id);
     if ($supplychain->loaded()) {
         $current_user_id = Auth::instance()->logged_in() ? (int) Auth::instance()->get_user()->id : 0;
         $owner_id = (int) $supplychain->user_id;
         if ($current_user_id && $supplychain->user_can($current_user_id, Sourcemap::WRITE)) {
             $supplychain = $supplychain->kitchen_sink($supplychain->id);
             // Load form template
             $form = Sourcemap_Form::load('/edit');
             $form->action('edit/' . $supplychain->id)->method('post');
             // Populate fields
             $form->field('title')->add_class('required');
             if (isset($supplychain->attributes->title)) {
                 $form->field('title')->value($supplychain->attributes->title);
             }
             if (isset($supplychain->attributes->description)) {
                 $form->field('description')->value($supplychain->attributes->description);
             }
             $form->field('tags')->add_class('tags');
             if (isset($supplychain->attributes->tags)) {
                 $form->field('tags')->value($supplychain->attributes->tags);
             }
             // fetch the taxonomy tree and use first level
             $taxonomy = Sourcemap_Taxonomy::load_tree();
             $form->field('category')->value($supplychain->category);
             $form->field('publish')->value($supplychain->other_perms & Sourcemap::READ);
             if (strtolower(Request::$method) === 'post') {
                 if ($form->validate($_POST)) {
                     $title = $form->get_field('title')->value();
                     $description = $form->get_field('description')->value();
                     $tags = Sourcemap_Tags::join(Sourcemap_Tags::parse($form->get_field('tags')->value()));
                     $category = $form->get_field('category')->value();
                     if ($category) {
                         $supplychain->category = $category;
                     } else {
                         $category = null;
                     }
                     $public = isset($_POST['publish']) ? Sourcemap::READ : 0;
                     $supplychain->attributes->title = $title;
                     $supplychain->attributes->description = $description;
                     $supplychain->attributes->tags = $tags;
                     if ($public) {
                         $supplychain->other_perms |= $public;
                     } else {
                         $supplychain->other_perms &= ~Sourcemap::READ;
                     }
                     try {
                         ORM::factory('supplychain')->save_raw_supplychain($supplychain, $supplychain->id);
                         Message::instance()->set('Map updated.', Message::SUCCESS);
                         return $this->request->redirect('view/' . $supplychain->id);
                     } catch (Exception $e) {
                         $this->request->status = 500;
                         Message::instance()->set('Couldn\\t update your supplychain. Please contact support.');
                     }
                 } else {
                     Message::instance()->set('Please correct the errors below.');
                 }
             }
             $this->template->supplychain = $supplychain;
             $this->template->form = $form;
         } else {
             Message::instance()->set('You\'re not allowed to edit that map.');
             $this->request->redirect('home');
         }
     } else {
         Message::instance()->set('That map does not exist.');
         $this->request->redirect('home');
     }
 }
Example #4
0
 public function action_index()
 {
     $this->template->tree = Sourcemap_Taxonomy::load_tree(null);
 }