| 1 |
<?php |
| 2 |
|
| 3 |
namespace Booktics\Service\Helpers; |
| 4 |
|
| 5 |
use Booktics\Models\Team_Member_Model; |
| 6 |
use Booktics\Taxonomy\Category; |
| 7 |
|
| 8 |
class Service_Helper { |
| 9 |
|
| 10 |
/** |
| 11 |
* Get team member details for given team member IDs. |
| 12 |
* |
| 13 |
* @param array $team_member_ids |
| 14 |
* @return array |
| 15 |
*/ |
| 16 |
public static function team_member_details( $team_member_ids ) { |
| 17 |
$details = array(); |
| 18 |
foreach ( $team_member_ids as $id ) { |
| 19 |
$member = ( new Team_Member_Model() )->find( $id ); |
| 20 |
if ( $member ) { |
| 21 |
$member = $member->to_array(); |
| 22 |
$details[] = array( |
| 23 |
'id' => $member['id'], |
| 24 |
'display_name' => $member['display_name'], |
| 25 |
'email' => $member['email'], |
| 26 |
'image' => $member['image'], |
| 27 |
); |
| 28 |
} |
| 29 |
} |
| 30 |
return $details; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Get category details for given category IDs. |
| 35 |
* |
| 36 |
* @param array $category_ids |
| 37 |
* @return array |
| 38 |
*/ |
| 39 |
public static function category_details( $category_ids ) { |
| 40 |
$category_ids = array_filter( $category_ids ); |
| 41 |
$details = array(); |
| 42 |
foreach ( $category_ids as $id ) { |
| 43 |
$category = \get_term( $id, ( new Category() )->get_name() ); |
| 44 |
if ( $category ) { |
| 45 |
$category = $category->to_array(); |
| 46 |
$details[] = array( |
| 47 |
'id' => $category['term_id'], |
| 48 |
'name' => $category['name'], |
| 49 |
); |
| 50 |
} |
| 51 |
} |
| 52 |
return $details; |
| 53 |
} |
| 54 |
} |
| 55 |
|