public function save()
 {
     $req = $this->app->request();
     if ($req->isPost()) {
         $v = $this->validator($this->post());
         $v->rule('required', array('title', 'idea'));
         if ($v->validate()) {
             $p = $this->post();
             $idea = new Idea();
             $idea->title = $p['title'];
             $idea->content = $p['idea'];
             $idea->user_id = $this->user->id;
             $idea->ip_address = $req->getIp();
             $idea->display = DISPLAY_OPTION;
             $idea->save();
             $id = $idea->id;
             if ($id) {
                 $this->successFlash(sprintf('You have successfully saved %s', $id));
                 $this->redirect('home');
             }
             $this->app->flashNow('error', 'Your idea was not saved.');
         }
         $this->app->flash('formError', $this->errorOutput($v->errors(), true));
         $this->redirect('home');
     }
     $this->render('ideas/idea');
 }
Exemplo n.º 2
0
 /**
  *
  * @access public
  * @static
  * @return Idea
  */
 public static function Create($title, $desc, $user)
 {
     $obj = new Idea();
     $obj->idea_title = Database::SafeData(Support::SafeTags($title));
     $obj->user_id = $user->user_id;
     $obj->SetDesc($desc);
     $obj->idea_date = time();
     $obj->idea_rate = 0;
     return $obj;
 }
Exemplo n.º 3
0
 public static function findOrCreate($description)
 {
     $qb = Idea::query();
     $idea = $qb->where('description', '=', $description)->first();
     if (!$idea) {
         $idea = new Idea();
         $idea->description = $description;
         $idea->save();
     }
     return $idea;
 }
Exemplo n.º 4
0
 public function indexAction()
 {
     $page = new Page('home:withNavbar');
     $page->visitor = new Visitor();
     $page->query = Request::get('q');
     $page->ideas = Idea::search(Request::get('q'));
     return new Response($page);
 }
 /**
  * @param Idea $idea
  * @return Idea|null
  */
 public function ideaRelatedTo(Idea $idea)
 {
     if ($this->idea1_id == $idea->id) {
         return Idea::find($this->idea2_id);
     } else {
         if ($this->idea2_id == $idea->id) {
             return Idea::find($this->idea1_id);
         } else {
             return null;
         }
     }
 }
Exemplo n.º 6
0
 public function post($identity)
 {
     if (\Request::segment($identity) == 'likes') {
         ### POST /ideas/<guid>/likes
         $idea = new \Idea($identity);
         if (!$idea->likers->exists($this->visitor->username)) {
             $idea->likers->add($this->visitor->username);
             $idea->save();
         }
         return new \ApiResponse($idea->likers->count());
     }
     ### POST /ideas/
     if (!\Request::get('summary')) {
         return new \ApiMissParameterResponse();
     }
     $idea = new \Idea(\Request::get('guid'));
     $idea->creator = $this->visitor->username;
     $idea->summary = \Request::get('summary');
     $idea->tags->add(array_filter(explode(' ', \Request::get('tags'))));
     $idea->save();
     return new \ApiResponse($idea->guid);
 }
Exemplo n.º 7
0
 /**
  *  function to not repeating same code in every method
  *  $query   sql query
  *  $message  message throwed by exception
  *  @access private
  *  @static
  *  @return Ideas|false
  */
 private static function GetCollectionData($query, $message = "error while getting ideas")
 {
     if (empty($query)) {
         return false;
     }
     $obj = new Ideas();
     try {
         $data = Database::Query($query);
         if (empty($data)) {
             throw new IdeasException($message);
         }
         foreach ($data as $row) {
             $obj->collection[] = Idea::GetById($row["idea_id"]);
         }
     } catch (Exception $e) {
         Debug::Log($e, WARNING);
         return false;
     }
     return $obj->collection;
 }
Exemplo n.º 8
0
             header("Location:" . PREFIX . "/idea?" . $idea->idea_id);
             exit;
         } else {
             Viewer::AddData("idea_title", $_POST["idea_title"]);
             Viewer::UseTemplate("new_idea.tpl");
             Viewer::AddData("title", I18n::L("Title New Idea"));
             Viewer::AddData("error_message", $error_message);
         }
     } else {
         Viewer::Restricted();
     }
     $action = "new_idea";
 }
 // Default view
 if (!empty($id)) {
     if ($idea = Idea::GetById($id)) {
         Viewer::AddData("comments", Comments::GetByIdea($idea));
         Viewer::AddData("idea", $idea);
         Viewer::AddData("title", $idea->idea_title);
         if (isset($_GET["rate_plus"])) {
             $rated = 3;
         } elseif (isset($_GET["rate_minus"])) {
             $rated = 2;
         } else {
             $rated = 1;
         }
         if (User::Logged()) {
             $rate = Rate::Find($idea, User::$current);
             if (!empty($rate)) {
                 $rated = 4;
             }
Exemplo n.º 9
0
if ($params = matchUriTemplate('/')) {
    if ($method == "GET") {
        $ideas = Idea::search();
        json_exit($ideas, SCHEMA_ROOT . '/idea#/definitions/array');
    } else {
        if ($method == "POST") {
            $idea = Idea::create($jsonData);
            $idea->save();
            link_header(JSON_ROOT . '/ideas/', 'invalidates');
            json_exit($idea->id);
        }
    }
    json_error(405, "Invalid method: {$method}", $method);
} else {
    if ($params = matchUriTemplate('/{id}')) {
        $idea = Idea::open($params->id);
        if ($method == "GET") {
            json_exit($idea, SCHEMA_ROOT . '/idea');
        } else {
            if ($method == "PUT") {
                $idea->put($jsonData);
                link_header(JSON_ROOT . '/ideas/', 'invalidates');
                json_exit($idea, SCHEMA_ROOT . '/idea');
            } else {
                if ($method == "DELETE") {
                    $idea->delete();
                    link_header(JSON_ROOT . '/ideas/', 'invalidates');
                    json_exit("deleted");
                }
            }
        }
Exemplo n.º 10
0
 public function find(Route $route)
 {
     $this->mCategory = Idea::find($route->getParameter('mCategory'));
 }
Exemplo n.º 11
0
<?php

/**
 * Created by PhpStorm.
 * User: DiD
 * Date: 02/10/2015
 * Time: 14:15
 */
include 'common.php';
if (isset($_POST['idea-id'], $_POST['name'], $_POST['description'])) {
    if (is_numeric($_POST['idea-id'])) {
        $idea = Database::getOne('ideas', array('id' => $_POST['idea-id']));
    } else {
        $idea = new Idea();
    }
    if ($idea) {
        $idea->name = $_POST['name'];
        $idea->description = $_POST['description'];
        $idea->save();
        $possibilities = Database::getAll('possibilities', array('idea' => $_POST['idea-id']));
        foreach ($possibilities as $possibility) {
            if (isset($_POST['possibility_' . $possibility->id]) && isset($_POST['possibility_code_' . $possibility->id]) && !empty($_POST['possibility_' . $possibility->id])) {
                $possibility->name = htmlspecialchars($_POST['possibility_' . $possibility->id]);
                $possibility->code = htmlspecialchars($_POST['possibility_code_' . $possibility->id]);
                $possibility->save();
            } else {
                $possibility->delete();
            }
        }
        foreach ($_POST['possibility_new'] as $index => $possibilityName) {
            if (!empty($possibilityName)) {