module Admin::PlaygroundHelper require 'securerandom' def secure_rand_number(max_num) if max_num.is_a?(Range) min_num = max_num.begin.to_i offset = max_num.exclude_end? ? 0 : 1 max_num = max_num.end.to_i - min_num + offset min_num + SecureRandom.random_number(max_num) else SecureRandom.random_number(max_num.to_i) end end def make_announcement_fake_data(ma, total_count=5) page = Page.Where(:module => ma.key).first rescue nil if page.nil? page = Page.new(:module => ma.key, :page_id => "announcements", :layout => "annc_index1", :name_translations => {"en" => "Announcement", "zh_tw" => "公告"}, :url => "/announcements", :enabled_for => ["en", "zh_tw"], :menu_enabled_for => ["en", "zh_tw"], :categories => ["all"], :tags => ["all"], :enabled_for_sitemap => ["en", "zh_tw"], :parent_page => Page.root) page.save end if ma.categories.empty? cat = Category.new cat.title_translations = {"en" => "Announcement", "zh_tw" => "公告"} cat.module_app = ma cat.save else cat = ma.categories.first end if ma.tags.empty? tag = Tag.new tag.name_translations = {"en" => "Announcement", "zh_tw" => "公告"} tag.module_app_ids << ma.id tag.save else tag = ma.tags.first end fake_ids = [] (1..total_count).each do |i| bulletin = Bulletin.new(:title_translations => get_random_title, :subtitle_translations => get_random_subtitle, :text_translations => get_random_content, :create_user_id => current_user.id.to_s, :update_user_id => current_user.id.to_s, :deadline => get_fake_date, :approved => true, :image_description_translations => get_random_title) bulletin.category = cat bulletin.tags=tag bulletin.is_top = get_random_status bulletin.is_hot = get_random_status bulletin.remote_image_url = get_fake_image_url(ma.key) bulletin.save fake_ids << bulletin.id (1..secure_rand_number(1..5)).each do |x| bf = BulletinFile.new(:title_translations => get_random_title, :description_translations => get_random_title) bf.remote_file_url = get_fake_file_url(ma.key) bf.bulletin = bulletin bf.save end (1..secure_rand_number(1..5)).each do |x| bl = BulletinLink.new(:title_translations => get_random_title, :url => get_fake_link) bl.bulletin = bulletin bl.save end end commit_fake_data(ma, fake_ids) end def delete_announcement_fake_data(ma) fd = FakeData.where(:module => ma).first rescue nil bulletins = Bulletin.where(:id.in => fd.ids) bulletins.destroy_all fd.destroy end def make_ad_banner_fake_data(ma, total_count=5) if ma.categories.empty? cat = Category.new cat.title_translations = {"en" => "Home Banners", "zh_tw" => "家庭橫幅"} cat.module_app = ma cat.save else cat = ma.categories.first end fake_ids = [] fds = FakeData.where(:module => "ad_banner").first.ids.count rescue 0 (1..total_count).each do |i| banner = Banner.new(:title => "Home banner #{i + fds}", :ad_fx => "fade", :height => 300, :width => 800, :timeout => 5, :base_image => 1, :speed => 200) banner.category = cat banner.save fake_ids << banner.id (1..secure_rand_number(2..4)).each do |x| image = AdImage.new(:title_translations => get_random_title, :context_translations => get_random_title, :out_link => get_fake_link, :deadline => get_fake_date, :sort_number => x, :link_open => AdImage::LINK_OPEN_TYPES.sample) image.remote_file_url = get_fake_image_url(ma.key) image.banner = banner image.save end end commit_fake_data(ma, fake_ids) end def delete_ad_banner_fake_data(ma) fd = FakeData.where(:module => ma).first rescue nil banners = Banner.where(:id.in => fd.ids) banners.destroy_all fd.destroy end def make_faq_fake_data(ma, total_count=5) page = Page.Where(:module => ma.key).first rescue nil if page.nil? page = Page.new(:module => ma.key, :page_id => "faqs", :layout => "faq_index1", :name_translations => {"en" => "FAQs", "zh_tw" => "FAQs"}, :url => "/faqs", :enabled_for => ["en", "zh_tw"], :menu_enabled_for => ["en", "zh_tw"], :categories => ["all"], :tags => ["all"], :enabled_for_sitemap => ["en", "zh_tw"], :parent_page => Page.root) page.save end if ma.categories.empty? cat = Category.new cat.title_translations = {"en" => "FAQ", "zh_tw" => "FAQ"} cat.module_app = ma cat.save else cat = ma.categories.first end if ma.tags.empty? tag = Tag.new tag.name_translations = {"en" => "FAQ", "zh_tw" => "FAQ"} tag.module_app_ids << ma.id tag.save else tag = ma.tags.first end fake_ids = [] (1..total_count).each do |i| qa = Qa.new(:title_translations => get_random_title, :answer_translations => get_random_subtitle, :create_user_id => current_user.id.to_s, :update_user_id => current_user.id.to_s, :is_hot => get_random_status, :is_top => get_random_status) qa.category = cat qa.tags=tag qa.save fake_ids << qa.id (1..secure_rand_number(1..5)).each do |x| qf = QaFile.new(:title_translations => get_random_title, :description_translations => get_random_title) qf.remote_file_url = get_fake_file_url(ma.key) qf.qa = qa qf.save end (1..secure_rand_number(1..5)).each do |x| ql = QaLink.new(:title_translations => get_random_title, :url => get_fake_link) ql.qa = qa ql.save end end commit_fake_data(ma, fake_ids) end def delete_faq_fake_data(ma) fd = FakeData.where(:module => ma).first rescue nil faqs = Qa.where(:id.in => fd.ids) faqs.destroy_all fd.destroy end def make_archive_fake_data(ma, total_count=5) page = Page.Where(:module => ma.key).first rescue nil if page.nil? page = Page.new(:module => ma.key, :page_id => "archive", :layout => "archive_index1", :name_translations => {"en" => "Archive", "zh_tw" => "檔案"}, :url => "/archive", :enabled_for => ["en", "zh_tw"], :menu_enabled_for => ["en", "zh_tw"], :categories => ["all"], :tags => ["all"], :enabled_for_sitemap => ["en", "zh_tw"], :parent_page => Page.root) page.save end if ma.categories.empty? cat = Category.new cat.title_translations = {"en" => "Archive", "zh_tw" => "檔案"} cat.module_app = ma cat.save else cat = ma.categories.first end if ma.tags.empty? tag = Tag.new tag.name_translations = {"en" => "Archive", "zh_tw" => "檔案"} tag.module_app_ids << ma.id tag.save else tag = ma.tags.first end fake_ids = [] (1..total_count).each do |i| archive = ArchiveFile.new(:title_translations => get_random_title, :create_user_id => current_user.id.to_s, :update_user_id => current_user.id.to_s, :deadline => get_fake_date, :is_top => get_random_status, :is_hot => get_random_status) archive.category = cat archive.tags=tag archive.save fake_ids << archive.id (1..secure_rand_number(1..5)).each do |x| afm = ArchiveFileMultiple.new(:file_title_translations => get_random_title, :sort_number => x) afm.remote_file_url = get_fake_file_url(ma.key) afm.archive_file = archive afm.save end end commit_fake_data(ma, fake_ids) end def delete_archive_fake_data(ma) fd = FakeData.where(:module => ma).first rescue nil archives = ArchiveFile.where(:id.in => fd.ids) archives.destroy_all fd.destroy end def make_gallery_fake_data(ma, total_count=5) page = Page.Where(:module => ma.key).first rescue nil if page.nil? page = Page.new(:module => ma.key, :page_id => "gallery", :layout => "gallery_index1", :name_translations => {"en" => "Gallery", "zh_tw" => "相簿"}, :url => "/gallery", :enabled_for => ["en", "zh_tw"], :menu_enabled_for => ["en", "zh_tw"], :categories => ["all"], :tags => ["all"], :enabled_for_sitemap => ["en", "zh_tw"], :parent_page => Page.root) page.save end if ma.categories.empty? cat = Category.new cat.title_translations = {"en" => "Gallery", "zh_tw" => "相簿"} cat.module_app = ma cat.save else cat = ma.categories.first end if ma.tags.empty? tag = Tag.new tag.name_translations = {"en" => "Gallery", "zh_tw" => "相簿"} tag.module_app_ids << ma.id tag.save else tag = ma.tags.first end fake_ids = [] (1..total_count).each do |i| album = Album.new(:name_translations => get_random_title, :description_translations => get_random_subtitle) album.tags=tag album.category = cat album.save fake_ids << album.id (1..secure_rand_number(5..10)).each do |x| image = AlbumImage.new(:title => get_random_title["zh_tw"], :description_translations => get_random_title, :order => x) image.remote_file_url = get_fake_image_url(ma.key) image.album = album image.save end end commit_fake_data(ma, fake_ids) end def delete_gallery_fake_data(ma) fd = FakeData.where(:module => ma).first rescue nil albums = Album.where(:id.in => fd.ids) albums.destroy_all fd.destroy end def make_web_resource_fake_data(ma, total_count=5) page = Page.Where(:module => ma.key).first rescue nil if page.nil? page = Page.new(:module => ma.key, :page_id => "links", :layout => "web_res_index1", :name_translations => {"en" => "Links", "zh_tw" => "連結"}, :url => "/links", :enabled_for => ["en", "zh_tw"], :menu_enabled_for => ["en", "zh_tw"], :categories => ["all"], :tags => ["all"], :enabled_for_sitemap => ["en", "zh_tw"], :parent_page => Page.root) page.save end if ma.categories.empty? cat = Category.new cat.title_translations = {"en" => "Links", "zh_tw" => "連結"} cat.module_app = ma cat.save else cat = ma.categories.first end if ma.tags.empty? tag = Tag.new tag.name_translations = {"en" => "Links", "zh_tw" => "連結"} tag.module_app_ids << ma.id tag.save else tag = ma.tags.first end fake_ids = [] (1..total_count).each do |i| link = WebLink.new(:title_translations => get_random_title, :context_translations => get_random_subtitle, :url_translations => {"en" => get_fake_link, "zh_tw" => get_fake_link}, :create_user_id => current_user.id.to_s, :update_user_id => current_user.id.to_s, :link_open => WebLink::LINK_OPEN_TYPES.sample, :is_top => get_random_status, :is_hot => get_random_status) link.category = cat link.tags=tag link.save fake_ids << link.id end commit_fake_data(ma, fake_ids) end def delete_web_resource_fake_data(ma) fd = FakeData.where(:module => ma).first rescue nil links = WebLink.where(:id.in => fd.ids) links.destroy_all fd.destroy end def get_fake_date(no=100) Time.now + secure_rand_number(1..no).days end def get_fake_link ["http://www.google.com", "http://www.rulingcom.com", "http://www.yahoo.com", "http://www.9gag.com", "http://www.youtube.com", "http://www.linkedin.com","http://www.imdb.com", "http://www.github.com", "http://www.google.co.in", "https://en.wikipedia.org/wiki/Wikipedia"].sample end def commit_fake_data(ma, fake_ids) fd = FakeData.where(:module => ma.key).first rescue nil if fd.nil? FakeData.create(:module => ma.key, :ids => fake_ids) else fd.ids = fd.ids.concat(fake_ids) fd.save end end def get_fake_file_url(key) OrbitStore::URL + "/fake_data/#{key}/files/" + secure_rand_number(1..5).to_s + ".txt" end def get_fake_image_url(key) OrbitStore::URL + "/fake_data/#{key}/images/" + secure_rand_number(1..15).to_s + ".jpg" end def get_random_status [true,false,true,true,false,false,false,false,false,false,false,true,false,true,false,true,false,false,true,false,true,false,true,false,false,false,false,false,true,false,true,false].sample end def get_random_title [ { "en" => "Lorem ipsum Quis deserunt culpa velit ea enim do labore ex.", "zh_tw" => "廣州百萬招聘往往角色所有爆炸後面自從本站慢慢插件,一批研發雙手變成漸漸出去將在先生她們清楚寂寞降,功夫女性線路才能設置之家好處朋友警方放心連載有的創意教。" }, { "en" => "Lorem ipsum Voluptate consectetur labore sed nisi Duis Duis in ut sit.", "zh_tw" => "確實姓名走出被人相對壓縮生活關注培訓紡織有所裡面房,是有能源威脅他是文本上帝印刷年輕,深圳科技有限公司類別廣播我家機制我說加入接收執行時間,求購人物轉讓大聲相當運行中心,恢復據說資本人物專欄房屋記得感受謝謝市委用戶" }, { "en" => "Lorem ipsum Ut adipisicing laboris tempor cillum eu tempor est minim ut deserunt elit sit.", "zh_tw" => "對外購買創新發現跟著欣賞掌握第二天,最初結構投資體系招生髮表不滿請點擊手,那些結果警察一下回事可用其中避免贏得大學還是按照利潤。" }, { "en" => "Chinese Lorem Ipsum includes the most common kanji chars and punctuation. Suggestions for improvements or alternatives are welcome.", "zh_tw" => "速牧摘藤請能攜針紹掲式盤談。報厚勝月注揚件岡視申邊幅念七屬年。頼疑観小章的談集演選容善為真北上左。" }, { "en" => "Lorem ipsum is a pseudo-Latin text used in web design, typography, layout, and printing in place of English to emphasise design elements over content.", "zh_tw" => "側經意責家方家閉討店暖育田載社轉線宇。得君新術治溫抗添代話考振投員毆大北裁。" }, { "en" => "Lorem ipsum Officia sed cillum aute magna consectetur nulla adipisicing magna.", "zh_tw" => "英文業務體現首頁聽到禁止警察平衡誠信上次基金次數。" }, { "en" => "Lorem ipsum Mollit officia sunt ea reprehenderit velit laborum.", "zh_tw" => "解壓密碼效益價格女孩怪物高校互聯網交給商品人士儲存,優勢通過讓她都是親自一生現場大家動態,作用不同再度在此標題肯定優惠服。" } ].sample end def get_random_subtitle [ { "en" => "Lorem ipsum is a pseudo-Latin text used in web design, typography, layout, and printing in place of English to emphasise design elements over content. It's also called placeholder (or filler) text. It's a convenient tool for mock-ups.", "zh_tw" => "財富整無必提引人懸身作渡健朝化紙事。人解食米生利娘法平終票織絶般改。文本行暮際對新左報事迫開件勝初測出人。速摘藤請能攜針紹式盤談。報厚勝月注揚件視申幅念七屬年。頼疑小章的談集演選容為真北左。" }, { "en" => "While lorem ipsum's still resembles classical Latin, it actually has no meaning whatsoever. As Cicero's text doesn't contain the letters K, W, or Z, alien to latin, these, and others are often inserted randomly to mimic the typographic appearence of European languages, as are digraphs not to be found in the original.", "zh_tw" => "目報貴代向能究介集分頃妻。休表化降最州別文東表住線。呼支保木前果告共芝暴禁玉姫五點稚。第色絡明域市造神草要督運流題。信下臨法職左通出官質給探。沖金普議雪受國女出般馬紙手災半塊。通別暮載典子郎將開展造能一。" }, { "en" => "In a professional context it often happens that private or corporate clients corder a publication to be made and presented with the actual content still not being ready. Think of a news blog that's filled with content hourly on the day of going live. However, reviewers tend to be distracted by comprehensible content.", "zh_tw" => "轉殺東入館特造賠感購予主市推製理承博。選被桶善外出神際抵法政。品誰非萬女話感合文昭。恐勢供村著雨木助階野食川園公大。連返一暮際平首寫一會未京美刃。珍者見藤石第返前鳥科宅様。直島載死談待思際考以響策依室參將機。演況民王手更愛五督銘索女。" } ].sample end def get_random_content [ { "en" => "Lorem ipsum In magna nisi aliquip enim ex consectetur. Lorem ipsum Id laboris veniam ullamco velit minim sit in aute commodo. Lorem ipsum Eiusmod nisi consectetur eu nostrud nisi et commodo laborum sint commodo. Lorem ipsum Irure aliquip laboris aliquip qui sint incididunt sunt nisi Ut pariatur. Lorem ipsum Sint culpa proident consequat sed eu proident ex ea dolor. Lorem ipsum Aliquip proident adipisicing fugiat fugiat consequat sed ex nulla. Lorem ipsum Labore culpa enim enim voluptate cillum velit labore esse voluptate. Lorem ipsum Aute est quis mollit consectetur reprehenderit. Lorem ipsum Pariatur et in Ut id laboris aute aliqua. Lorem ipsum Ut id non ad cillum non est ad sunt reprehenderit in nulla. Lorem ipsum Ea commodo cillum veniam Ut aute exercitation ullamco dolor aliqua. Lorem ipsum Quis anim ad officia esse ut magna. Lorem ipsum Irure aute reprehenderit officia esse qui ex laborum mollit Duis laboris.", "zh_tw" => "對待證券首頁看法我和確認發布你看明顯之類答案透明多麼破,確保風險做法吸收不大,誘惑女子新手不論不可地上採購能力漫畫音樂營養河北笑,蒐集製造英國河南即可決策所說強化註冊還有廣場這麼這樣,好友音樂黃金有一定女,次數黑暗想法告知手續北京註冊。循環策略簡體中文股份塑料,加入時間經過會不會一家特色公告屬性協議多,公告穿著死亡說明角度體制交通路線期間太陽問題桌面依法,影視大學生道德虛擬業主自由不能,進去飛機本周越來越傳奇結構批發新人官員要有下,理念現像對比用戶名中國計算機目的,定位插件晚上加油年輕僅僅監督探索授權方式創業經營放棄。處理實現航空規定明天總,這一電源限制原因意思指數實驗表達互動代理體內較大早就代表,就不參數貢獻服務理論一方面計算進來貫徹規格面議不如監管證據,優秀監管試題回答容量,突破允許障礙考研你能也就是他們的我說空調也,拍攝男女增長其他官方方面發布結束模擬女子出了欄目我的心他,大幅備案無數貿易多種和平招聘,一時商標要在從事毫不手段經典可能會遭,高達旁邊演員代理適用於鑑定堅持管理。許多本次臨時發現小學前往第二章新型鏈接讓她這里聯賽鄭,相關讀者存儲博客零售最近多次付出造成請點擊也在房間帶,出去說是避免騎士還是注重不停網通相冊排行榜到處,尊重思路回到責任編輯每個人鬱,靈魂沒有甚至自己可能會說過出席化學新技術對手責任編輯可惜他說,家庭諾基亞沒事開通個性保密辛苦文檔選擇準備商城基本上他也休閒。" }, { "en" => "Lorem ipsum Ad dolor in aliqua labore in dolor qui anim laborum. Lorem ipsum Et sed cillum anim nisi dolore. Lorem ipsum Enim sit dolor incididunt in tempor laborum nulla dolor nulla officia. Lorem ipsum Ut ea incididunt ad in esse eiusmod magna Excepteur sed esse. Lorem ipsum Cupidatat elit in ut dolore in mollit velit. Lorem ipsum Dolor enim aliqua consectetur veniam exercitation anim Duis occaecat aute in ex. Lorem ipsum Voluptate eiusmod sint pariatur quis velit aute enim fugiat. Lorem ipsum Officia dolore exercitation nisi qui minim anim id magna exercitation. Lorem ipsum Non in mollit veniam ut Excepteur officia. Lorem ipsum Ea in aliqua non ut commodo consequat commodo proident in anim. Lorem ipsum Culpa et Excepteur occaecat incididunt laborum pariatur ad ex reprehenderit. Lorem ipsum Cillum sed occaecat elit Excepteur Duis dolor exercitation commodo ut dolore. Lorem ipsum Sunt reprehenderit in dolore voluptate Excepteur ullamco pariatur sed dolore magna nisi. Lorem ipsum Mollit anim Ut elit aliqua labore laborum aliquip commodo nisi sint. Lorem ipsum Esse eu elit in nisi id sint nulla consectetur.", "zh_tw" => "加入時間一樣轉讓能量人們導致要有互動初步同學手機是怎麼,無關比例穿著再說上來好像我愛充滿當,新聞支付不足增加發揮神經果然將。招商經濟發展不少最後條款準確不,接受之類觀點身影蘇州總部可見言論空中一會這個問題電子如果您,解放危機顯卡享受足夠味道快速分類回答生成聯。一款帶來監督獎勵也能台北提出開了前面檢查,監管液晶交易建設而言看過放下江湖對了航空,智慧現代化緊緊一邊哥,屏幕長大角色前面精神新華網,刷新物質滿意看看反饋情感放在購買男生簡,默認最重要男孩世界杯還可以獲取全市版主我,位於讓他菜單矛盾塑料讓我畢業生作用人大常委會清楚寂。它們排行榜一張優勢本身接著感情人間有時候排行他就,形式第二天加快查詢尷尬影視大全你有詳細勝利和你演出出,世界杯多多供應改革監督出台作出總結提高最快全體美元文明西,神經那天法院你會靈活備案味道減,總是處理器森林服務器便宜中央不得不福建,回應插件倒是我們告訴你多媒體政府江蘇遺憾開口哥哥,言論你想文學外貿將會母親辛苦部落分析例如高級對,有限責任公司回事核心只要它們以往哪些大幅提交優勢對外否則。全省讓我們享受騎士嘗試男生新華網據說用戶,數碼相機用戶名退出得到見面部門老公小區讓他大賽被人開了,職責溝通字幕普遍介紹運,每年有一些點這裡下載身子竟然篇文章全國新年多個是不是天津您。這段頭銜下降河北獲得防止獨立道理公主策劃部落方案其實,等等等待不錯客服以外提示商家面對新聞,虛擬排行榜可以說恢復此時加大優勢上漲第一。品牌天使本身電子放在勝,又有痛苦尤其是如有商品金額有限公司爭取森林舉報好評期,印刷說到一部分金錢酒店畢業生交友概念治理付出,患者研究真實污染大力外資西安一聲這麼多內置舉報投,進步上次所需治理上傳文件大小否則個人形成有限責任公司成果魔法。提前安排的是考研起來手指小心所以監控一看很難一,媽媽在線有限責任公司適應重視就好會員增加環境試驗青年謝謝四川,贏得客人生意賓館語文。一體情形接下來鈴聲玻璃數碼相機動物英,出了禮物值得書庫看起來開了,治理不喜歡互相妻子偉大頭銜滿意動力花,似乎立刻爭取魔獸作品把你頻道,價值工程種種鐵路模擬慢慢保持爆炸才是迅速同一進,接收相關配套分配案例以後方面,具體室內請大家路線法律責任會員你有多,傳真零售日韓人事避免教育活,協調同步實施身影一大等方面海外本。趕緊安排特色技巧它們如果你非法,位於是由稱為不肯不錯核心你是行情明,股東日期值得國產正文,水晶後面模樣出售好多,說到不足怎麼辦市場名單友情鏈接稿件事,成熟隨著轉移解決不在人類台灣還在,家族慢慢鐵通怎麼電器願意設置內容簡介點這裡自主創,發貼或是男子裝置舉行網通優勢不限交通沒事聯盟最。年齡寶寶你自己曝光儀器體會情況不可一台這次考生農業變化鼠標,情感就在這麼多結婚身上公里給我紡織轉讓,錄入流程形成真實過了預防是有其實科技設計,外資充分森林如有事業,股東欣賞污染開展法院山東還沒有英國英文投票。廣播本地下載均為部分還可以,理解一對平時為何精華並不地址老婆演,一對不能湖北爸爸讓她早就酒店權力歐,同一先進多個協調通過創造關心機構興奮有機會都,笑話文化請求稿件我這現實求助改革,標題令人限制批准是個聯賽理念竟然麻煩目前,導航街道上次最新是他次數需,先進性反而付款認識批准禮物像是郵政。水果合理不肯智能明天世,時間措施鍵盤大部分國家吸引東西藥品不大作為光臨所謂,有時發行將軍女性再說都沒裡面地上實際上股權語文而已運行平台結,郵編但我前面讓我們亞洲拿出必須人口商品全身突破退出作品當中計,具備出發反正您是公斤想要。" } ].sample end end