示例#1
0
 public function mainAction()
 {
     //封装header
     $auth = Zend_Auth::getinstance();
     #获取auth用户实例
     $auth->getIdentity();
     #取得当前用户信息
     $email = $auth->getIdentity();
     //$this->view->code = $email;
     //$this->render('test');
     //exit(0);
     #$email = '*****@*****.**';
     $muser = new user();
     $quser = $muser->getAllbyEmail($email);
     $header = array("UID" => $quser[0]["UID"], "image" => $quser[0]["image"]);
     $mode = $this->getRequest()->getParam("mode", "0");
     $page = $this->getRequest()->getParam("P", "1");
     $mtag = new tag();
     $tag = $mtag->getAllTags();
     $mans = new answer();
     $mask = new ask();
     $mquestion = new question();
     $mfollowq = new followQ();
     $likec = new likeC();
     //lefter
     //Qlist
     $Qlist[0] = 0;
     if ($mode == 1) {
         $pnum = $mans->getAQnum();
     } else {
         $pnum = $mquestion->getQuestionnum();
     }
     $pend = ($pnum - $pnum % 10) / 10;
     if ($pnum % 10 != 0) {
         $pend++;
     }
     if ($page == $pend) {
         $start = ($page - 1) * 10 + 1;
         $end = $pnum;
     } else {
         $start = ($page - 1) * 10 + 1;
         $end = $page * 10;
     }
     if ($mode == 1) {
         $mQID = $mans->getMostAnsweredQID($start, $end);
     } else {
         $mQID = $mask->getNewest($start, $end);
     }
     $qnum = count($mQID);
     for ($i = 0; $i < $qnum; $i++) {
         $likea = new likeA();
         $QID[$i] = $mQID[$i];
         $question = $mquestion->getAllbyQID($QID[$i]);
         $title = $question["qtitle"];
         $time = $mask->getAskTimebyQID($QID[$i]);
         $answernum = $mans->getAnswernumbyQID($QID[$i]);
         $follownum = $mfollowq->getFollownumbyQID($QID[$i]);
         $tag = $mtag->getTagbyQID($QID[$i]);
         $AIDs = $mans->getAIDsbyQID($QID[$i]);
         if ($answernum != 0) {
             $likenum = $likea->getLikenumbyAID($AIDs[0]);
             $num = $AIDs[0];
             for ($j = 0; $j < count($AIDs); $j++) {
                 $now = $likea->getLikenumbyAID($AIDs[$j]);
                 if ($now > $likenum) {
                     $likenum = $now;
                     $num = $AIDs[$j];
                 }
             }
             $AID = $num;
             $UIDtmp = $mans->getUIDbyAID($AID);
             $usernow = $muser->getAllbyUID($UIDtmp);
             $AUID = $usernow["UID"];
             $Aimage = $usernow["image"];
             $Aabstract = $mans->getAbstractbyAID($AID);
         } else {
             $AUID = 0;
             $Aimage = 0;
             $Aabstract = 0;
         }
         $Qlist[$i] = array("QID" => $QID[$i], "title" => $title, "time" => $time, "answernum" => $answernum, "follownum" => $follownum, "tag" => $tag, "AUID" => $AUID, "Aimage" => $Aimage, "Aabstract" => $Aabstract);
     }
     //HotUlist
     $huser = $mans->getMostAnsweredUID(1, 3);
     for ($i = 0; $i < count($huser); $i++) {
         $uu = $muser->getAllbyUID($huser[$i]);
         $HotUlist[$i]["UID"] = $uu["UID"];
         $HotUlist[$i]["image"] = $uu["image"];
         $HotUlist[$i]["nickname"] = $uu["nickname"];
         $HotUlist[$i]["answernum"] = $mans->getAnswernumbyUID($uu["UID"]);
         $HotUlist[$i]["likenum"] = $this->getLikedNumByUID($uu["UID"]);
     }
     //HotQlist
     $hquestion = $mans->getMostAnsweredQID(1, 6);
     for ($i = 0; $i < count($hquestion); $i++) {
         $qq = $mquestion->getAllbyQID($hquestion[$i]);
         $HotQlist[$i]["QID"] = $qq["QID"];
         $HotQlist[$i]["title"] = $qq["qtitle"];
         $HotQlist[$i]["follownum"] = $mfollowq->getFollownumbyQID($qq["QID"]);
         $HotQlist[$i]["answernum"] = $mans->getAnswernumbyQID($qq["QID"]);
     }
     $lefter = array("Qlist" => $Qlist, "hotUlist" => $HotUlist, "hotQlist" => $HotQlist);
     $this->view->lefter = $lefter;
     $this->view->header = $header;
     $this->view->url = '/index/main';
     $this->view->P = $page;
     $this->view->Pnum = $pend;
     $this->view->mode = $mode;
     $this->render('main');
 }