@@ -31,7 +31,7 @@ class Tracker_TrendController extends Tracker_AppController
3131 public $ _components = array ('Breadcrumb ' );
3232
3333 /** @var array */
34- public $ _moduleModels = array ('Scalar ' , 'ThresholdNotification ' , 'Trend ' );
34+ public $ _moduleModels = array ('Producer ' , ' Scalar ' , 'ThresholdNotification ' , 'Trend ' );
3535
3636 /**
3737 * View a given trend.
@@ -524,4 +524,46 @@ public function notifysubmitAction()
524524
525525 echo JsonComponent::encode (array ('status ' => 'ok ' , 'message ' => 'Changes saved ' ));
526526 }
527+
528+ /**
529+ * Change key metric status of a trend
530+ *
531+ * Request parameters:
532+ * trendId - The id of the producer to delete
533+ * state - The state of is_key_metric on the trend
534+ *
535+ * @throws Zend_Exception
536+ */
537+ public function setkeymetricAction ()
538+ {
539+ $ this ->disableLayout ();
540+ $ this ->disableView ();
541+
542+ /** @var int $trendId */
543+ $ trendId = $ this ->getParam ('trendId ' );
544+
545+ /** @var int $state */
546+ $ state = $ this ->getParam ('state ' );
547+
548+ if (!isset ($ trendId )) {
549+ throw new Zend_Exception ('The required trendId parameter is missing. ' );
550+ }
551+ if (!isset ($ state )) {
552+ throw new Zend_Exception ('The required state parameter is missing. ' );
553+ }
554+
555+ /** @var Tracker_TrendDao $trendDao */
556+ $ trendDao = $ this ->Tracker_Trend ->load ($ trendId );
557+
558+ /** @var Tracker_ProducerDao $producerDao */
559+ $ producerDao = $ trendDao ->getProducer ();
560+
561+ if ($ this ->Tracker_Producer ->policyCheck ($ producerDao , $ this ->userSession ->Dao , MIDAS_POLICY_ADMIN ) === false
562+ ) {
563+ throw new Zend_Exception ('The producer does not exist or you do not have the necessary permission on its community ' , 403 );
564+ }
565+
566+ $ trendDao ->setIsKeyMetric ($ state === 'true ' );
567+ $ this ->Tracker_Trend ->save ($ trendDao );
568+ }
527569}
0 commit comments