public static function findOrAdd($name, $lang) { $id = self::where('name', $name)->also('lang', $lang)->get(1); if (!$id || sizeof($id) == 0) { $new = new ForumCategorys(); $new->name = $name; $new->lang = $lang; $new->saveGetId(); $id = self::where('name', $name)->also('lang', $lang)->get(1); } return $id; }
public function add($id) { isset($this->params[0]) ? $id = $this->params[0] : ($id = false); $scope = array('intro-title' => 'intro title', 'intro-text' => 'intro-text'); $navbar_stuff = $this->navbar_stuff(); $scope['navbar-stuff'] = $navbar_stuff['stuff']; $scope['navbar-links'] = $navbar_stuff['links']; $scope['categories'] = ForumCategorys::where('lang', 'pt')->select('name')->as_array()->get(); //$topics = new ForumTopics(); if ($id !== false) { $topic = ForumTopics::find($id)[0]; $scope['topic']['id'] = $topic->id; $scope['topic']['name'] = $topic->name; $scope['topic']['description'] = $topic->description; $sql = 'Select makefitreal.mfr_forum_categorys.name From makefitreal.mfr_forum_topic_categorys Inner Join makefitreal.mfr_forum_categorys On makefitreal.mfr_forum_topic_categorys.category_id = makefitreal.mfr_forum_categorys.id WHERE makefitreal.mfr_forum_topic_categorys.topic_id = ?'; $stmt = \Mariana\Framework\Database::getConnection()->prepare($sql); $stmt->bindParam(1, $topic->id); $stmt->execute(); $scope['topic']['categorys'] = $stmt->fetchAll(PDO::FETCH_ASSOC); } return View::render('forum/add/index.php', $scope); }