@@ -50,7 +50,22 @@ public function index() {
5050
5151 $ this ->FilterComponent = $ this ->Components ->load ('Filter ' );
5252 $ named_params = $ this ->request ->params ['named ' ];
53+ $ tag_filter_value = null ;
54+ $ tag_filter_field = null ;
5355 if ($ named_params ) {
56+ if (isset ($ named_params ['TagId ' ])) {
57+ $ tag_filter_value = $ named_params ['TagId ' ];
58+ $ tag_filter_field = 'Id ' ;
59+ unset($ named_params ['TagId ' ]);
60+ } else if (isset ($ named_params ['Tag ' ])) {
61+ $ tag_filter_value = $ named_params ['Tag ' ];
62+ $ tag_filter_field = 'Name ' ;
63+ unset($ named_params ['Tag ' ]);
64+ } else if (isset ($ named_params ['Tags ' ])) {
65+ $ tag_filter_value = $ named_params ['Tags ' ];
66+ $ tag_filter_field = 'Name ' ;
67+ unset($ named_params ['Tags ' ]);
68+ }
5469 # In 1.35.13 we renamed StartTime and EndTime to StartDateTime and EndDateTime.
5570 # This hack renames the query string params
5671 foreach ( $ named_params as $ k =>$ v ) {
@@ -101,7 +116,21 @@ public function index() {
101116 #ZM\Debug(print_r($conditions, true));
102117
103118 } else {
104- $ conditions = $ this ->FilterComponent ->buildFilter ($ _REQUEST );
119+ $ raw_params = $ _REQUEST ;
120+ if (isset ($ raw_params ['TagId ' ])) {
121+ $ tag_filter_value = $ raw_params ['TagId ' ];
122+ $ tag_filter_field = 'Id ' ;
123+ unset($ raw_params ['TagId ' ]);
124+ } else if (isset ($ raw_params ['Tag ' ])) {
125+ $ tag_filter_value = $ raw_params ['Tag ' ];
126+ $ tag_filter_field = 'Name ' ;
127+ unset($ raw_params ['Tag ' ]);
128+ } else if (isset ($ raw_params ['Tags ' ])) {
129+ $ tag_filter_value = $ raw_params ['Tags ' ];
130+ $ tag_filter_field = 'Name ' ;
131+ unset($ raw_params ['Tags ' ]);
132+ }
133+ $ conditions = $ this ->FilterComponent ->buildFilter ($ raw_params );
105134 }
106135 $ settings = array (
107136 // https://github.com/ZoneMinder/ZoneMinder/issues/995
@@ -118,6 +147,7 @@ public function index() {
118147 'paramType ' => 'querystring ' ,
119148 );
120149
150+ $ settings ['contain ' ] = array ('Tag ' );
121151 if ( isset ($ conditions ['GroupId ' ]) ) {
122152 $ settings ['joins ' ] = array (
123153 array (
@@ -128,7 +158,34 @@ public function index() {
128158 ),
129159 ),
130160 );
131- $ settings ['contain ' ] = array ('Group ' );
161+ $ settings ['contain ' ][] = 'Group ' ;
162+ }
163+ if ($ tag_filter_value !== null ) {
164+ if (!isset ($ settings ['joins ' ])) {
165+ $ settings ['joins ' ] = array ();
166+ }
167+ $ settings ['joins ' ][] = array (
168+ 'table ' => 'Events_Tags ' ,
169+ 'type ' => 'inner ' ,
170+ 'conditions ' => array (
171+ 'Events_Tags.EventId = Event.Id '
172+ ),
173+ );
174+ $ settings ['joins ' ][] = array (
175+ 'table ' => 'Tags ' ,
176+ 'type ' => 'inner ' ,
177+ 'conditions ' => array (
178+ 'Tags.Id = Events_Tags.TagId '
179+ ),
180+ );
181+ if ($ tag_filter_field === 'Id ' ) {
182+ $ tag_ids = is_array ($ tag_filter_value ) ? $ tag_filter_value : explode (', ' , $ tag_filter_value );
183+ $ tag_ids = array_map ('intval ' , $ tag_ids );
184+ $ conditions [] = array ('Tags.Id ' => $ tag_ids );
185+ } else {
186+ $ conditions [] = array ('Tags.Name ' => $ tag_filter_value );
187+ }
188+ $ settings ['group ' ] = 'Event.Id ' ;
132189 }
133190 $ settings ['conditions ' ] = array ($ conditions , $ mon_options );
134191
0 commit comments