Exemplo n.º 1
0
 function getSchoolAction()
 {
     $request = $this->getRequest();
     //print_r($request->getMethod());
     // die();
     if ('POST' == $request->getMethod()) {
         //var_dump($this->post());
         $ssotoken = $this->post("ssotoken");
         //->get();
         $type = $this->post()->get("type");
         $schoolId = $this->post()->get("schoolId");
         //die($ssotoken);
     } else {
         //$ssotoken = "token439f0036-e5c7-4053-a48e-0c23c91ec41epylmt67C";
         $ssotoken = $this->get("ssotoken");
         $type = $this->get("type");
         $schoolId = $this->get("schoolId");
     }
     $type = $type ? $type : 1;
     if (!$ssotoken || !$type) {
         $this->displayJsonUdo(Common_Error::ERROR_PARAM);
     }
     if ($type == 4 && !$schoolId) {
         $this->displayJsonUdo(Common_Error::ERROR_PARAM, "", "缺失参数schoolId");
     }
     $url = Common_Config::SSO_SCHOOL_URL;
     $post_data = array("ssotoken" => $ssotoken);
     //获取用户id
     $userModel = new UserModel();
     $schoolModel = new SchoolModel();
     $uid = $userModel->getUserId($ssotoken);
     if (is_array($uid)) {
         $this->displayJsonUdo(Common_Error::INVALID_TOKEN, "", $uid['msg']);
     }
     $cl = new Common_Curl();
     $array = $cl->request($url, $post_data);
     if (array_key_exists('code', $array) && $array['code'] == 0) {
         $this->displayJsonUdo(Common_Error::ERROR_FAIL, null, "SSO没有返回可以浏览的频道噢~");
     }
     $result = [];
     $newArray = [];
     //如果用户是请求所有频道
     if ($type == 1) {
         //获取到频道后,开始进行频道过滤
         //从本版本开始暂不进行频道过滤
         //$result = $schoolModel->schoolFilter($array);
         //过滤后的频道进行排序
         $result = $schoolModel->schoolOrder($array);
         //print_r($result);
         //print_r($result);
         //过滤后的结果去掉BaseUrl
     } elseif ($type == 3 || $type == 2) {
         $result = $schoolModel->getSubscribe($array['entrances'], $uid, $type);
     } elseif ($type == 4) {
         $result = $schoolModel->getSingleSchool($uid, $schoolId, $array['entrances']);
         if ($result == -1) {
             $this->displayJsonUdo(Common_Error::ERROR_FAIL, "", "没有返回有效的频道信息噢~");
         }
     }
     //测试用index
     // $i = 0;
     //在返回的频道列表中的每一项上附加上订阅信息
     foreach ($result as $k => $val) {
         //print_r($val);
         if (is_array($val)) {
             //测试用数据
             //$val['isAuthorized']= $val['isAuthorized']?0:1;
             if ($type == 2) {
                 $val = array_merge($val, array("isSubscribed" => 1));
             } else {
                 $val = array_merge($val, array("isSubscribed" => $schoolModel->getIfSub($val['id'], $uid) ? 1 : 0));
             }
             //附加频道的定价信息
             $val = array_merge($val, $schoolModel->getSchoolPrice($val['id'], $uid));
             //将SSO返回的无用字段过滤掉
             $index = 0;
             while ($key = key($val)) {
                 if ($key == "apiBaseUrl") {
                     array_splice($val, $index, 1);
                     break;
                 }
                 $index++;
                 next($val);
             }
         }
         $newArray[$k] = $val;
     }
     if ($type == 4) {
         $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, $newArray[0]);
     }
     $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, $newArray);
 }