Example #1
0
 public function getAllByTag($id)
 {
     return Cache::store('prevTag')->rememberForever($id . ':' . $this->page, function () use($id) {
         $tags = new Tags();
         $tag = $tags->getById($id)->first();
         //Да, да для статей алгоритм обсалютно такой-же
         //Но я действую так, если код дублируется больше 2храз (Но только в рамках одного класса/ф-и php файла)то:
         //создаем шаблон для повторяющихся действий, выносим всё в ф-и и т.п.
         //Для хлебных крошек
         $items['tag'] = ['id' => $tag->id, 'name' => $tag->name, 'curl' => $tag->curl];
         //методанные
         $items['title'] = $tag->name;
         $items['keywords'] = 'блог, разработка, тег, ' . $tag->name;
         if ($tag->meta_keywords != '') {
             //Доп ключевые слова
             $items['keywords'] .= ',' . $tag;
         }
         $items['description'] = 'Блог начинающего backend разработчика' . 'Все статьи отобранные по тегу ' . $tag->name . '.' . $tag->meta_descriptiom;
         //Превьюхи
         $articles = $tag->articles()->published()->orderByParam()->with('tags', 'category')->paginate($this->countPage);
         //Превьюхи в нужном формате
         $items['articles'] = $this->createArrPreviews($articles);
         return $this->createLengthAwarePaginator($articles, $items);
     });
 }
 public function getTags()
 {
     $tags = Tags::all()->toArray();
     if ($tags != null) {
         return Utility::response_format(Utility::RESPONSE_CODE_SUCCESS, $tags, '请求成功');
     }
 }
 public function getQuestionDetail()
 {
     $request = Request::capture();
     $token = $request->input('token');
     $questionId = $request->input('questionId');
     $userId = AuthController::getUserIdByToken($token);
     if ($userId == null) {
         return Utility::response_format(Utility::RESPONSE_CODE_AUTH_ERROR, '', '认证失败');
     }
     if ($questionId == null) {
         return Utility::response_format(Utility::RESPONSE_CODE_Error, '', 'questionId不能为空');
     }
     $question = Question::select('id', 'title', 'content', 'publish_time', 'user_id')->where('id', $questionId)->first()->toArray();
     //        print_r($question);
     // 个人信息
     $userInfo = UserInfo::select('user_name', 'head_pic')->where('user_id', $question['user_id'])->first()->toArray();
     $question = array_merge($question, $userInfo);
     // 图片
     $picIds = QuestionPictures::select('pic_id')->where('question_id', $question['id'])->get()->toArray();
     $pics = Picture::whereIn('id', $picIds)->get()->toArray();
     $question = array_merge($question, ['image' => $pics]);
     //            print_r($question);
     // 标签
     $tagIds = QuestionTags::select('tag_id')->where('question_id', $question['id'])->get()->toArray();
     $tags = Tags::whereIn('id', $tagIds)->get()->toArray();
     $question = array_merge($question, ['tags' => $tags]);
     // 回答 时间倒序 前三条
     $answers = Answer::select('*')->where('question_id', $questionId)->orderBy('answer_time', 'desc')->paginate(3, '*', 'page', 1)->toArray();
     $result = array();
     foreach ($answers['data'] as $answer) {
         // 个人信息
         $userInfo = UserInfo::select('user_name', 'head_pic')->where('user_id', $answer['user_id'])->first()->toArray();
         $answer = array_merge($answer, $userInfo);
         // 回答的评论数
         $comments = Comment::select('*')->where('answer_id', $answer['id'])->get()->toArray();
         $answer = array_merge($answer, ['commentNumber' => count($comments)]);
         array_push($result, $answer);
     }
     $question = array_merge($question, ['answers' => $result]);
     // 回答 最热门 三条
     //        ....
     return Utility::response_format(Utility::RESPONSE_CODE_SUCCESS, $question, '请求成功');
 }
 public function view($id)
 {
     if ($alert = Session::get('alert')) {
         $param['alert'] = $alert;
     }
     $param['pageNo'] = 61;
     $param['people'] = PeopleModel::find($id);
     $param['selectTags'] = TagPeopleModel::whereRaw('peopleId =?', array($id))->get();
     $param['project'] = ProjectModel::whereRaw('peopleId = ?', array($id))->get();
     $param['category'] = CategoryModel::whereRaw(true)->orderBy('category', 'asc')->get();
     $param['industry'] = IndustryModel::whereRaw(true)->orderBy('industry', 'asc')->get();
     $param['tags'] = TagsModel::whereRaw(true)->orderBy('tags', 'asc')->get();
     $param['company'] = CompanyModel::whereRaw(true)->orderBy('companyName', 'asc')->get();
     $param['type'] = TypeModel::whereRaw(true)->orderBy('type', 'asc')->get();
     $param['selectTags'] = TagPeopleModel::whereRaw('peopleId =?', array($id))->get();
     $param['members'] = MembersModel::whereRaw(true)->orderBy('first_name', 'asc')->get();
     $param['project'] = ProjectModel::whereRaw('peopleId =?', array($id))->get();
     $projectIDs = ProjectModel::whereRaw('peopleId =?', array($id))->get();
     $k = 0;
     $listQuote = array();
     for ($i = 0; $i < count($projectIDs); $i++) {
         $quotes = QuoteModel::whereRaw('projectId = ?', array($projectIDs[$i]->id))->get();
         for ($j = 0; $j < count($quotes); $j++) {
             $listQuote[$k] = $quotes[$j];
             $k++;
         }
     }
     $param['listQuote'] = $listQuote;
     $param['note'] = NoteModel::whereRaw('peopleId=?', array($id))->get();
     $note = NoteModel::whereRaw('peopleId=?', array($id))->get();
     $list = "";
     for ($i = 0; $i < count($note); $i++) {
         $list .= '<div class="col-md-12 margin-bottom-10 forest-change-note-header">';
         if (strtoupper($note[$i]->noteCommType->noteCommType) == "PHONE") {
             $list .= '<div class="panel panel-blue margin-bottom-20" >';
         } else {
             if (strtoupper($note[$i]->noteCommType->noteCommType) == "EMAIL") {
                 $list .= '<div class="panel panel-green margin-bottom-20" >';
             }
         }
         if (strtoupper($note[$i]->noteCommType->noteCommType) == "PHONE") {
             $list .= '<div class="panel-heading forest-panel-heading-note" style="background: #3498db; ">';
         } else {
             if (strtoupper($note[$i]->noteCommType->noteCommType) == "EMAIL") {
                 $list .= '<div class="panel-heading forest-panel-heading-note" style="background: #2ecc71;">';
             }
         }
         $list .= '<h3 class="panel-title forest-panel-title-note">';
         if (strtoupper($note[$i]->noteCommType->noteCommType) == "PHONE") {
             $list .= '<img src="/images/Modern-Phone-icon.jpg" style="width:30px; height:30px;">';
         } else {
             if (strtoupper($note[$i]->noteCommType->noteCommType) == "EMAIL") {
                 $list .= '<img src="/images/Email.png" style="width:30px; height:30px;">';
             }
         }
         $list .= '<span>(' . ucfirst($note[$i]->noteType->notesType) . ')</span>';
         $list .= '<span>(' . substr($note[$i]->updated_at, 0, 16) . ')</span>';
         $list .= '<span>(' . ucfirst($note[$i]->noteStatus->notesStatus) . ')</span>';
         $list .= ' </h3>
                             </div>
                             <div class="panel-body">';
         $list .= $note[$i]->notes;
         $list .= ' </div>
                          </div>
                       </div>';
     }
     $param['list'] = $list;
     return View::make('admin.contact.detail')->with($param);
 }
 public function main($id)
 {
     if ($alert = Session::get('alert')) {
         $param['alert'] = $alert;
     }
     $user_id = Session::get('user_id');
     $param['member'] = MembersModel::find($user_id);
     $param['people'] = PeopleModel::find($id);
     $param['category'] = CategoryModel::whereRaw(true)->orderBy('category', 'asc')->get();
     $param['industry'] = IndustryModel::whereRaw(true)->orderBy('industry', 'asc')->get();
     $param['tags'] = TagsModel::whereRaw(true)->orderBy('tags', 'asc')->get();
     $param['company'] = CompanyModel::whereRaw(true)->orderBy('companyName', 'asc')->get();
     $param['type'] = TypeModel::whereRaw(true)->orderBy('type', 'asc')->get();
     $param['selectTags'] = TagPeopleModel::whereRaw('peopleId =?', array($id))->get();
     $param['members'] = MembersModel::whereRaw(true)->orderBy('first_name', 'asc')->get();
     /****note base*******/
     $param['noteType'] = NoteTypeModel::whereRaw(true)->orderBy('notesType', 'asc')->get();
     $param['noteCommType'] = NoteCommTypeModel::whereRaw(true)->orderBy('noteCommType', 'asc')->get();
     $param['noteAssign'] = NoteAssignModel::whereRaw(true)->orderBy('noteAssign', 'asc')->get();
     $param['noteStatus'] = NoteStatusModel::whereRaw(true)->orderBy('notesStatus', 'asc')->get();
     $param['noteTypeDetails'] = NoteTypeDetailsModel::whereRaw(true)->orderBy('noteTypeDetails', 'asc')->get();
     /****note ***/
     $param['note'] = NoteModel::whereRaw('peopleId=?', array($id))->get();
     /******Projects****/
     $param['project'] = ProjectModel::whereRaw('peopleId =?', array($id))->get();
     $projectIDs = ProjectModel::whereRaw('peopleId =?', array($id))->get();
     $k = 0;
     $listQuote = array();
     for ($i = 0; $i < count($projectIDs); $i++) {
         $quotes = QuoteModel::whereRaw('projectId = ?', array($projectIDs[$i]->id))->get();
         for ($j = 0; $j < count($quotes); $j++) {
             $listQuote[$k] = $quotes[$j];
             $k++;
         }
     }
     $param['listQuote'] = $listQuote;
     $param['pageNo'] = "4";
     $peopleId = $id;
     $note = NoteModel::whereRaw('peopleId=?', array($peopleId))->get();
     $list = "";
     for ($i = 0; $i < count($note); $i++) {
         $list .= '<div class="col-md-12 margin-bottom-10 forest-change-note-header">';
         if (strtoupper($note[$i]->noteCommType->noteCommType) == "PHONE") {
             $list .= '<div class="panel panel-blue margin-bottom-20">';
         } else {
             if (strtoupper($note[$i]->noteCommType->noteCommType) == "EMAIL") {
                 $list .= '<div class="panel panel-green margin-bottom-20">';
             }
         }
         $list .= '<div class="panel-heading forest-panel-heading-note">';
         $list .= '<h3 class="panel-title forest-panel-title-note">';
         if (strtoupper($note[$i]->noteCommType->noteCommType) == "PHONE") {
             $list .= '<img src="/images/Modern-Phone-icon.jpg" style="width:30px; height:30px;">';
         } else {
             if (strtoupper($note[$i]->noteCommType->noteCommType) == "EMAIL") {
                 $list .= '<img src="/images/Email.png" style="width:30px; height:30px;">';
             }
         }
         $list .= '<a href = "javascript:void(0)" onclick = "onEditNoteChange(' . $note[$i]->id . ')">Edit</a>';
         $list .= '<span>(' . ucfirst($note[$i]->noteType->notesType) . ')</span>';
         $list .= '<span>(' . substr($note[$i]->updated_at, 0, 16) . ')</span>';
         $list .= '<span>(' . ucfirst($note[$i]->noteStatus->notesStatus) . ')</span>';
         $list .= ' </h3>
                             </div>
                             <div class="panel-body">';
         $list .= $note[$i]->notes;
         $list .= ' </div>
                          </div>
                       </div>';
     }
     $param['list'] = $list;
     return View::make('user.contact.main')->with($param);
 }