コード例 #1
0
 public function prsp_get_records()
 {
     $tmplt_id = $_POST['tmplt_id'];
     $from = (int) $_POST['from'];
     $count = (int) $_POST['count'];
     $result = array();
     // Load Template definition
     $the_template = new ProspectTemplate(false, $tmplt_id, true, true, false);
     // Get dependent Templates needed for Joins
     $d_templates = $the_template->get_dependent_templates(false);
     // Get associative array for all Attribute definitions
     $assoc_atts = ProspectAttribute::get_assoc_defs();
     // Get Records -- Need to order by Record ID, etc
     $args = array('post_type' => 'prsp-record', 'post_status' => 'publish', 'meta_key' => 'record-id', 'orderby' => 'meta_value', 'order' => 'ASC', 'offset' => $from, 'posts_per_page' => $count, 'meta_query' => array('key' => 'tmplt-id', 'value' => $tmplt_id, 'compare' => '='));
     $query = new WP_Query($args);
     if ($query->have_posts()) {
         foreach ($query->posts as $rec) {
             $the_rec = new ProspectRecord(true, $rec->ID, false, $the_template, $d_templates, $assoc_atts);
             // Extract the necessary data in proper format
             $extracted_rec = array();
             $extracted_rec['id'] = $the_rec->id;
             $extracted_rec['wp'] = $the_rec->post_id;
             $extracted_rec['l'] = $the_rec->label;
             $extracted_rec['a'] = $the_rec->att_data;
             array_push($result, $extracted_rec);
         }
     }
     die(json_encode($result, JSON_UNESCAPED_UNICODE));
 }
コード例 #2
0
ファイル: class-prospect.php プロジェクト: tbessias/prospect
 public function prsp_page_template($page_template)
 {
     global $post;
     $post_type = get_query_var('post_type');
     // What kind of page viewed?
     switch ($post_type) {
         case 'prsp-attribute':
         case 'prsp-template':
             break;
         case 'prsp-record':
             $blog_id = get_current_blog_id();
             $ajax_url = get_admin_url($blog_id, 'admin-ajax.php');
             $tmplt_id = get_post_meta($post->ID, 'tmplt-id', true);
             if ($tmplt_id != '') {
                 // Load Template definition
                 $the_template = new ProspectTemplate(false, $tmplt_id, true, true, true);
                 // Get dependent Templates needed for Joins
                 $d_templates = $the_template->get_dependent_templates(true);
                 // Get associative array for all Attribute definitions
                 $assoc_atts = ProspectAttribute::get_assoc_defs();
                 $record = new ProspectRecord(true, $post->ID, false, $the_template, $d_templates, $assoc_atts);
                 wp_enqueue_script('jquery');
                 wp_enqueue_script('underscore');
                 wp_enqueue_style('view-record-css', plugins_url('/css/view-record.css', dirname(__FILE__)));
                 if ($the_template->view->sc != null && $the_template->view->sc != 'disable') {
                     wp_enqueue_script('soundcloud-api', 'http://w.soundcloud.com/player/api.js');
                 }
                 wp_enqueue_script('view-record', plugins_url('/js/view-record.js', dirname(__FILE__)), array('jquery', 'underscore'));
                 // Convert attributes to serial array
                 $att_array = array();
                 foreach ($assoc_atts as $key => $value) {
                     $att_entry = array();
                     $att_entry['id'] = $key;
                     $att_entry['def'] = $value;
                     array_push($att_array, $att_entry);
                 }
                 // Sort by ID
                 usort($att_array, array('Prospect', 'cmp_ids'));
                 // Compile Dependent Template view data
                 $d_t_array = array();
                 foreach ($d_templates as $this_temp) {
                     $d_t_entry = array();
                     $d_t_entry['id'] = $this_temp->id;
                     $d_t_entry['v'] = $this_temp->view;
                     array_push($d_t_array, $d_t_entry);
                 }
                 wp_localize_script('view-record', 'prspdata', array('ajax_url' => $ajax_url, 'd' => $record->att_data, 'a' => $att_array, 'v' => $the_template->view, 'j' => $the_template->joins, 't' => $d_t_array));
                 $dltext = ProspectAdmin::get_script_text('view-record.txt');
                 echo $dltext;
             }
             break;
         case 'prsp-exhibit':
             $page_template = dirname(__FILE__) . '/view-exhibit.php';
             break;
             // Don't currently support any special views as they are meant for backend
         // Don't currently support any special views as they are meant for backend
         case 'prsp-map':
         case 'prsp-prspctv':
             break;
     }
     // switch
     return $page_template;
 }