--- C:\Documents and Settings\williamj\Desktop\classroom-1.x-dev\classroom.views.inc	Tue Oct 12 15:46:42 2010
+++ C:\Documents and Settings\williamj\Desktop\classroom\classroom.views.inc	Tue Oct 12 15:44:42 2010
@@ -1,21 +1,40 @@
 <?php 
-// $Id: classroom.views.inc,v 1.5 $
+// $Id: classroom.views.inc,v 1.1 $
+
+/**
+ *
+ * Created by Will Jaspers, NuAire, Inc.
+ *
+ * v1.1 - Exposed most data to views
+ *	Known Issues: 
+ *    Cannot filter on CLASSROOM_<ROLE>
+ *    Ignored classroom_signup_request table until it is fixed up.
+ *    Finding certain nodes by type may require a 'Relationship' filter in Views.
+ *    Base tables are exposed, although they may be ultimately unnecessary.
+ *
+ * v1.0 - Initial dev release 
+ *
+ */
 
 function classroom_views_data()
 {
   $data = array();
   
   
-  
   // --------------------- COURSES ------------------ //
   
   
-  
   // The 'group' index will be used as a prefix in the UI for any of this
   // table's fields, sort criteria, etc. so it's easy to tell where they came
   // from.
   $data['classroom_course']['table']['group'] = t('Classroom');
   
+  $data['classroom_course']['table']['base'] = array(
+    'field' => 'nid',
+    'title' => t('Classroom: Courses'),
+    'help' => t("Courses within our classroom."),
+  );
+  
   // This table references the {node} table.
   // This creates an 'implicit' relationship to the node table, so that when 'Node'
   // is the base table, the fields are automatically available.
@@ -27,15 +46,36 @@
       'left_field' => 'nid',
       'field' => 'nid',
     ),
-    'role' => array(
-      'left_field' => 'rid',
-      'field' => 'access_by_rid'
+  );
+
+  $data['classroom_course']['nid'] = array(
+    'title' => t('Course: ID'),
+    'help' => t('The Course ID.'),
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_numeric',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_node_nid',
+      'name field' => 'title', 
+      'numeric' => TRUE,
+      'validate type' => 'nid',
+    ),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Course ID'),
+      'base' => 'node',
+      'base field' => 'nid',
+      'skip base' => array(),
     ),
   );
   
-  /** 
-   * Data for courses
-   */
   $data['classroom_course']['start_t'] = array(
     'title' => t('Course: Start Date'),
     'help' => t('When class begins.'),
@@ -50,6 +90,7 @@
       'handler' => 'views_handler_filter_date',
     ),
   );
+  
   $data['classroom_course']['end_t'] = array(
     'title' => t('Course: End Date'),
     'help' => t('When class ends.'),
@@ -64,6 +105,7 @@
       'handler' => 'views_handler_filter_date',
     ),
   );
+  
   $data['classroom_course']['registration_start'] = array(
     'title' => t('Course: Registration Start'),
     'help' => t('When class is available for registration.'),
@@ -78,6 +120,7 @@
       'handler' => 'views_handler_filter_date',
     ),
   );
+  
   $data['classroom_course']['registration_end'] = array(
     'title' => t('Course: Registration End Date'),
     'help' => t('When class is no longer available for registration.'),
@@ -92,28 +135,12 @@
       'handler' => 'views_handler_filter_date',
     ),
   );
-  $data['classroom_course']['course_tid'] = array(
-    'title' => t('Course: ID'),
-    'help' => t('The ID of this course.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_numeric',
-    ),
-  );
+
   $data['classroom_course']['access_by_rid'] = array(
     'title' => t('Course: Role ID'),
     'help' => t('The role ID that may access this course.'),
     'field' => array(
-      'handler' => 'views_handler_field_numeric',
+      'handler' => 'views_handler_field',
       'click sortable' => TRUE,
     ),
     'sort' => array(
@@ -125,33 +152,46 @@
     'argument' => array(
       'handler' => 'views_handler_argument_numeric',
     ),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Role ID'),
+      'base' => 'role',
+      'base field' => 'rid',
+    ),
   );
-  $data['classroom_course']['name'] = array(
-    'title' => t('Course: Role Name'),
-    'help' => t('The Name of the role which may access this course.'),
+  
+  $data['classroom_course']['use_grade_percentages'] = array(
+    'title' => t('Course: Use grade Percentages'),
+    'help' => t('Whether or not this course weighs assignments by percentage.'),
     'field' => array(
-      'handler' => 'views_handler_field',
+      'handler' => 'views_handler_field_boolean',
       'click sortable' => TRUE,
     ),
     'sort' => array(
       'handler' => 'views_handler_sort',
     ),
     'filter' => array(
-      'handler' => 'views_handler_filter_string',
+      'handler' => 'views_handler_filter_boolean_operator',
+      'label' => t('Uses Grade Percentages'),
+      'type' => 'yes-no',
     ),
   );
   
   
-  
   // --------------------- ASSIGNMENTS ------------------ //
   
   
-  
   // The 'group' index will be used as a prefix in the UI for any of this
   // table's fields, sort criteria, etc. so it's easy to tell where they came
   // from.
   $data['classroom_assignment']['table']['group'] = t('Classroom');
   
+  $data['classroom_assignment']['table']['base'] = array(
+    'field' => 'nid',
+    'title' => t('Classroom: Course Assignments'),
+    'help' => t("Assignments given to a course."),
+  );
+  
   // This table references the {node} table.
   // This creates an 'implicit' relationship to the node table, so that when 'Node'
   // is the base table, the fields are automatically available.
@@ -163,17 +203,59 @@
       'left_field' => 'nid',
       'field' => 'nid',
     ),
-    'classroom_topic' => array(
-      'left_field' => 'tid',
-      'field' => 'topic_tid'
+    'classroom_course' => array(
+      'left_field' => 'nid',
+      'field' => 'course_nid',
     ),
   );
 
+  $data['classroom_assignment']['nid'] = array(
+    'title' => t('Assignment: ID'),
+    'help' => t('The assignment ID.'),
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_numeric',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_node_nid',
+      'name field' => 'title', 
+      'numeric' => TRUE,
+      'validate type' => 'nid',
+    ),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Node ID'),
+      'base' => 'node',
+      'base field' => 'nid',
+      'skip base' => array('classroom_assignment','node'),
+    ),
+  );
   
-  /** 
-   * Data for assignments
-   */
-  $data['classroom_assignment']['end_date'] = array(
+  $data['classroom_assignment']['course_nid'] = array(
+    'title' => t('Course: ID'),
+    'help' => t('The Course ID associated with an assignment.'),
+    'sort' => array(
+      'handler' => 'views_handler_sort_numeric',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Course ID'),
+      'base' => 'classroom_course',
+      'base field' => 'nid',
+      'skip base' => array('node'),
+    ),
+  );
+
+  $data['classroom_assignment']['end_t'] = array(
     'title' => t('Assignment: Due Date'),
     'help' => t('When an assigment must be completed.'),
     'field' => array(
@@ -187,9 +269,37 @@
       'handler' => 'views_handler_filter_date',
     ),
   );
-  /** 
-   * Data for assignments
-   */
+
+  $data['classroom_assignment']['relative_end'] = array(
+    'title' => t('Assignment: Relative End'),
+    'help' => t('Unknown field -- assumed date type.'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_date',
+    ),
+  );
+  
+  $data['classroom_assignment']['grade_percentage'] = array(
+    'title' => t('Assignment: Grade Percentage'),
+    'help' => t('The grade weight for this assignment against the entire course.'),
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+  );
+  
   $data['classroom_assignment']['max_grade'] = array(
     'title' => t('Assignment: Maximum Grade'),
     'help' => t('The highest grade possible for this assignment.'),
@@ -206,8 +316,51 @@
   );
   
   $data['classroom_assignment']['topic_tid'] = array(
-    'title' => t('Assignment: Topic ID'),
-    'help' => t('Topic ID this assignment belongs to.'),
+    'title' => t('Topic: ID'),
+    'help' => t('The Topic ID associated with an assignment.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Topic ID'),
+      'base' => 'classroom_topic',
+      'base field' => 'tid',
+      'skip base' => array('node'),
+    ),
+  );  
+    
+  // --------------------- TOPICS ------------------ //  
+  
+  
+  // The 'group' index will be used as a prefix in the UI for any of this
+  // table's fields, sort criteria, etc. so it's easy to tell where they came
+  // from.
+  $data['classroom_topic']['table']['group'] = t('Classroom');
+  
+  $data['classroom_topic']['table']['base'] = array(
+    'field' => 'tid',
+    'title' => t('Classroom: Course Topics'),
+    'help' => t("Topics associated with Courses."),
+  );
+  
+  // This table references the {node} table.
+  // This creates an 'implicit' relationship to the node table, so that when 'Node'
+  // is the base table, the fields are automatically available.
+  $data['classroom_topic']['table']['join'] = array(
+    // Index this array by the table name to which this table refers.
+    // 'left_field' is the primary key in the referenced table.
+    // 'field' is the foreign key in this table.
+    'node' => array(
+      'left_field' => 'nid',
+      'field' => 'course_nid',
+    ),
+    'classroom_course' => array(
+      'left_field' => 'nid',
+      'field' => 'course_nid',
+    ),
+  );
+  
+  $data['classroom_topic']['tid'] = array(
+    'title' => t('Topic: ID'),
+    'help' => t('The topic ID in a course.'),
     'field' => array(
       'handler' => 'views_handler_field_numeric',
       'click sortable' => TRUE,
@@ -220,24 +373,48 @@
     ),
     'argument' => array(
       'handler' => 'views_handler_argument_numeric',
+      'name field' => 'title', 
+      'numeric' => TRUE,
+    ),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Assignment ID'),
+      'base' => 'classroom_assignment',
+      'base field' => 'topic_tid',
+      'skip base' => array('classroom_topic'),
+    ),
+  );
+  
+  $data['classroom_topic']['course_nid'] = array(
+    'title' => t('Course: ID'),
+    'help' => t('The Course ID associated with a topic.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Course ID'),
+      'base' => 'classroom_course',
+      'base field' => 'nid',
+      'skip base' => array(),
     ),
   );
   
-  $data['classroom_assignment']['description'] = array(
-    'title' => t('Assignment: Topic Description'),
-    'help' => t('A description of this class topic.'),
+  $data['classroom_topic']['name'] = array(
+    'title' => t('Topic: Name'),
+    'help' => t('The name of a topic in a course.'),
     'field' => array(
       'handler' => 'views_handler_field',
       'click sortable' => TRUE,
     ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
     'filter' => array(
       'handler' => 'views_handler_filter_string',
     ),
   );
   
-  $data['classroom_assignment']['name'] = array(
-    'title' => t('Assignment: Topic Name'),
-    'help' => t('Topic name this assignment belongs to.'),
+  $data['classroom_topic']['description'] = array(
+    'title' => t('Topic: Description'),
+    'help' => t('The description of a topic in a course.'),
     'field' => array(
       'handler' => 'views_handler_field',
       'click sortable' => TRUE,
@@ -250,5 +427,258 @@
     ),
   );
   
+  $data['classroom_topic']['number'] = array(
+    'title' => t('Topic: Number'),
+    'help' => t('The topic number in a course.'),
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_numeric',
+      'name field' => 'title', 
+      'numeric' => TRUE,
+    ),
+  );
+  
+  
+  // --------------------- RESPONSES ------------------ //  
+  
+  
+  // The 'group' index will be used as a prefix in the UI for any of this
+  // table's fields, sort criteria, etc. so it's easy to tell where they came
+  // from.
+  $data['classroom_response']['table']['group'] = t('Classroom');
+  
+  $data['classroom_response']['table']['base'] = array(
+    'field' => 'nid',
+    'title' => t('Classroom: Course Assignment Responses'),
+    'help' => t("Responses to assignments given to a course."),
+  );
+  
+  // This table references the {node} table.
+  // This creates an 'implicit' relationship to the node table, so that when 'Node'
+  // is the base table, the fields are automatically available.
+  $data['classroom_response']['table']['join'] = array(
+    // Index this array by the table name to which this table refers.
+    // 'left_field' is the primary key in the referenced table.
+    // 'field' is the foreign key in this table.
+    'node' => array(
+      'left_field' => 'nid',
+      'field' => 'nid',
+    ),
+    'classroom_assignment' => array(
+      'left_field' => 'nid',
+      'field' => 'assignment_nid',
+    ),
+  );
+  
+  $data['classroom_response']['assignment_nid'] = array(
+    'title' => t('Assignment: ID'),
+    'help' => t('The ID of the assignment this response is for.'),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Assignment ID'),
+      'base' => 'classroom_assignment',
+      'base field' => 'nid',
+      'skip base' => array('classroom_response'),
+    ),
+  );
+  
+  $data['classroom_response']['grade'] = array(
+    'title' => t('Response: Grade'),
+    'help' => t('The grade given in response to an assignment.'),
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+  );
+  
+  // --------------------- RESOURCES ------------------ //  
+  
+  // The 'group' index will be used as a prefix in the UI for any of this
+  // table's fields, sort criteria, etc. so it's easy to tell where they came
+  // from.
+  $data['classroom_course_resource']['table']['group'] = t('Classroom');
+  
+  $data['classroom_course_resource']['table']['base'] = array(
+    'field' => 'resource_nid',
+    'title' => t('Classroom: Course Resources'),
+    'help' => t("Resources associated with Courses."),
+  );
+
+  // This table references the {node} table.
+  // This creates an 'implicit' relationship to the node table, so that when 'Node'
+  // is the base table, the fields are automatically available.
+  $data['classroom_course_resource']['table']['join'] = array(
+    // Index this array by the table name to which this table refers.
+    // 'left_field' is the primary key in the referenced table.
+    // 'field' is the foreign key in this table.
+    'node' => array(
+      'left_field' => 'nid',
+      'field' => 'resource_nid',
+    ),
+    'classroom_course' => array(
+      'left_field' => 'nid',
+      'field' => 'course_nid',
+    ),
+    'classroom_topic' => array(
+      'left_field' => 'tid',
+      'field' => 'topic_tid',
+    ),
+  );
+
+  $data['classroom_course_resource']['resource_nid'] = array(
+    'title' => t('Resource: ID'),
+    'help' => t('The Resource ID.'),
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_numeric',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_node_nid',
+      'name field' => 'title', 
+      'numeric' => TRUE,
+      'validate type' => 'nid',
+    ),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Resource ID'),
+      'base' => 'node',
+      'base field' => 'nid',
+      'skip base' => array('node'),
+    ),
+  );
+
+  $data['classroom_course_resource']['course_nid'] = array(
+    'title' => t('Course: ID'),
+    'help' => t('The Course ID associated with a resource.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Course ID'),
+      'base' => 'classroom_course',
+      'base field' => 'nid',
+      'skip base' => array(),
+    ),
+  );
+  
+  $data['classroom_course_resource']['topic_tid'] = array(  
+    'title' => t('Topic: ID'),
+    'help' => t('The Topic ID associated with a resource.'),
+  );
+
+  // --------------------- REGISTRATION ------------------ //  
+  
+  // The 'group' index will be used as a prefix in the UI for any of this
+  // table's fields, sort criteria, etc. so it's easy to tell where they came
+  // from.
+  $data['classroom_registration']['table']['group'] = t('Classroom');
+  
+  $data['classroom_registration']['table']['base'] = array(
+    'title' => t('Classroom: Course Registrations'),
+    'help' => t("Users whom have registered for Courses."),
+  );
+  
+  // This table references the {node} table.
+  // This creates an 'implicit' relationship to the node table, so that when 'Node'
+  // is the base table, the fields are automatically available.
+  $data['classroom_registration']['table']['join'] = array(
+    // Index this array by the table name to which this table refers.
+    // 'left_field' is the primary key in the referenced table.
+    // 'field' is the foreign key in this table.
+    'node' => array(
+      'left_field' => 'nid',
+      'field' => 'course_nid',
+    ),
+    'users' => array(
+      'left_field' => 'uid',
+      'field' => 'uid',
+    ),
+    // why this is in the registration table is beyond me 
+    // ... but we'll include it anyway.
+    'role' => array(
+      'left_field' => 'rid',
+      'field' => 'access_by_rid',
+    ),
+  );
+  
+  $data['classroom_registration']['course_nid'] = array(
+    'title' => t('Course: ID'),
+    'help' => t('The Course ID associated with a resource.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'label' => t('Course ID'),
+      'base' => 'classroom_course',
+      'base field' => 'nid',
+      'skip base' => array(),
+    ),
+  );
+  
+  $data['classroom_registration']['active'] = array(  
+    'title' => t('Registration: Active'),
+    'help' => t('Whether or not the users registration is accepted.'),
+    'field' => array(
+      'handler' => 'views_handler_field_boolean',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_boolean_operator',
+      'label' => t('Active'),
+      'type' => 'yes-no',
+    ),
+  );
+  
+  $data['classroom_registration']['role'] = array(  
+    'title' => t('Registration: Role'),
+    'help' => t('What persona the user is in relation to a course. (DEV: Needs Work)'),
+    // TODO: Add Sorting,
+    // TODO: Add Argument,
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+  );
+  
+  $data['classroom_registration']['date'] = array(
+    'title' => t('Registration: Date'),
+    'help' => t('When a user registered for class.'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_date',
+    ),
+  );
+
   return $data;
-}
+}
