Наследование: extends yii\db\ActiveRecord
Пример #1
0
 public function create($firstName = '', $lastName = '', $email = '', $password = '')
 {
     $account = new Account();
     $account->ip = Request::getClientIp();
     $account->account_key = str_random(RANDOM_KEY_LENGTH);
     // Track referal code
     if ($referralCode = Session::get(SESSION_REFERRAL_CODE)) {
         if ($user = User::whereReferralCode($referralCode)->first()) {
             $account->referral_user_id = $user->id;
         }
     }
     if ($locale = Session::get(SESSION_LOCALE)) {
         if ($language = Language::whereLocale($locale)->first()) {
             $account->language_id = $language->id;
         }
     }
     $account->save();
     $user = new User();
     if (!$firstName && !$lastName && !$email && !$password) {
         $user->password = str_random(RANDOM_KEY_LENGTH);
         $user->username = str_random(RANDOM_KEY_LENGTH);
     } else {
         $user->first_name = $firstName;
         $user->last_name = $lastName;
         $user->email = $user->username = $email;
         $user->password = bcrypt($password);
     }
     $user->confirmed = !Utils::isNinja();
     $user->registered = !Utils::isNinja() && $user->email;
     if (!$user->confirmed) {
         $user->confirmation_code = str_random(RANDOM_KEY_LENGTH);
     }
     $account->users()->save($user);
     return $account;
 }
 public function edit($id)
 {
     $param['pageNo'] = 2;
     $result = LanguageModel::find($id);
     $param['language'] = $result;
     return View::make('languages.edit')->with($param);
 }
Пример #3
0
 private function setLanguage()
 {
     $request = Yii::$app->request;
     $cookie = $request->cookies->get('language');
     if ($cookie) {
         $lang = Language::findOne(['lang' => $cookie->value]);
         if ($lang) {
             Yii::$app->language = $lang->lang;
             return;
         }
     }
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $accepts = $request->parseAcceptHeader($_SERVER['HTTP_ACCEPT_LANGUAGE']);
         foreach ($accepts as $lang => $options) {
             //FIXME: DBと整合をとってちゃんとやる
             switch (strtolower($lang)) {
                 case 'ja':
                 case 'ja-jp':
                     Yii::$app->language = 'ja-JP';
                     return;
                 case 'en':
                 case 'en-US':
                     Yii::$app->language = 'en-US';
                     return;
             }
         }
     }
     Yii::$app->language = 'en-US';
 }
Пример #4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     try {
         //DELETE TABLES
         DB::table('osu_genres')->delete();
         DB::table('osu_languages')->delete();
         //COUNTS
         if (!DB::table('osu_counts')->where('name', 'pp_rank_column')->get()) {
             DB::table('osu_counts')->insert([['name' => 'pp_rank_column', 'count' => 90], ['name' => 'usercount', 'count' => 500000]]);
         }
         //END COUNTS
         //GENRES
         DB::table('osu_genres')->insert([['genre_id' => 99, 'name' => 'Any'], ['genre_id' => 1, 'name' => 'Unspecified'], ['genre_id' => 2, 'name' => 'Video Game'], ['genre_id' => 3, 'name' => 'Anime'], ['genre_id' => 4, 'name' => 'Rock'], ['genre_id' => 5, 'name' => 'Pop'], ['genre_id' => 6, 'name' => 'Other'], ['genre_id' => 7, 'name' => 'Novelty'], ['genre_id' => 9, 'name' => 'Hip Hop'], ['genre_id' => 10, 'name' => 'Electronic']]);
         $any_genre = \App\Models\Genre::find(99);
         $any_genre->genre_id = 0;
         $any_genre->save();
         //  END GENRES
         //LANGUAGES
         DB::table('osu_languages')->insert([['language_id' => 99, 'name' => 'Any', 'display_order' => 0], ['language_id' => 1, 'name' => 'Other', 'display_order' => 11], ['language_id' => 2, 'name' => 'English', 'display_order' => 1], ['language_id' => 3, 'name' => 'Japanese', 'display_order' => 6], ['language_id' => 4, 'name' => 'Chinese', 'display_order' => 2], ['language_id' => 5, 'name' => 'Instrumental', 'display_order' => 10], ['language_id' => 6, 'name' => 'Korean', 'display_order' => 7], ['language_id' => 7, 'name' => 'French', 'display_order' => 3], ['language_id' => 8, 'name' => 'German', 'display_order' => 4], ['language_id' => 9, 'name' => 'Swedish', 'display_order' => 9], ['language_id' => 10, 'name' => 'Spanish', 'display_order' => 8], ['language_id' => 11, 'name' => 'Italian', 'display_order' => 5]]);
         $any_language = \App\Models\Language::find(99);
         $any_language->language_id = 0;
         $any_language->save();
         //END LANGUAGES
     } catch (\Illuminate\Database\QueryException $e) {
         echo $e->getMessage() . "\r\n";
     } catch (Exception $ex) {
         echo $ex->getMessage() . "\r\n";
     }
 }
Пример #5
0
 public function edit($id)
 {
     $param['pageNo'] = 1;
     $result = DomainModel::find($id);
     $param['domain'] = $result;
     $param['language'] = LanguageModel::all();
     $param['template'] = TemplateModel::all();
     return View::make('domains.edit')->with($param);
 }
 public function getAutoCompleteWordsAjax(Request $request)
 {
     if (!$request->ajax()) {
         return response()->json(['response' => 'reject', 'msg' => 'request Not Allowed', 'searchWord' => $request->searchWord, 'language' => $request->languageName, 'Ajax' => $request->ajax(), 'Request' => $request->method()]);
     }
     $searchWord = $request->searchWord;
     $languageId = Language::where('id', '=', $request->languageId)->value('id');
     $Words = Word::where('language_id', '=', $languageId)->where('word', 'LIKE', $searchWord . '%')->orderBy('word', 'asc')->limit(10)->get();
     return $Words;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $now = date('Y-m-d H:i:s', strtotime('now'));
     $languages = [['name' => 'english', 'description' => 'the Language English', 'created_at' => $now, 'updated_at' => $now], ['name' => 'danish', 'description' => 'the Language Danish, spoken in Denmark', 'created_at' => $now, 'updated_at' => $now], ['name' => 'pashto', 'description' => 'the Language Pashto, spoken in Afghanistan', 'created_at' => $now, 'updated_at' => $now]];
     foreach ($languages as $language) {
         if (\App\Models\Language::where('name', '=', $language['name'])->exists()) {
             echo $language['name'] . " Already exists\n";
         } else {
             \App\Models\Language::create($language);
         }
     }
     //DB::table('words')->truncate();
     //Schema::drop('words');
     $passed = 0;
     $exists = 0;
     //word table - seed from a file
     //        $pashto_json = File::get(storage_path() . "/app/json_data/pashto.json");
     //	$pashto_word = json_decode($pashto_json);
     //
     //        foreach ($pashto_word as $wordObj)
     //        {
     //            if(\App\Models\Word::where('word', '=', $wordObj->s2p[0])->exists())
     //            {
     //                  echo $wordObj->s2p[0] . " Already exists\n";
     //                  $exists++;
     //            }
     //            else
     //            {
     //                 \App\Models\Word::create([
     //                    'language_id' => 3,
     //                    'user_id' => 3,
     //                    'word' => $wordObj->s2p[0],
     //                    'pronounce_audio_path' => '',
     //                    'pronounce_text' => 'pronounce_text missing',
     //                    'definition' => 'Word definition missing',
     //                    'created_at' => $now,
     //                    'updated_at' => $now,
     //                ]);
     //
     //                $passed++;
     //            }
     //        }
     foreach (File(storage_path() . "/app/danskOrde_49389.txt", FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES) as $word) {
         if (App\Models\Word::where(['language_id' => 2, 'word' => $word])->exists()) {
             echo $word . ": Already exists in Danish\n";
             $exists++;
         } else {
             App\Models\Word::create(['language_id' => 2, 'user_id' => 3, 'word' => $word, 'pronounce_audio_path' => '', 'pronounce_text' => 'pronounce_text missing', 'definition' => 'Word definition missing', 'created_at' => $now, 'updated_at' => $now]);
             $passed++;
         }
     }
     echo "\n Words Already Exists: " . $exists;
     echo "\n Words added: " . $passed . "\n";
 }
Пример #8
0
 private function detectLanguageByCookie()
 {
     $cookie = Yii::$app->request->cookies->get('language');
     if (!$cookie) {
         return false;
     }
     if (!($lang = Language::findOne(['lang' => $cookie->value]))) {
         return false;
     }
     return $lang->lang;
 }
Пример #9
0
 public function actionSelect($id, $current_url = '')
 {
     $language = Language::findOne($id);
     Yii::$app->response->cookies->add(new Cookie(['name' => 'language', 'value' => $language->code, 'expire' => (new \Datetime())->modify('+1 year')->getTimestamp()]));
     if ($current_url) {
         $current_url = urldecode($current_url);
     } else {
         $current_url = ['site/index'];
     }
     return $this->redirect($current_url);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Language::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['l_id' => $this->l_id]);
     $query->andFilterWhere(['like', 'short', $this->short])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Пример #11
0
 public function translateToAll($category, $message, $params = [])
 {
     if (self::$langs === null) {
         self::$langs = Language::find()->all();
     }
     $i18n = Yii::$app->i18n;
     $ret = [];
     foreach (self::$langs as $lang) {
         $ret[strtr($lang->lang, '-', '_')] = $i18n->translate($category, $message, $params, $lang->lang);
     }
     return $ret;
 }
Пример #12
0
 public function init()
 {
     parent::init();
     if ($this->currentLanguage === null) {
         $this->currentLanguage = Language::getCurrent();
     }
     if ($this->allowedLanguages === null) {
         $this->allowedLanguages = Language::find()->where('`id` != :id', [':id' => $this->currentLanguage->id])->all();
     }
     $this->cssClass .= ' dropdown dropdown-language';
     $this->options['class'] = trim($this->cssClass);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Language::find();
     $pageSize = Yii::$app->session->get('pageSize', Yii::$app->params['defaultPageSize']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $pageSize]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['l_id' => $this->l_id]);
     $query->andFilterWhere(['like', 'short', $this->short])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'message', $this->message]);
     return $dataProvider;
 }
Пример #14
0
 private function setLanguage()
 {
     $request = Yii::$app->request;
     $cookie = $request->cookies->get('language');
     if ($cookie) {
         $lang = Language::findOne(['lang' => $cookie->value]);
         if ($lang) {
             Yii::$app->language = $lang->lang;
             return;
         }
     }
 }
Пример #15
0
 static function getLangByUrl($url = null)
 {
     if ($url === null) {
         return null;
     } else {
         $language = Language::find()->where('url = :url', [':url' => $url])->one();
         if ($language === null) {
             return null;
         } else {
             return $language;
         }
     }
 }
Пример #16
0
 public function getLangUrl()
 {
     if ($this->_lang_url === null) {
         $this->_lang_url = $this->getUrl();
         $url_list = explode('/', $this->_lang_url);
         $lang_url = isset($url_list[1]) ? $url_list[1] : null;
         Language::setCurrent($lang_url);
         if ($lang_url !== null && $lang_url === Language::getCurrent()->url_key && strpos($this->_lang_url, Language::getCurrent()->url_key) === 1) {
             $this->_lang_url = substr($this->_lang_url, strlen(Language::getCurrent()->url_key) + 1);
         }
     }
     return $this->_lang_url;
 }
Пример #17
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Language::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'default' => $this->default, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'url_key', $this->url_key])->andFilterWhere(['like', 'local', $this->local])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Пример #18
0
 public function run()
 {
     Eloquent::unguard();
     $languages = [['name' => 'English', 'locale' => 'en'], ['name' => 'Italian', 'locale' => 'it'], ['name' => 'German', 'locale' => 'de'], ['name' => 'French', 'locale' => 'fr'], ['name' => 'Brazilian Portuguese', 'locale' => 'pt_BR'], ['name' => 'Dutch', 'locale' => 'nl'], ['name' => 'Spanish', 'locale' => 'es'], ['name' => 'Norwegian', 'locale' => 'nb_NO'], ['name' => 'Danish', 'locale' => 'da'], ['name' => 'Japanese', 'locale' => 'ja'], ['name' => 'Swedish', 'locale' => 'sv'], ['name' => 'Spanish - Spain', 'locale' => 'es_ES'], ['name' => 'French - Canada', 'locale' => 'fr_CA'], ['name' => 'Lithuanian', 'locale' => 'lt'], ['name' => 'Polish', 'locale' => 'pl'], ['name' => 'Czech', 'locale' => 'cs']];
     foreach ($languages as $language) {
         $record = Language::whereLocale($language['locale'])->first();
         if ($record) {
             $record->name = $language['name'];
             $record->save();
         } else {
             Language::create($language);
         }
     }
     Eloquent::reguard();
 }
Пример #19
0
 public function index()
 {
     $fractal = new Manager();
     $languages = Language::listing();
     $genres = Genre::listing();
     $data = new Collection(BeatmapSet::listing(), new BeatmapSetTransformer());
     $beatmaps = $fractal->createData($data)->toArray();
     // temporarily put filters here
     $modes = [['id' => null, 'name' => trans('beatmaps.mode.any')], ['id' => Beatmap::OSU, 'name' => trans('beatmaps.mode.osu')], ['id' => Beatmap::TAIKO, 'name' => trans('beatmaps.mode.taiko')], ['id' => Beatmap::FRUITS, 'name' => trans('beatmaps.mode.fruits')], ['id' => Beatmap::MANIA, 'name' => trans('beatmaps.mode.mania')]];
     $statuses = [['id' => null, 'name' => trans('beatmaps.status.any')], ['id' => 0, 'name' => trans('beatmaps.status.ranked-approved')], ['id' => 1, 'name' => trans('beatmaps.status.approved')], ['id' => 2, 'name' => trans('beatmaps.status.faves')], ['id' => 3, 'name' => trans('beatmaps.status.modreqs')], ['id' => 4, 'name' => trans('beatmaps.status.pending')], ['id' => 5, 'name' => trans('beatmaps.status.graveyard')], ['id' => 6, 'name' => trans('beatmaps.status.my-maps')]];
     $extras = [['id' => 0, 'name' => trans('beatmaps.extra.video')], ['id' => 1, 'name' => trans('beatmaps.extra.storyboard')]];
     $ranks = [['id' => 'XH', 'name' => trans('beatmaps.rank.silver-ss')], ['id' => 'X', 'name' => trans('beatmaps.rank.ss')], ['id' => 'SH', 'name' => trans('beatmaps.rank.silver-s')], ['id' => 'S', 'name' => trans('beatmaps.rank.s')], ['id' => 'A', 'name' => trans('beatmaps.rank.a')], ['id' => 'B', 'name' => trans('beatmaps.rank.b')], ['id' => 'C', 'name' => trans('beatmaps.rank.c')], ['id' => 'D', 'name' => trans('beatmaps.rank.d')]];
     $filters = ['data' => compact('modes', 'statuses', 'genres', 'languages', 'extras', 'ranks')];
     return view('beatmaps.index', compact('filters', 'beatmaps'));
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     if ($language = \App\Models\Language::whereLocale('sv')->first()) {
         $language->delete();
     }
     if ($language = \App\Models\Language::whereLocale('es_ES')->first()) {
         $language->delete();
     }
     if ($language = \App\Models\Language::whereLocale('fr_CA')->first()) {
         $language->delete();
     }
     if ($language = \App\Models\Language::whereLocale('lt')->first()) {
         $language->delete();
     }
 }
Пример #21
0
 public function run()
 {
     Eloquent::unguard();
     // https://github.com/caouecs/Laravel-lang
     // https://www.loc.gov/standards/iso639-2/php/code_list.php
     $languages = [['name' => 'English', 'locale' => 'en'], ['name' => 'Italian', 'locale' => 'it'], ['name' => 'German', 'locale' => 'de'], ['name' => 'French', 'locale' => 'fr'], ['name' => 'Brazilian Portuguese', 'locale' => 'pt_BR'], ['name' => 'Dutch', 'locale' => 'nl'], ['name' => 'Spanish', 'locale' => 'es'], ['name' => 'Norwegian', 'locale' => 'nb_NO'], ['name' => 'Danish', 'locale' => 'da'], ['name' => 'Japanese', 'locale' => 'ja'], ['name' => 'Swedish', 'locale' => 'sv'], ['name' => 'Spanish - Spain', 'locale' => 'es_ES'], ['name' => 'French - Canada', 'locale' => 'fr_CA'], ['name' => 'Lithuanian', 'locale' => 'lt'], ['name' => 'Polish', 'locale' => 'pl'], ['name' => 'Czech', 'locale' => 'cs'], ['name' => 'Croatian', 'locale' => 'hr'], ['name' => 'Albanian', 'locale' => 'sq']];
     foreach ($languages as $language) {
         $record = Language::whereLocale($language['locale'])->first();
         if ($record) {
             $record->name = $language['name'];
             $record->save();
         } else {
             Language::create($language);
         }
     }
     Eloquent::reguard();
 }
Пример #22
0
 public function createUrl($params)
 {
     if (isset($params['lang_id'])) {
         $lang = Language::findOne($params['lang_id']);
         if ($lang === null) {
             $lang = Language::getDefaultLang();
         }
         unset($params['lang_id']);
     } else {
         $lang = Language::getCurrent();
     }
     $url = parent::createUrl($params);
     if ($url == '/') {
         return '/' . $lang->url;
     } else {
         return '/' . $lang->url . $url;
     }
 }
Пример #23
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::statement("SET foreign_key_checks = 0");
     Language::truncate();
     Language::create(['language_name' => 'Marathi']);
     Language::create(['language_name' => 'Hindi']);
     Language::create(['language_name' => 'Bengali']);
     Language::create(['language_name' => 'Tamil']);
     Language::create(['language_name' => 'Telugu']);
     Language::create(['language_name' => 'Malyalam']);
     Language::create(['language_name' => 'Bhojpuri']);
     Language::create(['language_name' => 'Maithili']);
     Language::create(['language_name' => 'Punjabi']);
     Language::create(['language_name' => 'Haryani']);
     Language::create(['language_name' => 'Gujrati']);
     Language::create(['language_name' => 'Odiya']);
     Language::create(['language_name' => 'Tulu']);
 }
Пример #24
0
 public static function languageLinkTags()
 {
     $controller = Yii::$app->controller;
     $request = Yii::$app->request;
     if (!$controller || !$request || !$request->isGet) {
         return '';
     }
     $params = $request->get();
     unset($params['_lang_']);
     if (!($route = $controller->route)) {
         return '';
     }
     $ret = [];
     foreach (Language::find()->asArray()->all() as $lang) {
         $newParams = array_merge([$route, '_lang_' => $lang['lang']], $params);
         $ret[] = Html::tag('link', '', ['rel' => 'alternate', 'hreflang' => $lang['lang'], 'href' => Url::to($newParams, true)]);
     }
     return implode("\n", $ret) . "\n";
 }
Пример #25
0
 public function index()
 {
     $languages = Language::listing();
     $genres = Genre::listing();
     $beatmaps = json_collection(Beatmapset::listing(), new BeatmapsetTransformer(), 'beatmaps');
     // temporarily put filters here
     $modes = [['id' => null, 'name' => trans('beatmaps.mode.any')]];
     foreach (Beatmap::MODES as $name => $id) {
         $modes[] = ['id' => (string) $id, 'name' => trans("beatmaps.mode.{$name}")];
     }
     $statuses = [['id' => '7', 'name' => trans('beatmaps.status.any')], ['id' => '0', 'name' => trans('beatmaps.status.ranked-approved')], ['id' => '1', 'name' => trans('beatmaps.status.approved')], ['id' => '8', 'name' => trans('beatmaps.status.loved')], ['id' => '2', 'name' => trans('beatmaps.status.faves')], ['id' => '3', 'name' => trans('beatmaps.status.modreqs')], ['id' => '4', 'name' => trans('beatmaps.status.pending')], ['id' => '5', 'name' => trans('beatmaps.status.graveyard')], ['id' => '6', 'name' => trans('beatmaps.status.my-maps')]];
     $extras = [['id' => '0', 'name' => trans('beatmaps.extra.video')], ['id' => '1', 'name' => trans('beatmaps.extra.storyboard')]];
     $ranks = [];
     foreach (['XH', 'X', 'SH', 'S', 'A', 'B', 'C', 'D'] as $rank) {
         $ranks[] = ['id' => $rank, 'name' => trans("beatmaps.rank.{$rank}")];
     }
     $filters = compact('modes', 'statuses', 'genres', 'languages', 'extras', 'ranks');
     return view('beatmaps.index', compact('filters', 'beatmaps'));
 }
Пример #26
0
 public function init()
 {
     parent::init();
     Yii::$app->session->open();
     $language = Yii::$app->request->cookies->getValue('language');
     if ($language && strlen($language) == 5) {
         Yii::$app->language = $language;
     } else {
         if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
             $languages = Language::find()->orderBy(['name' => SORT_ASC])->all();
             $codes = [];
             foreach ($languages as $language) {
                 $codes[] = $language->code;
             }
             if (preg_match("/(" . implode('|', $codes) . ")+(-|;|,)?(.*)?/", $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches)) {
                 $browser_language = $matches[1];
                 Yii::$app->response->cookies->add(new Cookie(['name' => 'language', 'value' => $browser_language, 'expire' => (new \Datetime())->modify('+1 year')->getTimestamp()]));
                 Yii::$app->language = $browser_language;
             }
         }
     }
 }
Пример #27
0
 public function createUrl($params)
 {
     if (isset($params['lang_id'])) {
         //Если указан идентификатор языка, то делаем попытку найти язык в БД,
         //иначе работаем с языком по умолчанию
         $lang = Language::findOne($params['lang_id']);
         if ($lang === null) {
             $lang = Language::getDefaultLang();
         }
         unset($params['lang_id']);
     } else {
         //Если не указан параметр языка, то работаем с текущим языком
         $lang = Language::getCurrent();
     }
     //Получаем сформированный URL(без префикса идентификатора языка)
     $url = parent::createUrl($params);
     //Добавляем к URL префикс - буквенный идентификатор языка
     if ($url == '/') {
         return '/' . $lang->url_key;
     } else {
         return '/' . $lang->url_key . $url;
     }
 }
Пример #28
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $fromWhere = Input::get('from', null);
     // Problem --------------------------------------------------
     $problem_id = Input::get('problem_id', '');
     // User -----------------------------------------------------
     $username = Input::get('user', '');
     // Result ---------------------------------------------------
     $resultRefs = Result::all();
     $result_id = Input::get('result_id', 0);
     // Language -------------------------------------------------
     $lang_id = Input::get('lang_id', 0);
     $langRefs = Language::all();
     $acceptCode = Result::acceptCode;
     $solutions = SolutionService::getSolutionsByOption(['problem_id' => $problem_id, 'username' => $username, 'lang_id' => $lang_id, 'result_id' => $result_id]);
     // $solutions = $solutions->paginateFrom(Input::get('top', ''), 20);
     //$solutions = $solutions->paginate(20, ['url' => \Request::url()]);
     $getUser_id = SolutionService::getUser();
     if ($getUser_id) {
         $getUser_id = $getUser_id->id;
     }
     return view('solutions.index', compact('fromWhere', 'solutions', 'problem_id', 'username', 'result_id', 'resultRefs', 'lang_id', 'langRefs', 'acceptCode', 'getUser_id'));
 }
Пример #29
0
 /**
  * Add a dvd to the database
  * If you're curious where a million db requests are coming from, it's here.
  * @param  array  $input
  * @return bool
  */
 public function create(array $input)
 {
     $dvd = $this->dvdInfo->firstOrCreate(['title' => $input['title'], 'description' => $input['description'], 'length' => $input['length'], 'cover_image' => $input['cover_image']]);
     $price = Price::firstOrCreate(['price_whole' => $input['price_whole'], 'price_cents' => $input['price_cents'], 'late_fee_whole' => $input['late_fee_whole'], 'late_fee_cents' => $input['late_fee_cents'], 'points' => $input['points']]);
     $input['price_id'] = $price->id;
     // Insert producers
     for ($i = 0; $i < sizeof($input['producer_name']); $i++) {
         $producer = Producer::firstOrCreate(['name' => $input['producer_name'][$i]]);
         $dvd->producers()->attach($producer);
     }
     // Insert genres
     for ($i = 0; $i < sizeof($input['genre']); $i++) {
         $genre = Genre::firstOrCreate(['genre' => $input['genre'][$i]]);
         $dvd->genres()->attach($genre);
     }
     // Insert actors
     for ($i = 0; $i < sizeof($input['actor_name']); $i++) {
         $actor = Actor::firstOrCreate(['name' => $input['actor_name'][$i]]);
         $dvd->actors()->attach($actor, ['character_name' => $input['character_name'][$i]]);
     }
     // Add new dvd stock
     $newDvds = [];
     for ($i = 0; $i < $input['stock']; $i++) {
         array_push($newDvds, new DVD($input));
     }
     $dvd->dvds()->saveMany($newDvds);
     foreach ($newDvds as $newDvd) {
         // Insert languages
         for ($i = 0; $i < sizeof($input['language_name']); $i++) {
             $language = Language::firstOrCreate(['language' => $input['language_name'][$i]]);
             $newDvd->languages()->attach($language);
         }
         // Insert subtitles
         for ($i = 0; $i < sizeof($input['subtitle_name']); $i++) {
             $subtitle = Language::firstOrCreate(['language' => $input['subtitle_name'][$i]]);
             $newDvd->subtitles()->attach($subtitle);
         }
     }
 }
Пример #30
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // Set up trusted X-Forwarded-Proto proxies
     // TRUSTED_PROXIES accepts a comma delimited list of subnets
     // ie, TRUSTED_PROXIES='10.0.0.0/8,172.16.0.0/12,192.168.0.0/16'
     if (isset($_ENV['TRUSTED_PROXIES'])) {
         Request::setTrustedProxies(array_map('trim', explode(',', env('TRUSTED_PROXIES'))));
     }
     // Ensure all request are over HTTPS in production
     if (Utils::requireHTTPS() && !Request::secure()) {
         return Redirect::secure(Request::path());
     }
     // If the database doens't yet exist we'll skip the rest
     if (!Utils::isNinja() && !Utils::isDatabaseSetup()) {
         return $next($request);
     }
     // Check if a new version was installed
     if (!Utils::isNinja()) {
         $file = storage_path() . '/version.txt';
         $version = @file_get_contents($file);
         if ($version != NINJA_VERSION) {
             $handle = fopen($file, 'w');
             fwrite($handle, NINJA_VERSION);
             fclose($handle);
             return Redirect::to('/update');
         }
     }
     // Check the application is up to date and for any news feed messages
     if (Auth::check()) {
         $count = Session::get(SESSION_COUNTER, 0);
         Session::put(SESSION_COUNTER, ++$count);
         if (isset($_SERVER['REQUEST_URI']) && !Utils::startsWith($_SERVER['REQUEST_URI'], '/news_feed') && !Session::has('news_feed_id')) {
             $data = false;
             if (Utils::isNinja()) {
                 $data = Utils::getNewsFeedResponse();
             } else {
                 $file = @file_get_contents(NINJA_APP_URL . '/news_feed/' . Utils::getUserType() . '/' . NINJA_VERSION);
                 $data = @json_decode($file);
             }
             if ($data) {
                 if (version_compare(NINJA_VERSION, $data->version, '<')) {
                     $params = ['user_version' => NINJA_VERSION, 'latest_version' => $data->version, 'releases_link' => link_to(RELEASES_URL, 'Invoice Ninja', ['target' => '_blank'])];
                     Session::put('news_feed_id', NEW_VERSION_AVAILABLE);
                     //Session::flash('news_feed_message', trans('texts.new_version_available', $params));
                 } else {
                     Session::put('news_feed_id', $data->id);
                     if ($data->message && $data->id > Auth::user()->news_feed_id) {
                         Session::flash('news_feed_message', $data->message);
                     }
                 }
             } else {
                 Session::put('news_feed_id', true);
             }
         }
     }
     // Check if we're requesting to change the account's language
     if (Input::has('lang')) {
         $locale = Input::get('lang');
         App::setLocale($locale);
         Session::set(SESSION_LOCALE, $locale);
         if (Auth::check()) {
             if ($language = Language::whereLocale($locale)->first()) {
                 $account = Auth::user()->account;
                 $account->language_id = $language->id;
                 $account->save();
             }
         }
     } elseif (Auth::check()) {
         $locale = Auth::user()->account->language ? Auth::user()->account->language->locale : DEFAULT_LOCALE;
         App::setLocale($locale);
     } elseif (session(SESSION_LOCALE)) {
         App::setLocale(session(SESSION_LOCALE));
     }
     // Make sure the account/user localization settings are in the session
     if (Auth::check() && !Session::has(SESSION_TIMEZONE)) {
         Event::fire(new UserSettingsChanged());
     }
     // Check if the user is claiming a license (ie, additional invoices, white label, etc.)
     if (isset($_SERVER['REQUEST_URI'])) {
         $claimingLicense = Utils::startsWith($_SERVER['REQUEST_URI'], '/claim_license');
         if (!$claimingLicense && Input::has('license_key') && Input::has('product_id')) {
             $licenseKey = Input::get('license_key');
             $productId = Input::get('product_id');
             $data = trim(file_get_contents((Utils::isNinjaDev() ? SITE_URL : NINJA_APP_URL) . "/claim_license?license_key={$licenseKey}&product_id={$productId}"));
             if ($productId == PRODUCT_INVOICE_DESIGNS) {
                 if ($data = json_decode($data)) {
                     foreach ($data as $item) {
                         $design = new InvoiceDesign();
                         $design->id = $item->id;
                         $design->name = $item->name;
                         $design->pdfmake = $item->pdfmake;
                         $design->save();
                     }
                     Cache::forget('invoiceDesigns');
                     Session::flash('message', trans('texts.bought_designs'));
                 }
             } elseif ($productId == PRODUCT_WHITE_LABEL) {
                 if ($data == 'valid') {
                     $account = Auth::user()->account;
                     $account->pro_plan_paid = NINJA_DATE;
                     $account->save();
                     Session::flash('message', trans('texts.bought_white_label'));
                 }
             }
         }
     }
     // Check data has been cached
     $cachedTables = unserialize(CACHED_TABLES);
     if (Input::has('clear_cache')) {
         Session::flash('message', 'Cache cleared');
     }
     foreach ($cachedTables as $name => $class) {
         if (Input::has('clear_cache') || !Cache::has($name)) {
             if ($name == 'paymentTerms') {
                 $orderBy = 'num_days';
             } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries'])) {
                 $orderBy = 'name';
             } else {
                 $orderBy = 'id';
             }
             $tableData = $class::orderBy($orderBy)->get();
             if (count($tableData)) {
                 Cache::forever($name, $tableData);
             }
         }
     }
     // Show message to IE 8 and before users
     if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/(?i)msie [2-8]/', $_SERVER['HTTP_USER_AGENT'])) {
         Session::flash('error', trans('texts.old_browser'));
     }
     $response = $next($request);
     //$response->headers->set('X-Frame-Options', 'DENY');
     return $response;
 }