Example #1
0
 /**
  * test User Business Logic
  * @return [type] [description]
  */
 public function testUserBiz()
 {
     $userBo = new UserBO();
     $userBo->setId(1);
     $userBo->setUsername('hongker');
     $userBo->setPassword('my pass');
     $userBiz = new UserBiz();
     $newPass = 'new pass';
     $this->assertTrue($userBiz->changePass($userBo, $newPass));
     $this->assertEquals($newPass, $userBo->getPassword());
 }
Example #2
0
 /**
  * @RequestMapping(value="/user/{id:[0-9]+}", method="GET", produces="application/json")
  */
 public function user($request, $response)
 {
     $id = $request->getAttribute('id');
     $user = UserBO::getUser($id);
     $response->write($user->toJson());
 }
Example #3
0
 public function search($view, $para)
 {
     try {
         $paraSQL = [];
         $sqlSelectAll = "SELECT u.* ";
         $sqlSelectCount = "SELECT COUNT(*) as countUser ";
         //para: orderby, order, page, s, paged, users, new_role, new_role2, action, action2
         $sqlFrom = " FROM " . TABLE_USERS . " AS u, " . TABLE_USERMETA . " AS m ";
         $sqlWhere = " WHERE m." . TB_USERMETA_COL_USER_ID . " = u." . TB_USERS_COL_ID . " \n            AND m." . TB_USERMETA_COL_META_KEY . " = '" . WP_CAPABILITIES . "'\n            AND user_status != " . USER_STATUS_DELETED;
         if (isset($para->s) && strlen(trim($para->s)) > 0) {
             $sqlWhere .= "  AND (u." . TB_USERS_COL_USER_LOGIN . " like :s OR\n                                u." . TB_USERS_COL_DISPLAY_NAME . " like :s OR\n                                u." . TB_USERS_COL_USER_EMAIL . " like :s ) ";
             $paraSQL[':s'] = "%" . $para->s . "%";
             $view->s = $para->s;
         }
         $view->orderby = "login";
         $view->order = "asc";
         if (isset($para->orderby) && in_array($para->orderby, array("login", "name", "email"))) {
             switch ($para->orderby) {
                 case "login":
                     $para->orderby = TB_USERS_COL_USER_LOGIN;
                     $view->orderby = "login";
                     break;
                 case "name":
                     $para->orderby = TB_USERS_COL_DISPLAY_NAME;
                     $view->orderby = "name";
                     break;
                 case "email":
                     $para->orderby = TB_USERS_COL_USER_EMAIL;
                     $view->orderby = "email";
                     break;
             }
             if (isset($para->order) && in_array($para->order, array("desc", "asc"))) {
                 $view->order = $para->order;
             } else {
                 $para->order = "asc";
                 $view->order = "asc";
             }
             $sqlOrderby = " ORDER BY u." . $para->orderby . " " . $para->order;
         } else {
             $sqlOrderby = " ORDER BY u." . TB_USERS_COL_USER_LOGIN . " ASC";
         }
         $view->count = array(FILTER_USERS_LIST_ALL_TITLE => 0, CAPABILITY_ADMINISTRATOR => 0, CAPABILITY_SUBSCRIBER => 0, CAPABILITY_CONTRIBUTOR => 0, CAPABILITY_AUTHOR => 0, CAPABILITY_EDITOR => 0);
         $sqlCount = $sqlSelectCount . $sqlFrom . $sqlWhere;
         $sth = $this->db->prepare($sqlCount);
         $sth->execute($paraSQL);
         $countUser = (int) $sth->fetch()->countUser;
         $view->pageNumber = 0;
         $view->page = 1;
         $sqlLimit = "";
         if ($countUser > 0) {
             $view->count[FILTER_USERS_LIST_ALL_TITLE] = $countUser;
             $sqlCountAdmin = $sqlSelectCount . $sqlFrom . $sqlWhere . " AND m." . TB_USERMETA_COL_META_VALUE . " = '" . CAPABILITY_ADMINISTRATOR . "'";
             $sth = $this->db->prepare($sqlCountAdmin);
             $sth->execute($paraSQL);
             $view->count[CAPABILITY_ADMINISTRATOR] = (int) $sth->fetch()->countUser;
             $sqlCountAdmin = $sqlSelectCount . $sqlFrom . $sqlWhere . " AND m." . TB_USERMETA_COL_META_VALUE . " = '" . CAPABILITY_EDITOR . "'";
             $sth = $this->db->prepare($sqlCountAdmin);
             $sth->execute($paraSQL);
             $view->count[CAPABILITY_EDITOR] = (int) $sth->fetch()->countUser;
             $sqlCountAdmin = $sqlSelectCount . $sqlFrom . $sqlWhere . " AND m." . TB_USERMETA_COL_META_VALUE . " = '" . CAPABILITY_AUTHOR . "'";
             $sth = $this->db->prepare($sqlCountAdmin);
             $sth->execute($paraSQL);
             $view->count[CAPABILITY_AUTHOR] = (int) $sth->fetch()->countUser;
             $sqlCountAdmin = $sqlSelectCount . $sqlFrom . $sqlWhere . " AND m." . TB_USERMETA_COL_META_VALUE . " = '" . CAPABILITY_CONTRIBUTOR . "'";
             $sth = $this->db->prepare($sqlCountAdmin);
             $sth->execute($paraSQL);
             $view->count[CAPABILITY_CONTRIBUTOR] = (int) $sth->fetch()->countUser;
             $sqlCountAdmin = $sqlSelectCount . $sqlFrom . $sqlWhere . " AND m." . TB_USERMETA_COL_META_VALUE . " = '" . CAPABILITY_SUBSCRIBER . "'";
             $sth = $this->db->prepare($sqlCountAdmin);
             $sth->execute($paraSQL);
             $view->count[CAPABILITY_SUBSCRIBER] = (int) $sth->fetch()->countUser;
             $userLoginBO = json_decode(Session::get("userInfo"));
             $users_per_page = USERS_PER_PAGE_DEFAULT;
             if ($userLoginBO != NULL) {
                 if (isset($userLoginBO->users_per_page) && is_numeric($userLoginBO->users_per_page)) {
                     $users_per_page = (int) $userLoginBO->users_per_page;
                 }
             }
             if (!isset($users_per_page)) {
                 if (!isset($_SESSION['options'])) {
                     $_SESSION['options'] = new stdClass();
                     $_SESSION['options']->users_per_page = USERS_PER_PAGE_DEFAULT;
                     $users_per_page = USERS_PER_PAGE_DEFAULT;
                 } elseif (!isset($_SESSION['options']->users_per_page)) {
                     $_SESSION['options']->users_per_page = USERS_PER_PAGE_DEFAULT;
                     $users_per_page = USERS_PER_PAGE_DEFAULT;
                 }
             }
             $view->count[NUMBER_SEARCH_USER] = $view->count[FILTER_USERS_LIST_ALL_TITLE];
             $view->role = "-1";
             if (isset($para->role) && in_array($para->role, array(CAPABILITY_ADMINISTRATOR, CAPABILITY_EDITOR, CAPABILITY_AUTHOR, CAPABILITY_CONTRIBUTOR, CAPABILITY_SUBSCRIBER))) {
                 $sqlWhere .= " AND m." . TB_USERMETA_COL_META_VALUE . "= '" . $para->role . "' ";
                 $view->count[NUMBER_SEARCH_USER] = $view->count[$para->role];
                 $view->role = $para->role;
             }
             if ($view->count[NUMBER_SEARCH_USER] > 0) {
                 $view->pageNumber = floor($view->count[NUMBER_SEARCH_USER] / $users_per_page);
                 if ($view->count[NUMBER_SEARCH_USER] % $users_per_page != 0) {
                     $view->pageNumber++;
                 }
                 if (isset($para->page)) {
                     try {
                         $page = (int) $para->page;
                         if ($para->page <= 0) {
                             $page = 1;
                         }
                     } catch (Exception $e) {
                         $page = 1;
                     }
                 } else {
                     $page = 1;
                 }
                 if ($page > $view->pageNumber) {
                     $page = $view->pageNumber;
                 }
                 $view->page = $page;
                 $startUser = ($page - 1) * $users_per_page;
                 $sqlLimit = " LIMIT " . $users_per_page . " OFFSET " . $startUser;
                 $sqlAll = $sqlSelectAll . $sqlFrom . $sqlWhere . $sqlOrderby . $sqlLimit;
                 $sth = $this->db->prepare($sqlAll);
                 $sth->execute($paraSQL);
                 $count = $sth->rowCount();
                 if ($count > 0) {
                     $userList = $sth->fetchAll();
                     for ($i = 0; $i < sizeof($userList); $i++) {
                         $userInfo = $userList[$i];
                         $this->autoloadBO('user');
                         $userBO = new UserBO();
                         $userBO->setUserInfo($userInfo);
                         $userMetaInfoArray = $this->getMetaInfo($userInfo->ID);
                         $userBO->setUserMetaInfo($userMetaInfoArray);
                         $userList[$i] = $userBO;
                     }
                     $view->userList = $userList;
                 } else {
                     $view->userList = NULL;
                 }
             } else {
                 $view->userList = NULL;
                 $view->page = 0;
             }
         } else {
             $view->userList = NULL;
         }
     } catch (Exception $e) {
         $view->userList = NULL;
     }
 }