Ejemplo n.º 1
0
 function prepare_items()
 {
     /* set up the columns */
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     /* set paging parameters */
     $per_page = ltp_options::get_admin_per_page('ltp_student_users_pp');
     $current_page = $this->get_pagenum();
     $offset = ($current_page - 1) * $per_page;
     /* set ordering parameters */
     $poss_orderby = array('first_name', 'last_name', 'user_login', 'user_email');
     $orderby = isset($_REQUEST["orderby"]) && in_array($_REQUEST["orderby"], $poss_orderby) ? $_REQUEST["orderby"] : 'last_name';
     $order = isset($_REQUEST["order"]) && in_array(strtoupper($_REQUEST["order"]), array('ASC', 'DESC')) ? strtoupper($_REQUEST["order"]) : 'ASC';
     $searchterm = isset($_REQUEST["s"]) && trim($_REQUEST["s"]) !== '' ? trim($_REQUEST["s"]) : '';
     /* build arguments to user query */
     $args = array('role' => 'student', 'number' => $per_page, 'offset' => $offset, 'fields' => 'all_with_meta', 'count_total' => true);
     if ($searchterm !== '') {
         $args['meta_query'] = array('relation' => 'OR', array('key' => 'first_name', 'value' => $searchterm, 'compare' => 'LIKE'), array('key' => 'last_name', 'value' => $searchterm, 'compare' => 'LIKE'));
     }
     if ($orderby) {
         switch ($orderby) {
             case 'first_name':
             case 'last_name':
                 $args['orderby'] = 'meta_value';
                 $args['meta_key'] = $orderby;
                 break;
             default:
                 $args['orderby'] = $orderby;
         }
         $args['order'] = $order;
     }
     /* query users */
     $user_query = new WP_User_Query($args);
     /* get total users */
     $total_items = $user_query->get_total();
     /* get results */
     $wpp_users = $user_query->get_results();
     /* get additional data */
     /* get people pages */
     $people_pages = get_posts(array('post_type' => 'people', 'numberposts' => -1, 'nopaging' => true, 'post_status' => 'any'));
     /* map people page IDs to usernames */
     $pages_map = array();
     foreach ($people_pages as $pp) {
         $wp_username = get_post_meta($pp->ID, 'wp_username', true);
         if ($wp_username) {
             $pages_map[$wp_username] = $pp;
         }
     }
     /* build items for table */
     $this->items = array();
     if (!empty($user_query->results)) {
         foreach ($user_query->results as $user) {
             $userdata = ltp_template::get_user_data($user);
             $student_user = array();
             $student_user["ID"] = $user->ID;
             $student_user["first_name"] = $user->first_name;
             $student_user["last_name"] = $user->last_name;
             $student_user["user_login"] = $user->user_login;
             $student_user["user_email"] = $user->user_email;
             $student_user["showcase_count"] = 0;
             $student_user["downloads_count"] = 0;
             $student_user["cv_uploaded"] = false;
             $student_user["profile_url"] = '';
             $student_user["profile_views"] = 0;
             /* get data related to profile publishing status */
             if (!isset($pages_map[$user->user_login])) {
                 $student_user["profile_status"] = "Not started";
             } else {
                 /* find out how much has been done on the profile */
                 for ($i = 1; $i < 4; $i++) {
                     if (trim($userdata["showcase" . $i . "_title"]) !== '' || trim($userdata["showcase" . $i . "_text"]) !== '' || trim($userdata["showcase" . $i . "_image"]) !== '' || trim($userdata["showcase" . $i . "_file"]) !== '' || trim($userdata["showcase" . $i . "_video"]) !== '') {
                         $student_user["showcase_count"]++;
                     }
                 }
                 if (!empty($userdata["cv"])) {
                     $student_user["cv_uploaded"] = true;
                     $student_user["downloads_count"] = ltp_data::get_downloads($pages_map[$user->user_login]->ID);
                 }
                 /* set status, view count and URL */
                 if ($pages_map[$user->user_login]->post_status == "publish") {
                     $student_user["profile_status"] = "Published";
                     $student_user["profile_url"] = get_permalink($pages_map[$user->user_login]->ID);
                 } else {
                     $student_user["profile_status"] = "Draft";
                 }
                 $student_user["profile_views"] = ltp_data::get_views($pages_map[$user->user_login]->ID);
             }
             //print('<pre>' . print_r($student_user, true) . '</pre>');
             array_push($this->items, $student_user);
         }
     }
 }
ltp_data::save_actions();
get_header();
print '<div class="section sticky toolbar">';
global $current_user;
$previous_login_date = ltp_data::get_previous_login($current_user->ID);
$profiles_added = ltp_data::get_profiles_added_since($previous_login_date);
print ltp_template::wpp_toolbar($current_user->ID, $previous_login_date, $profiles_added);
print '</div>';
print '<div class="ltp-profiles">';
if (count($people_pages)) {
    // get all students
    $students = array();
    $users = get_users(array('role' => 'student', 'fields' => 'all'));
    if (count($users)) {
        foreach ($users as $user) {
            $students[$user->user_login] = ltp_template::get_user_data($user);
        }
    }
    // apply filters on $students to see which pages are to be displayed
    //$to_display = apply_filters( 'ltp_results', $students );
    $count = 0;
    // loop through people pages displaying users
    foreach ($people_pages as $post) {
        $username = get_post_meta($post->ID, 'wp_username', true);
        if (in_array($username, array_keys($students))) {
            // display user data
            if (trim($students[$username]["firstname"]) !== '' && trim($students[$username]["surname"]) !== '') {
                $latest = false;
                foreach ($profiles_added as $newprofile) {
                    if ($post->ID == $newprofile->ID) {
                        $latest = true;