| 1 |
<?php |
| 2 |
/** |
| 3 |
* Abstract factory class. |
| 4 |
* |
| 5 |
* @package UpStream |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace UpStream; |
| 9 |
|
| 10 |
use Upstream_Counter; |
| 11 |
|
| 12 |
// Prevent direct access. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Abstract factory class. |
| 19 |
* |
| 20 |
* @since 1.24.0 |
| 21 |
*/ |
| 22 |
abstract class Factory { |
| 23 |
/** |
| 24 |
* Counters. |
| 25 |
* |
| 26 |
* @var array |
| 27 |
*/ |
| 28 |
protected static $counters = array(); |
| 29 |
|
| 30 |
/** |
| 31 |
* Create milestone data. |
| 32 |
* |
| 33 |
* @param string $name Milestone name. |
| 34 |
* |
| 35 |
* @return Milestone |
| 36 |
*/ |
| 37 |
public static function create_milestone( $name ) { |
| 38 |
$post_id = wp_insert_post( |
| 39 |
array( |
| 40 |
'post_type' => Milestone::POST_TYPE, |
| 41 |
'post_title' => sanitize_text_field( $name ), |
| 42 |
'post_status' => 'publish', |
| 43 |
) |
| 44 |
); |
| 45 |
|
| 46 |
return self::get_milestone( $post_id ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Get milestone data. |
| 51 |
* |
| 52 |
* @param int|\WP_Post $post WP post data. |
| 53 |
* |
| 54 |
* @return Milestone |
| 55 |
*/ |
| 56 |
public static function get_milestone( $post ) { |
| 57 |
return new Milestone( $post ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Get project activity. |
| 62 |
* |
| 63 |
* @return \UpStream_Project_Activity |
| 64 |
*/ |
| 65 |
public static function get_activity() { |
| 66 |
return \UpStream_Project_Activity::getInstance(); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Get project counter |
| 71 |
* |
| 72 |
* @param int|array $project_ids Project IDs. |
| 73 |
* |
| 74 |
* @return Upstream_Counter |
| 75 |
*/ |
| 76 |
public static function get_project_counter( $project_ids ) { |
| 77 |
if ( ! isset( self::$counters[ $project_ids ] ) ) { |
| 78 |
self::$counters[ $project_ids ] = new Upstream_Counter( $project_ids ); |
| 79 |
} |
| 80 |
|
| 81 |
return self::$counters[ $project_ids ]; |
| 82 |
} |
| 83 |
} |
| 84 |
|