Skip to content
Browse files

Show associated posts on a session admin page if the plugin exists

  • Loading branch information...
1 parent 150cb12 commit e6419e481634a94750d81501805392cddb254021 @danielbachhuber danielbachhuber committed Sep 8, 2011
Showing with 43 additions and 3 deletions.
  1. +6 −0 css/admin.css
  2. +0 −1 css/session_admin.css
  3. +2 −0 functions.php
  4. +35 −2 php/class.ona11_session.php
View
6 css/admin.css
@@ -0,0 +1,6 @@
+ul.show-list li {
+ margin-left: 15px;
+ margin-right: 15px;
+ list-style-type: square;
+}
+
View
1 css/session_admin.css
@@ -62,7 +62,6 @@
width: 100%;
}
-
#ona11-session-information .option-item {
padding-top: 10px;
padding-bottom: 10px;
View
2 functions.php
@@ -38,6 +38,8 @@ function enqueue_resources() {
wp_enqueue_style( 'ona11_primary_css', get_bloginfo('stylesheet_url'), false, ONA11_VERSION );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'ona11_twitter', get_bloginfo( 'template_directory' ) . '/js/twitter.js', array( 'jquery' ), ONA11_VERSION );
+ } else {
+ wp_enqueue_style( 'ona_admin_css', get_bloginfo( 'template_url' ) . '/css/admin.css', false, ONA11_VERSION, 'all' );
}
}
View
37 php/class.ona11_session.php
@@ -90,9 +90,12 @@ function add_admin_resources() {
function add_post_meta_boxes() {
add_meta_box( 'ona11-session-information', 'Session Information', array( &$this, 'session_information_meta_box' ), 'ona11_session', 'normal', 'high');
- add_meta_box( 'ona11-session-date-time-location', 'Session Date, Time & Location', array( &$this, 'date_time_location_meta_box' ), 'ona11_session', 'side', 'default');
+ add_meta_box( 'ona11-session-date-time-location', 'Session Date, Time & Location', array( &$this, 'date_time_location_meta_box' ), 'ona11_session', 'side', 'default');
remove_meta_box( 'ona11_locationsdiv', 'ona11_session', 'side' );
+ if ( function_exists( 'p2p_register_connection_type' ) )
+ add_meta_box( 'ona11-session-associated-posts', 'Associated Posts', array( &$this, 'associated_posts_meta_box' ), 'ona11_session', 'side', 'default');
+
}
function date_time_location_meta_box() {
@@ -204,7 +207,37 @@ function session_information_meta_box() {
<?php
- } // END post_meta_box()
+ }
+
+ /**
+ * Show posts that have been associated to this session
+ */
+ function associated_posts_meta_box() {
+ global $post, $wpdb;
+
+ $query = $wpdb->prepare( "SELECT p2p_from FROM $wpdb->p2p WHERE p2p_to=$post->ID;" );
+ $results = $wpdb->get_results( $query );
+
+ echo "<p>Posts associated with this session:</p>";
+
+ if ( count( $results ) ) {
+ $post_ids = array();
+ foreach( $results as $result )
+ $post_ids[] = $result->p2p_from;
+ $results_str = implode( ', ', $post_ids );
+ $query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID in(%s);", $results_str );
+ $posts = $wpdb->get_results( $query );
+ echo '<ul class="show-list">';
+ foreach( $posts as $post ) {
+ echo '<li>' . esc_html( $post->post_title ) . '</li>';
+ }
+ echo '</ul>';
+ } else {
+ ?>
+ <div class="message info">No posts have been associated with this session yet</div>
+ <?php
+ }
+ }
/**
* Save the data from our metaboxes

0 comments on commit e6419e4

Please sign in to comment.
Something went wrong with that request. Please try again.