コード例 #1
0
function psp_current_projects($atts)
{
    extract(shortcode_atts(array('type' => 'all', 'status' => 'all', 'access' => 'user', 'count' => '10', 'sort' => 'default', 'order' => 'ASC'), $atts));
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $cuser = wp_get_current_user();
    $cid = $cuser->ID;
    unset($meta_args);
    unset($status_args);
    // Determine the sorting
    if ($sort == 'start') {
        $meta_sort = 'start_date';
        $orderby = 'meta_value';
    } elseif ($sort == 'end') {
        $meta_sort = 'end_date';
        $order_by = 'meta_value';
    } else {
        $meta_sort = 'start_date';
        $order_by = 'menu_order';
    }
    // Set the initial arguments
    $args = array('post_type' => 'psp_projects', 'paged' => $paged, 'posts_per_page' => $count, 'meta_key' => $meta_sort, 'orderby' => $order_by, 'order' => $order);
    // If a type has been selected, add it to the argument
    if (!empty($type) && $type != 'all') {
        $tax_args = array('psp_tax' => $type);
        $args = array_merge($args, $tax_args);
    }
    if ($status == 'active') {
        $status_args = array('tax_query' => array(array('taxonomy' => 'psp_status', 'field' => 'slug', 'terms' => 'completed', 'operator' => 'NOT IN')));
        $args = array_merge($args, $status_args);
    }
    if ($status == 'completed') {
        $status_args = array('tax_query' => array(array('taxonomy' => 'psp_status', 'field' => 'slug', 'terms' => 'completed')));
        $args = array_merge($args, $status_args);
    }
    if ($access == 'user') {
        // Just restricting access, not worried about active or complete
        if (!current_user_can('manage_options')) {
            $cuser = wp_get_current_user();
            $cid = $cuser->ID;
            $meta_args = array('meta_query' => array('relation' => 'OR', array('key' => 'allowed_users_%_user', 'value' => $cid), array('key' => 'restrict_access_to_specific_users', 'value' => '')));
            $args = array_merge($args, $meta_args);
        }
    }
    $projects = new WP_Query($args);
    if ($access == 'user' && !is_user_logged_in()) {
        ?>
		
		<div id="psp-overview">
		
        	<div id="psp-login" class="shortcode-login">
        	
				<h2><?php 
        _e('Please Login to View Projects', 'psp_projects');
        ?>
</h2>
            
				<?php 
        echo panorama_login_form();
        ?>
			
			</div> <!--/#psp-login-->
		
		</div>
	
	<?php 
        psp_front_assets(1);
        return;
    }
    if ($projects->have_posts()) {
        ob_start();
        ?>

        <table class="psp_project_list">
            <thead>
            <tr>
                <th class="psp_pl_col1"><?php 
        _e('Project', 'psp_projects');
        ?>
</th>
                <th class="psp_pl_col2"><?php 
        _e('Progress', 'psp_projects');
        ?>
</th>
                <th class="psp_pl_col3"><?php 
        _e('Start', 'psp_projects');
        ?>
</th>
                <th class="psp_pl_col4"><?php 
        _e('End', 'psp_projets');
        ?>
</th>
            </tr>
            </thead>

            <?php 
        while ($projects->have_posts()) {
            $projects->the_post();
            global $post;
            ?>

                <tr>
                    <td>
                        <a href="<?php 
            the_permalink();
            ?>
"><?php 
            the_title();
            ?>
</a>
                        <div class="psp-table-meta">
                            <p><strong><?php 
            _e('Client', 'psp_projects');
            ?>
:</strong> <?php 
            the_field('client');
            ?>
<br> <strong><?php 
            _e('Last Updated', 'psp_projects');
            ?>
:</strong> <?php 
            the_modified_date();
            ?>
</p>
                        </div>
                    </td>
                    <td>
                        <?php 
            global $post;
            $completed = psp_compute_progress($post->ID);
            if (!empty($completed)) {
                echo '<p class="psp-progress"><span class="psp-' . $completed . '"><b>' . $completed . '%</b></span></p>';
            }
            ?>
                    </td>
                    <td>
                        <?php 
            psp_the_start_date($post->ID);
            ?>
                    </td>
                    <td>
                        <?php 
            psp_the_end_date($post->ID);
            ?>
                    </td>
                </tr>

            <?php 
        }
        ?>

        </table>

        <p><?php 
        echo get_next_posts_link('&laquo; More Projects', $projects->max_num_pages) . ' ' . get_previous_posts_link('Previous Projects &raquo;');
        ?>
</p>

        <?php 
        psp_front_assets(1);
        return ob_get_clean();
    } else {
        return '<p>' . __('No projects found', 'psp_projects') . '</p>';
    }
}
コード例 #2
0
function psp_the_timing($id)
{
    $startDate = get_field('start_date', $id);
    $endDate = get_field('end_date', $id);
    $s_year = substr($startDate, 0, 4);
    $s_month = substr($startDate, 4, 2);
    $s_day = substr($startDate, 6, 2);
    $e_year = substr($endDate, 0, 4);
    $e_month = substr($endDate, 4, 2);
    $e_day = substr($endDate, 6, 2);
    $textStartDate = $s_month . '/' . $s_day . '/' . $s_year;
    $textEndDate = $e_month . '/' . $e_day . '/' . $e_year;
    if (empty($startDate) || empty($endDate)) {
        return;
    }
    global $post;
    $all_time = psp_calculate_timing($id);
    if ($all_time[0] < 0) {
        $all_time[0] = 100;
    }
    $psp_tt_10 = $all_time[0] >= 10 ? 'active' : null;
    $psp_tt_20 = $all_time[0] >= 20 ? 'active' : null;
    $psp_tt_30 = $all_time[0] >= 30 ? 'active' : null;
    $psp_tt_40 = $all_time[0] >= 40 ? 'active' : null;
    $psp_tt_50 = $all_time[0] >= 50 ? 'active' : null;
    $psp_tt_60 = $all_time[0] >= 60 ? 'active' : null;
    $psp_tt_70 = $all_time[0] >= 70 ? 'active' : null;
    $psp_tt_80 = $all_time[0] >= 80 ? 'active' : null;
    $psp_tt_90 = $all_time[0] >= 90 ? 'active' : null;
    ?>

    <div id="psp-time-overview">

        <div class="project-timing cf">

            <?php 
    if ($startDate || $endDate) {
        ?>

                <h4><?php 
        _e('Project Timing', 'psp_projects');
        ?>
</h4>

                <ul class="psp-timing cf">
                    <?php 
        if ($startDate) {
            ?>
                        <li><strong><?php 
            _e('Start', 'psp_projects');
            ?>
</strong>
                            <?php 
            psp_the_start_date($id);
            ?>
                        </li>
                    <?php 
        }
        if ($endDate) {
            ?>
                        <li><strong><?php 
            _e('End', 'psp_projects');
            ?>
</strong>
							<?php 
            psp_the_end_date($id);
            ?>
                        </li>
                    <?php 
        }
        ?>
                </ul>


				<?php 
        if ($startDate && $endDate) {
            ?>

       		 	<div class="psp-timebar">
					
   				 <?php 
            if ($all_time[2] > $all_time[1]) {
                $days_left = '<span class="psp-time-details">' . $all_time[2] . __('days past project end date.', 'psp_projects') . '</span>';
            } else {
                $days_left = '<span class="psp-time-details">' . $all_time[2] . __(' days remaining', 'psp_projects') . '</span>';
            }
            ?>

            		 <p class="psp-time-start-end"><?php 
            echo $textStartDate;
            ?>
 <span><?php 
            echo $textEndDate;
            ?>
</span></p>

            		 <div class="psp-time-progress">

               		  	<p class="psp-time-bar"><span class="psp-<?php 
            echo $all_time[0];
            ?>
"></span></p>

              			<ol class="psp-time-ticks">
                  			<li class="psp-tt-10 <?php 
            echo $psp_tt_10;
            ?>
"></li>
                    		<li class="psp-tt-20 <?php 
            echo $psp_tt_20;
            ?>
"></li>
                    		<li class="psp-tt-30 <?php 
            echo $psp_tt_30;
            ?>
"></li>
                    		<li class="psp-tt-40 <?php 
            echo $psp_tt_40;
            ?>
"></li>
                    		<li class="psp-tt-50 <?php 
            echo $psp_tt_50;
            ?>
"></li>
                    		<li class="psp-tt-60 <?php 
            echo $psp_tt_60;
            ?>
"></li>
                    		<li class="psp-tt-70 <?php 
            echo $psp_tt_70;
            ?>
"></li>
                    		<li class="psp-tt-80 <?php 
            echo $psp_tt_80;
            ?>
"></li>
                    		<li class="psp-tt-90 <?php 
            echo $psp_tt_90;
            ?>
"></li>
                		</ol>

                		<span class="psp-time-indicator" style="left: <?php 
            echo $all_time[0];
            ?>
%"><span></span><?php 
            echo $all_time[0];
            ?>
%</span>

           	 	  </div> <!--/.psp-time-progress-->

    		</div> <!--/.psp-timebar-->
			<?php 
        }
        // if start and end date
        ?>
			
	  <?php 
    }
    // if start or end date
    ?>
	  </div> <!--/.project-timing-->
    <?php 
}