PluginProbe
Assistant – Every Day Productivity Apps / 1.4.7
Assistant – Every Day Productivity Apps v1.4.7
1.5.5 trunk 0.1.0 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.6.0 0.7.0 0.7.0.2 0.7.0.3 0.7.0.4 0.7.0.5 0.7.0.6 0.7.0.7 0.7.0.8 0.7.0.9 0.7.1 1.0 All 71 releases
← All changes | backend/src/Data/Repository/LabelsRepository.php +84 -5 0.3.11.4.7 View file →
@@ -25,8 +25,87 @@
25 25
26 26 return parent::query( $args );
27 27 }
28 28
29 + /**
30 + * @return array
31 + */
32 + public function count() {
33 + global $wpdb;
34 +
35 + $terms = $this->query(
36 + [
37 + 'hide_empty' => false,
38 + ]
39 + )->get_terms();
40 +
41 + if ( ! count( $terms ) ) {
42 + return [];
43 + }
44 +
45 + $counts = [];
46 + $subqueries = [];
47 +
48 + foreach ( $terms as $term ) {
49 + $subqueries[] = $wpdb->prepare(
50 + "(SELECT COUNT(*)
51 + FROM $wpdb->postmeta
52 + WHERE meta_key = 'fl_asst_notation_label_id'
53 + AND meta_value = %d) as label_%d",
54 + $term->term_id,
55 + $term->term_id
56 + );
57 + }
58 +
59 + $results = $wpdb->get_row( 'SELECT ' . implode( ',', $subqueries ) );
60 + $counts = [];
61 +
62 + foreach ( $results as $key => $count ) {
63 + $key = str_replace( 'label_', '', $key );
64 + $counts[ $key ] = $count;
65 + }
66 +
67 + return $counts;
68 + }
69 +
70 + /**
71 + * @param string $object_type
72 + * @param int $label_id
73 + * @return array
74 + */
75 + function get_object_ids( $object_type, $label_id ) {
76 + global $wpdb;
77 +
78 + $results = $wpdb->get_results(
79 + $wpdb->prepare(
80 + "SELECT m1.meta_value
81 + FROM $wpdb->postmeta m1
82 + INNER JOIN $wpdb->postmeta m2
83 + ON m1.post_id = m2.post_id
84 + AND m1.meta_key = 'fl_asst_notation_object_id'
85 + AND m2.meta_key = 'fl_asst_notation_label_id'
86 + AND m2.meta_value = %d
87 + INNER JOIN $wpdb->postmeta m3
88 + ON m1.post_id = m3.post_id
89 + AND m3.meta_key = 'fl_asst_notation_object_type'
90 + AND m3.meta_value = %s",
91 + $label_id,
92 + $object_type
93 + )
94 + );
95 +
96 + $ids = [];
97 +
98 + foreach ( $results as $result ) {
99 + $ids[] = $result->meta_value;
100 + }
101 +
102 + return $ids;
103 + }
104 +
105 + /**
106 + * @return void
107 + */
29 108 public function save_defaults() {
30 109 $did_install = get_option( static::FL_ASST_INSTALLED_LABELS, false );
31 110 $existing = $this->query(
32 111 [
@@ -44,13 +123,13 @@
44 123 *
45 124 * TODO: Load from server config.
46 125 */
47 126 $default_labels = [
48 - '#FF305C' => __( 'Red', 'fl-assistant' ),
49 - '#FF9500' => __( 'Orange', 'fl-assistant' ),
50 - '#FFD000' => __( 'Yellow', 'fl-assistant' ),
51 - '#00D281' => __( 'Green', 'fl-assistant' ),
52 - '#1BADF8' => __( 'Blue', 'fl-assistant' ),
127 + '#FF305C' => __( 'Red', 'assistant' ),
128 + '#FF9500' => __( 'Orange', 'assistant' ),
129 + '#FFD000' => __( 'Yellow', 'assistant' ),
130 + '#00D281' => __( 'Green', 'assistant' ),
131 + '#1BADF8' => __( 'Blue', 'assistant' ),
53 132 ];
54 133
55 134 foreach ( $default_labels as $color => $label ) {
56 135 $result = wp_insert_term(