[opw-web] List user's projects on the user profile page



commit 59817b5b5b35509a8c10031bd6ad3291809b1207
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Tue Apr 1 10:56:55 2014 -0400

    List user's projects on the user profile page
    
    List the user's projects (sorted by program) on their profile page.
    For mentors/admins, show the status of the project and link to the
    organization manage projects page. The user themselves just sees a
    plain list.
    
    This is meant to be a place to make it easy to see what is going
    on for students who are submitting applications to multiple
    organizations.

 modules/mod_user_profile.php                       |   61 ++++++++++++++++++++
 skins/easterngreen/html/tpl_user_profile.html      |    7 ++
 .../html/tpl_user_profile_project.html             |   15 +++++
 .../html/tpl_user_profile_project_header.html      |    5 ++
 4 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/modules/mod_user_profile.php b/modules/mod_user_profile.php
index 11041aa..1d5985f 100644
--- a/modules/mod_user_profile.php
+++ b/modules/mod_user_profile.php
@@ -61,8 +61,67 @@ if ($action == 'view') {
                 ));
 
                 $identities_list .= $skin->output('tpl_user_profile_identity');
+        }
+
+        $sql = "SELECT prj.*, org.title as org_title from {$db->prefix}projects prj " .
+               "LEFT JOIN {$db->prefix}participants prt " .
+                   "ON prt.project_id = prj.id " .
+               "LEFT JOIN {$db->prefix}organizations org " .
+                   "ON prj.organization_id = org.id " .
+               "WHERE prt.username = ? AND prt.role = 's'" .
+               "ORDER BY prj.program_id DESC, prt.project_id";
+
+        $project_data = $db->query($sql, $username);
+        $program_id = null;
+
+        $projects_list = "";
+        $projects_visibility = false;
+
+        foreach ($project_data as $row)
+        {
+            if ($row['program_id'] != $program_id) {
+                $program_id = $row['program_id'];
+                $user->get_role($program_id, $role, $mentor_organization_id);
+                $program_data = $cache->get_program_data($program_id);
+                $shown_header = false;
             }
 
+            // This will do another DB query to see if the user owns the project; accept
+            // that to keep permissions logic unified.
+            $project_permissions = get_project_permissions($program_data, $role, $row);
+            if (!$project_permissions->can_view)
+                continue;
+
+            if (!$shown_header) {
+                $shown_header = true;
+                $projects_visibility = true;
+
+                $skin->assign(array(
+                    'program_title'      => $program_data['title'],
+                ));
+
+                $projects_list .= $skin->output('tpl_user_profile_project_header');
+            }
+
+            if ($role == 'm' || $user->is_admin) {
+                $org_opinion = $lang->get('opinion_' . $row['org_opinion']);
+                $organization = "<a 
href='?q=manage_projects&amp;prg={$program_id}&amp;o={$row['organization_id']}'>" . 
htmlspecialchars($row['org_title']) . "</a>";
+            } else {
+                $org_opinion = '';
+                $organization = htmlspecialchars($row['org_title']);
+            }
+
+            $skin->assign(array(
+                              'project_url'    => 
"?q=view_projects&amp;prg={$program_id}&amp;p={$row['id']}",
+                              'project_title'  => htmlspecialchars($row['title']),
+                              'badges'         => build_project_badges($role, $row, 0, 0),
+                              'organization'   => $organization,
+                              'opinion'        => $org_opinion,
+                              ));
+
+            $projects_list .= $skin->output('tpl_user_profile_project');
+        }
+
         $is_admin   = false;
         $avatar_url = "?q=user_avatar&amp;u={$username_encoded}";
         $edit_url = "?q=user_profile&amp;a=editor&amp;u={$username_encoded}";
@@ -83,10 +142,12 @@ if ($action == 'view') {
             'return_url'            => $return_url,
             'edit_url'              => $edit_url,
             'identities_list'       => $identities_list,
+            'projects_list'         => $projects_list,
             'profile_visibility'    => $skin->visibility(true),
             'notice_visibility'     => $skin->visibility(false),
             'edit_visibility'       => $skin->visibility($can_edit),
             'details_visibility'    => $skin->visibility($can_view_details),
+            'projects_visibility'   => $skin->visibility($projects_visibility),
             'contact_visibility'    => $skin->visibility(!$is_self && $can_view_details),
             'badge_visibility'      => $skin->visibility($is_admin),
             'return_visibility'     => $skin->visibility(empty($return_url), true),
diff --git a/skins/easterngreen/html/tpl_user_profile.html b/skins/easterngreen/html/tpl_user_profile.html
index 0d441e3..ec0a68e 100644
--- a/skins/easterngreen/html/tpl_user_profile.html
+++ b/skins/easterngreen/html/tpl_user_profile.html
@@ -65,6 +65,13 @@
       </tbody>
     </table>
 
+    <h4 class="[[projects_visibility]]">{{projects}} <span 
class="visibility-note">[[visible_to_mentors]]</span></h4>
+    <table class="table table-striped [[projects_visibility]]">
+      <tbody>
+        [[projects_list]]
+      </tbody>
+    </table>
+
     <div class="form-actions">
         <a href="[[edit_url]]" class="btn btn-primary [[edit_visibility]]">
             <i class="icon-pencil icon-white"></i>
diff --git a/skins/easterngreen/html/tpl_user_profile_project.html 
b/skins/easterngreen/html/tpl_user_profile_project.html
new file mode 100644
index 0000000..da971b8
--- /dev/null
+++ b/skins/easterngreen/html/tpl_user_profile_project.html
@@ -0,0 +1,15 @@
+<tr>
+    <td>
+        <a href="[[project_url]]">
+            [[project_title]]
+        </a>[[badges]]
+    </td>
+
+    <td>
+        [[organization]]
+    </td>
+
+    <td>
+        [[opinion]]
+    </td>
+</tr>
diff --git a/skins/easterngreen/html/tpl_user_profile_project_header.html 
b/skins/easterngreen/html/tpl_user_profile_project_header.html
new file mode 100644
index 0000000..1ad257d
--- /dev/null
+++ b/skins/easterngreen/html/tpl_user_profile_project_header.html
@@ -0,0 +1,5 @@
+<tr>
+    <th colspan="3">
+        [[program_title]]
+    </th>
+</tr>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]