Exemple #1
0
 /**
  * Show page (get).
  *
  * @Get("show/{id}", as="memo.show")
  *
  * @param string $id
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function getShow($id)
 {
     $memo = $this->memo->find($id);
     if (!isset($memo)) {
         abort(404);
     }
     return view('memos.show', compact('memo'));
 }
 /**
  * @dataProvider userDataProvider
  *
  * @param string $sn
  */
 public function testUser($sn)
 {
     $tmp = $this->memo->where('user_sn', $sn);
     $memos = $tmp->orderBy('id', 'desc')->paginate(10);
     $count = $tmp->count();
     foreach ($memos as $memo) {
         $this->visit("/memo/user/{$memo->user_sn}")->see("@{$memo->user_sn}のメモ")->see("https://twitter.com/{$memo->user_sn}")->see($count)->see($memo->created_at->format(dateFormat()))->see($memo->user_sn)->see(autoLink($memo->content))->seeInfo()->assertResponseOk();
         if ($count > 10) {
             $this->see("/memo/user/{$memo->user_sn}");
         }
     }
 }
Exemple #3
0
 /**
  * memo/create API.
  *
  * @Any("create", as="api.memo.create")
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function anyCreate()
 {
     try {
         $id = $this->request('id');
         if (empty($id) || !is_string($id)) {
             throw new RuntimeException('id is empty.');
         }
         $info = $this->TwistOAuth->get('statuses/show', compact('id'));
         $data = ['user_sn' => $info->user->screen_name, 'user_id' => $info->user->id_str, 'content' => $info->text];
         foreach ($info->entities->urls as $url) {
             $data['content'] = str_replace($url->url, $url->expanded_url, $data['content']);
         }
         if (isset($info->extended_entities)) {
             foreach ($info->extended_entities->media as $m) {
                 $data['content'] = str_replace($m->url, $m->media_url_https, $data['content']);
             }
         }
         $validate = $this->memo->insert($data, ['save' => true]);
         if ($validate === true) {
             $id = $this->memo->select('id')->where('user_sn', '=', $data['user_sn'])->where('user_id', '=', $data['user_id'])->where('content', '=', $data['content'])->get()->last()->id;
             $json = ['id' => $id, 'user_sn' => $data['user_sn'], 'user_id' => $data['user_id'], 'content' => $data['content']];
             return $this->onSuccess($json);
         }
         throw new RuntimeException($validate->errors()->first(), 400);
     } catch (Exception $e) {
         return $this->onError($e);
     }
 }
Exemple #4
0
 /**
  * Delete page (post).
  *
  * @Post("delete/{id}", as="user.memo.delete")
  *
  * @param string $id
  *
  * @return \Illuminate\Http\RedirectResponse
  *
  * @throws \Exception
  */
 public function postDelete($id)
 {
     $memo = $this->memo->find($id);
     if (!isset($memo)) {
         abort(404);
     }
     if ($memo->user_id !== $this->user_id) {
         return redirect('user/memo')->with('message', 'そのメモはあなたのメモではありません。');
     }
     $memo->delete();
     return redirect('user/memo')->with('message', '削除しました。');
 }
 /**
  * Create sitemap data.
  *
  * @return array
  */
 protected function createSiteMapData()
 {
     $data = [];
     $pasteBin = new M\PasteBin();
     $last = $pasteBin->orderBy('id')->get()->last();
     $data[] = ['loc' => '/pastebin', 'lastmod' => $last->created_at->format('Y-m-d'), 'changefreq' => 'monthly', 'priority' => '0.7'];
     $all = $pasteBin->select(['hash', 'created_at'])->where('protect', '=', false)->get();
     foreach ($all as $p) {
         $data[] = ['loc' => "/pastebin/show/{$p->hash}", 'lastmod' => $p->created_at->format('Y-m-d'), 'changefreq' => 'never', 'priority' => '0.4'];
     }
     $memo = new M\Memo();
     $last = $memo->orderBy('id')->get()->last();
     $data[] = ['loc' => '/memo', 'lastmod' => $last->created_at->format('Y-m-d'), 'changefreq' => 'monthly', 'priority' => '0.7'];
     foreach ($memo->select(['id', 'created_at'])->get() as $m) {
         $data[] = ['loc' => "/memo/show/{$m->id}", 'lastmod' => $m->created_at->format('Y-m-d'), 'changefreq' => 'never', 'priority' => '0.4'];
     }
     foreach ($memo->select('user_sn')->distinct()->get() as $m) {
         $updated_at = $memo->where('user_sn', '=', $m->user_sn)->get()->last()->updated_at;
         $data[] = ['loc' => "/memo/user/{$m->user_sn}", 'lastmod' => $updated_at->format('Y-m-d'), 'changefreq' => 'monthly', 'priority' => '0.4'];
     }
     return $data;
 }
Exemple #6
0
 /**
  * Update memo user_sn.
  *
  * @param string $userId
  * @param string $userSn
  */
 protected function updateMemo($userId, $userSn)
 {
     $memo = new Memo();
     $all = $memo->select(['user_sn', 'user_id'])->whereUserId($userId)->get();
     foreach ($all as $memo) {
         if ($memo->user_sn === $userSn) {
             continue;
         }
         $memo->user_sn = $userSn;
         $memo->update();
     }
 }
 /**
  * @dataProvider allMemoDataProvider
  *
  * @param Memo $memo
  */
 public function testShow(Memo $memo)
 {
     $this->call('GET', '/api/memo/show', ['id' => $memo->id]);
     $this->seeJsonEquals($memo->toArray())->assertResponseOk();
 }
Exemple #8
0
 /**
  * Test insert method.
  *
  * @dataProvider insertDataProvider
  *
  * @param mixed $user_sn
  * @param mixed $user_id
  * @param mixed $content
  * @param bool  $hasError
  */
 public function testInsert($user_sn, $user_id, $content, $hasError)
 {
     $data = compact('user_sn', 'user_id', 'content');
     $response = $this->memo->insert($data);
     $this->checkError($response, $hasError);
 }