function followuAction()
 {
     $set = array("UID" => $_POST["UID"], "FUID" => $_POST["FUID"], "time" => date('Y-m-d h:i:s'));
     $followu = new followU();
     $followu->insertFollowU($set);
     $this->render("followu");
     return 1;
 }
 public function searchAction()
 {
     function modify($s)
     {
         $s = "%" . $s . "%";
         for ($i = 0; $i < strlen($s); $i++) {
             if ($s[$i] == ' ') {
                 $s[$i] = '%';
             }
         }
         return $s;
     }
     function my_sort1($a, $b)
     {
         // sort question by follownum first and then answernum
         if ($a['follownum'] == $b['follownum']) {
             if ($a['answernum'] == $b['answernum']) {
                 return 0;
             } else {
                 return $a['answernum'] < $b['answernum'] ? 1 : -1;
             }
         }
         return $a['follownum'] < $b['follownum'] ? 1 : -1;
     }
     function my_sort2($a, $b)
     {
         // sort user by likenum
         if ($a['likenum'] == $b['likenum']) {
             return 0;
         } else {
             return $a['likenum'] < $b['likenum'] ? 1 : -1;
         }
     }
     $perpage = 10;
     //question number per page
     if ($_GET) {
         // get front-data
         $data = $this->getRequest()->getParam('key', '');
         $key = $data = trim($data);
         $data = modify($data);
         $P = $this->getRequest()->getParam('P', '1');
     }
     //file_put_contents ( "2.txt", $data );
     $result = array();
     if ($data == '') {
         $this->render('searchresult');
         return -1;
     }
     /*
      * search for question
      *
      */
     //file_put_contents ( "1.txt", "search2" );
     $search = new question();
     $result = $search->searchQestion($data);
     $answer = new answer();
     $followQ = new followQ();
     $question = new question();
     $tag = new tag();
     $ask = new ask();
     for ($i = 0; $i < count($result); $i++) {
         $result[$i]['time'] = $ask->getAskTimebyQID($result[$i]['QID']);
         $result[$i]['answernum'] = $answer->getAnswernumbyQID($result[$i]['QID']);
         $result[$i]['follownum'] = $followQ->getFollownumbyQID($result[$i]['QID']);
         $result[$i]['tag'] = $tag->getTagbyQID($result[$i]['QID']);
     }
     usort($result, "my_sort1");
     // sort question by follownum first and then answernum
     //print_r($result);
     //$_SESSION["$key"] = $result;
     $sum = count($result);
     $Pnum = floor($sum / $perpage);
     if ($sum % $perpage > 0) {
         $Pnum++;
     }
     $presult = array();
     $length = min($P * $perpage, $sum);
     for ($i = ($P - 1) * $perpage; $i < $length; $i++) {
         $presult[$i] = $result[$i];
     }
     $this->view->P = $P;
     $this->view->Pnum = $Pnum;
     $this->view->Qresult = $presult;
     /*
      * search for user
      * 
      */
     session_start();
     $loginuser = $_SESSION['user'];
     $UID = $loginuser['UID'];
     $followu = new followU();
     $farr = $followu->getFUIDsbyUID($UID);
     if ($P > 1) {
         $this->view->Uresult = array();
     } else {
         $search = new user();
         $result = $search->searchUser($data);
         $likeA = new likeA();
         $likeC = new likeC();
         $likeQ = new likeQ();
         $answer = new answer();
         for ($i = 0; $i < count($result); $i++) {
             $isfollow = false;
             $result[$i]['likenum'] = $this->getLikedNumByUID($result[$i]['UID']);
             //$result[$i]['likenum']+=$likeC->getLikenumbyUID($result[$i]['UID']);
             //$result[$i]['likenum']+=$likeQ->getLikenumbyUID($result[$i]['UID']);
             $result[$i]['answernum'] = $answer->getAnswernumbyUID($result[$i]['UID']);
             for ($j = 0; $j < count($farr); $j++) {
                 if ($farr[$j] == $result[$i]['UID']) {
                     $isfollow = true;
                     break;
                 }
             }
             $result[$i]['isfollow'] = $isfollow;
         }
         usort($result, "my_sort2");
         //sort user by likenum
         $this->view->Uresult = $result;
     }
     $this->view->key = $key;
     $this->view->url = "/search/search";
     $this->render('searchresult');
     //
     //file_put_contents ( "1.txt", "search3" );
 }
 public function answerAction()
 {
     session_start();
     if (isset($_SESSION['user'])) {
         $loginuser = $_SESSION['user'];
     } else {
         $loginuser = array('UID' => -1);
     }
     #名字要根据login的控制器改过来
     $UID = $loginuser['UID'];
     //if($_GET['P'] != null)
     //$APage=$_GET['P'];   #从前端获取ask的页码
     //else $APage=1;
     $APage = 1;
     //$UID=2;
     $this->view->PersonalInfo = array('UID' => $UID, 'image' => '');
     #$loginuser['image']);
     #$MUID=$this->getRequest()->getParam('MUID','');  #从前端的获取被访问者的UID
     $MUID = $_GET['UID'];
     $user = new user();
     $info = $user->getAllbyUID($MUID);
     $answer_tmp = new answer();
     $likeQ = new likeQ();
     $likeA = new likeA();
     $followu = new followU();
     $follownum = $followu->getFollownumbyUID($MUID);
     $followednum = $followu->getFollownumbyFUID($MUID);
     $farr = $followu->getFUIDsbyUID($UID);
     $isfollow = false;
     for ($i = 0; $i < count($farr); $i++) {
         if ($farr[$i] == $MUID) {
             $isfollow = true;
             break;
         }
     }
     $this->view->pinfo = array('UID' => $MUID, 'nickname' => $info['nickname'], 'sex' => $info['sex'], 'image' => $info['image'], 'institute' => $info['institute'], 'grade' => $info['grade'], 'answernum' => $answer_tmp->getAnswernumbyUID($MUID), 'likenum' => $this->getLikedNumByUID($MUID), 'follownum' => $follownum, 'followednum' => $followednum, 'isfollow' => $isfollow);
     $question = new question();
     $answer_tmp1 = new answer();
     $answer = array();
     $tag = new tag();
     $followq = new followQ();
     $AIDs = $answer_tmp1->getAIDsbyUID($MUID);
     $Anum = count($AIDs);
     $AID_Time_tmp = array();
     $m = 0;
     #为answer数组计数用
     for ($i = 0; $i < $Anum; $i++) {
         $AID_Time_tmp[$AIDs[$i]] = $answer_tmp1->getTimebyAID($AIDs[$i]);
     }
     arsort($AID_Time_tmp);
     foreach ($AID_Time_tmp as $aid => $time) {
         $a = $answer_tmp1->getAllbyAID($aid);
         $qid = $a['QID'];
         $answer[$m] = array('QID' => $qid, 'title' => $question->getAllbyQID($qid)['qtitle'], 'abstract' => $question->getAllbyQID($qid)['Qabstract'], 'Aabstract' => $a['AAbstract'], 'Atime' => $a['time'], 'follownum' => $followq->getFollownumbyQID($qid), 'answernum' => $answer_tmp->getAnswernumbyQID($qid), 'tag' => $tag->getTagbyQID($qid));
         $m++;
     }
     if ($Anum % 10 == 0) {
         $this->view->Pnum = $Anum / 10;
     } else {
         $this->view->Pnum = $Anum / 10 + 1;
     }
     $this->view->answer = array_slice($answer, ($APage - 1) * 10, 10);
     $this->view->url = "/personal/answer?UID={$MUID}&";
     $this->render("homepage-answer");
 }