Example #1
0
 public function rawTopicsForUser($user_id)
 {
     $user = User::find($user_id);
     $query = DB::table('forums_topics')->select(DB::raw("forums_topics.id, forum_id, title, first_post, is_complete, is_sticky, views, forums_topics.created_at, forums_topics.updated_at, fpost.topic_id"))->where('forum_id', $this->id)->leftJoin('forums_posts as fpost', 'forums_topics.first_post', '=', 'fpost.id');
     if ($this->time_limited && !$user->isStoryteller()) {
         $char = $user->activeCharacter();
         if ($char) {
             $timestamp = 0;
             $date_added = ForumCharacterPermission::where(['forum_id' => $this->id, 'character_id' => $char->id]);
             if ($date_added->exists()) {
                 $timestamp = $date_added->first()->created_at;
             } else {
                 if (!$this->is_private) {
                     //Get version 1 creation date.
                     $timestamp = CharacterVersion::where(['character_id' => $char->id, 'version' => 1])->first()->created_at;
                 }
             }
             $query = $query->where(function ($q) use($timestamp) {
                 $q->where('fpost.created_at', '>', $timestamp);
                 $q->orWhere('forums_topics.is_sticky', true);
             });
         } else {
             $query = $query->where('fpost.id', '<', 0);
         }
     }
     if ($this->player_specific_threads) {
         if (!$user->isStoryteller()) {
             $query = $query->leftJoin("forums_topics_added_users as added", function ($join) use($user_id) {
                 $join->on("added.topic_id", "=", "forums_topics.id")->where('added.user_id', '=', $user_id);
             })->where(function ($q) use($user_id) {
                 $q->where('fpost.posted_by', $user_id)->orWhereNotNull('added.user_id');
             });
         }
     }
     return $query;
 }
Example #2
0
 public function save()
 {
     $user = Auth::user();
     $character = Character::find(Input::get('characterId'));
     if (!$character) {
         $character = new Character();
         $characterIsNew = true;
     }
     if (!isset($character->user_id)) {
         $character->user_id = $user->id;
     }
     $character->name = Input::get("sheet.name");
     $character->save();
     CharacterVersion::where('character_id', $character->id)->where('version', '>', $character->approved_version)->delete();
     $version = CharacterVersion::createNewVersion($character, Input::has("comment") ? Input::get("comment") : null);
     if ($version->isNewCharacter()) {
         $version->setHasDroppedMorality(Input::get("sheet.hasDroppedMorality") == "true");
     }
     try {
         $version->setEditingUser($user);
         if (Input::get("sheet.sect.selected")) {
             $version->setSect(RulebookSect::find(Input::get("sheet.sect.selected")), RulebookSect::find(Input::get("sheet.sect.displaying")));
         }
         if (Input::get("sheet.clan.selected")) {
             $version->setClan(RulebookClan::find(Input::get("sheet.clan.selected")), RulebookClan::find(Input::get("sheet.clan.displaying")));
         }
         $version->setClanOptions(Input::get("sheet.clanOptions.0"), Input::get("sheet.clanOptions.1"), Input::get("sheet.clanOptions.2"));
         if (Input::get("sheet.nature")) {
             $version->setNature(RulebookNature::find(Input::get("sheet.nature")));
         }
         if (Input::get("sheet.willpower")) {
             $version->setWillpower(Input::get("sheet.willpower.dots"), Input::get("sheet.willpower.traits"));
         }
         if (Input::get("sheet.attributes")) {
             $version->setAttributes(Input::get("sheet.attributes.physicals"), Input::get("sheet.attributes.mentals"), Input::get("sheet.attributes.socials"));
         }
         foreach ((array) Input::get("sheet.abilities") as $ability) {
             if (array_key_exists("specialization", $ability)) {
                 $version->addAbilityWithSpecialization(RulebookAbility::find($ability["id"]), $ability["count"], $ability["specialization"], $ability["name"]);
             } else {
                 $version->addAbility(RulebookAbility::find($ability["id"]), $ability["count"], $ability["name"]);
             }
         }
         foreach ((array) Input::get("sheet.disciplines") as $discipline) {
             $version->updateDiscipline(RulebookDiscipline::find($discipline["id"]), $discipline["count"], array_key_exists("path", $discipline) ? $discipline["path"] : 0);
         }
         foreach ((array) Input::get("newRituals") as $newRitualData) {
             $version->addRitualToBook($newRitualData["name"], $newRitualData["description"], $newRitualData["type"]);
         }
         foreach ((array) Input::get("sheet.rituals") as $ritualId) {
             $version->addRitual($ritualId);
         }
         if (Input::get("sheet.path")) {
             $version->updatePath(RulebookPath::find(Input::get("sheet.path")), Input::get("sheet.virtues.0"), Input::get("sheet.virtues.1"), Input::get("sheet.virtues.2"), Input::get("sheet.virtues.3"));
         }
         foreach ((array) Input::get("sheet.merits") as $meritData) {
             $version->addMerit(RulebookMerit::find($meritData["id"]), array_key_exists("description", $meritData) ? $meritData["description"] : null);
         }
         foreach ((array) Input::get("sheet.flaws") as $flawData) {
             $version->addFlaw(RulebookFlaw::find($flawData["id"]), array_key_exists("description", $flawData) ? $flawData["description"] : null);
         }
         foreach ((array) Input::get("sheet.derangements") as $derangementData) {
             $version->addDerangement(RulebookDerangement::find($derangementData["id"]), array_key_exists("description", $derangementData) ? $derangementData["description"] : null);
         }
         foreach ((array) Input::get("sheet.backgrounds") as $backgroundData) {
             $version->addBackground(RulebookBackground::find($backgroundData["id"]), $backgroundData["count"], array_key_exists("description", $backgroundData) ? $backgroundData["description"] : null);
         }
         foreach ((array) Input::get("sheet.elderPowers") as $elderData) {
             $version->addElderPower($elderData);
         }
         foreach ((array) Input::get("sheet.comboDisciplines") as $comboData) {
             $version->addComboDiscipline($comboData);
         }
         $version->clearUntouchedRecords();
     } catch (Exception $e) {
         throw $e;
     }
     return $version;
 }
Example #3
0
 public function revertChanges($version)
 {
     if (Auth::user()->isStoryteller()) {
         $this->approved_version = $version;
         $this->in_review = false;
         $this->save();
     }
     CharacterVersion::where('character_id', $this->id)->where('version', '>', $version)->delete();
 }