PluginProbe
UpStream: a Project Management Plugin for WordPress / trunk
UpStream: a Project Management Plugin for WordPress vtrunk
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / frontend / class-upstream-view.php

class-upstream-view.php in UpStream: a Project Management Plugin for WordPress trunk, at includes/frontend/class-upstream-view.php

239 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UpStream_View
4 *
5 * @package UpStream
6 */
7
8 // Prevent direct access.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 use UpStream\Traits\Singleton;
14
15 /**
16 * Class UpStream_View
17 *
18 * @since 1.15.0
19 */
20 class UpStream_View {
21
22 use Singleton;
23
24 /**
25 * Project
26 *
27 * @var undefined
28 */
29 protected static $project = null;
30
31 /**
32 * Milestones
33 *
34 * @var array
35 */
36 protected static $milestones = array();
37
38
39 /**
40 * Tasks
41 *
42 * @var array
43 */
44 protected static $tasks = array();
45
46 /**
47 * Users
48 *
49 * @var array
50 */
51 protected static $users = array();
52
53 /**
54 * Construct
55 *
56 * @return void
57 */
58 public function __construct() {
59 self::$namespace = get_class(
60 empty( self::$instance )
61 ? $this
62 : self::$instance
63 );
64 }
65
66 /**
67 * Get Milestones
68 *
69 * @param int $project_id Project Id.
70 */
71 public static function get_milestones( $project_id = 0 ) {
72 return \UpStream\Milestones::getInstance()->get_milestones_as_rowset( $project_id );
73 }
74
75 /**
76 * Get Project
77 *
78 * @param int $id Project ID.
79 */
80 public static function get_project( $id = 0 ) {
81 if ( empty( $project ) ) {
82 self::set_project( $id );
83 }
84
85 return self::$project;
86 }
87
88 /**
89 * Set Project
90 *
91 * @param int $id Project ID.
92 * @return void
93 */
94 public static function set_project( $id = 0 ) {
95 self::$project = new UpStream_Project( $id );
96 }
97
98 /**
99 * Get Time Zone Offset
100 */
101 public static function get_time_zone_offset() {
102 $offset = get_option( 'gmt_offset' );
103 $sign = $offset < 0 ? '-' : '+';
104 $hours = (int) $offset;
105 $minutes = abs( ( $offset - (int) $offset ) * 60 );
106 $offset = (int) sprintf( '%s%d%02d', $sign, abs( $hours ), $minutes );
107 $calc_offset_seconds = $offset < 0 ? $offset * -1 * 60 : $offset * 60;
108 return (int) ( $calc_offset_seconds );
109 }
110
111 /**
112 * Get Tasks
113 *
114 * @param int $project_id Project Id.
115 */
116 public static function get_tasks( $project_id = 0 ) {
117 $project = self::get_project( $project_id );
118
119 if ( count( self::$tasks ) === 0 ) {
120 $data = array();
121 $frowset = array_filter( (array) $project->get_meta( 'tasks' ) );
122
123 $rowset = array();
124 foreach ( $frowset as $row ) {
125 if ( upstream_override_access_object( true, UPSTREAM_ITEM_TYPE_TASK, $row['id'], UPSTREAM_ITEM_TYPE_PROJECT, $project_id, UPSTREAM_PERMISSIONS_ACTION_VIEW ) ) {
126 $rowset[] = $row;
127 }
128 }
129
130 $statuses = upstream_get_tasks_statuses();
131
132 foreach ( $rowset as $row ) {
133 $row['created_by'] = (int) $row['created_by'];
134 $row['created_time'] = isset( $row['created_time'] ) ? (int) $row['created_time'] : 0;
135 $assignees = array();
136 if ( isset( $row['assigned_to'] ) ) {
137 $assignees = array_map(
138 'intval',
139 ! is_array( $row['assigned_to'] ) ? (array) $row['assigned_to'] : $row['assigned_to']
140 );
141 }
142
143 $row['assigned_to'] = $assignees;
144
145 if ( ! empty( $assignees ) ) {
146 // Get the name of assignees to fix ordering.
147 $row['assigned_to_order'] = upstream_get_users_display_name( $assignees );
148 }
149
150 $row['status_order'] = isset( $row['status'] ) ? @$statuses[ $row['status'] ]['order'] : '0';
151 $row['progress'] = isset( $row['progress'] ) ? (float) $row['progress'] : 0.00;
152 $row['notes'] = isset( $row['notes'] ) ? (string) $row['notes'] : '';
153
154 $row['start_date'] = ! isset( $row['start_date'] ) || ! is_numeric( $row['start_date'] ) || $row['start_date'] < 0 ? 0 : (int) $row['start_date'];// + self::get_time_zone_offset();
155 $row['end_date'] = ! isset( $row['end_date'] ) || ! is_numeric( $row['end_date'] ) || $row['end_date'] < 0 ? 0 : (int) $row['end_date'];// + self::get_time_zone_offset();
156
157 $data[ $row['id'] ] = $row;
158 }
159
160 self::$tasks = $data;
161 } else {
162 $data = self::$tasks;
163 }
164
165 return $data;
166 }
167
168 /**
169 * Get Bugs
170 *
171 * @param int $project_id Project Id.
172 */
173 public static function get_bugs( $project_id = 0 ) {
174 $rowset = array();
175
176 $severities = upstream_get_bugs_severities();
177 $statuses = upstream_get_bugs_statuses();
178
179 $fmeta = (array) get_post_meta( $project_id, '_upstream_project_bugs', true );
180
181 $meta = array();
182 foreach ( $fmeta as $row ) {
183 if ( ! isset( $row['id'] ) ) {
184 continue;
185 }
186 if ( upstream_override_access_object( true, UPSTREAM_ITEM_TYPE_BUG, $row['id'], UPSTREAM_ITEM_TYPE_PROJECT, $project_id, UPSTREAM_PERMISSIONS_ACTION_VIEW ) ) {
187 $meta[] = $row;
188 }
189 }
190
191 foreach ( $meta as $data ) {
192 if ( ! isset( $data['id'] ) || ! isset( $data['created_by'] ) ) {
193 continue;
194 }
195
196 $data['created_by'] = (int) $data['created_by'];
197 $data['created_time'] = isset( $data['created_time'] ) ? (int) $data['created_time'] : 0;
198
199 $assignees = array();
200 if ( isset( $data['assigned_to'] ) ) {
201 $assignees = array_map(
202 'intval',
203 ! is_array( $data['assigned_to'] ) ? (array) $data['assigned_to'] : $data['assigned_to']
204 );
205 }
206
207 $data['assigned_to'] = $assignees;
208
209 if ( ! empty( $assignees ) ) {
210 // Get the name of assignees to fix ordering.
211 $data['assigned_to_order'] = upstream_get_users_display_name( $assignees );
212 }
213
214 $data['description'] = isset( $data['description'] ) ? (string) $data['description'] : '';
215 $data['severity'] = isset( $data['severity'] ) ? (string) $data['severity'] : '';
216 $data['severity_order'] = isset( $data['severity'] ) ? @$severities[ $data['severity'] ]['order'] : '0';
217 $data['status'] = isset( $data['status'] ) ? (string) $data['status'] : '';
218 $data['status_order'] = isset( $data['status'] ) ? @$statuses[ $data['status'] ]['order'] : '0';
219 $data['start_date'] = ! isset( $data['start_date'] ) || ! is_numeric( $data['start_date'] ) || $data['start_date'] < 0 ? 0 : (int) $data['start_date'];// + self::get_time_zone_offset();
220 $data['end_date'] = ! isset( $data['end_date'] ) || ! is_numeric( $data['end_date'] ) || $data['end_date'] < 0 ? 0 : (int) $data['end_date'];// + self::get_time_zone_offset();
221
222 $rowset[ $data['id'] ] = $data;
223 }
224
225 return $rowset;
226 }
227
228 /**
229 * Get Users
230 */
231 protected static function get_users() {
232 if ( count( self::$users ) === 0 ) {
233 self::$users = upstream_get_users_map();
234 }
235
236 return self::$users;
237 }
238 }
239