Skip to content

Commit

Permalink
refs matomo-org#1486 some more cleanup, bugfixes and moved defined me…
Browse files Browse the repository at this point in the history
…trics/group conditions to the processor as only this class can know which ones it supports
  • Loading branch information
tsteur committed Dec 20, 2013
1 parent 3bd9c0b commit 450e861
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 190 deletions.
74 changes: 39 additions & 35 deletions plugins/CustomAlerts/API.php
Expand Up @@ -22,32 +22,29 @@
*/
class API extends \Piwik\Plugin\API
{

private function getModel()
{
return new Model();
}

/**
* Returns a single Alert
*
* @param int $idAlert
*/
/**
* Returns a single Alert
*
* @param int $idAlert
*
* @return array
*/
public function getAlert($idAlert)
{
return $this->getModel()->getAlert($idAlert);
}

/**
* Returns the Alerts that are defined on the idSites given.
* If no value is given, all Alerts for the current user will
* be returned.
*
* @param array $idSites
*/
/**
* Returns the Alerts that are defined on the idSites given.
* If no value is given, all Alerts for the current user will
* be returned.
*
* @param array $idSites
* @return array
*/
public function getAlerts($idSites = array())
{
return $this->getModel()->getAlert($idSites);
return $this->getModel()->getAlerts($idSites);
}

public function getTriggeredAlerts($period, $date, $login = false)
Expand Down Expand Up @@ -80,22 +77,23 @@ public function addAlert($name, $idSites, $period, $email, $metric, $metricCondi
return $this->getModel()->addAlert($name, $idSites, $period, $email, $metric, $metricCondition, $metricValue, $report, $reportCondition, $reportValue);
}

/**
* Edits an Alert for given website(s).
*
* @param string $idalert ID of the Alert to edit.
* @param string $name Name of Alert
* @param mixed $idSites Single int or array of ints of idSites.
* @param string $period Period the alert is defined on.
* @param bool $email
* @param string $metric (nb_uniq_visits, sum_visit_length, ..)
* @param string $metricCondition
* @param float $metricValue
* @param string $report
* @param string $reportCondition
* @param string $reportValue
* @return boolean
*/
/**
* Edits an Alert for given website(s).
*
* @param $idAlert
* @param string $name Name of Alert
* @param mixed $idSites Single int or array of ints of idSites.
* @param string $period Period the alert is defined on.
* @param bool $email
* @param string $metric (nb_uniq_visits, sum_visit_length, ..)
* @param string $metricCondition
* @param float $metricValue
* @param string $report
* @param string $reportCondition
* @param string $reportValue
*
* @return boolean
*/
public function editAlert($idAlert, $name, $idSites, $period, $email, $metric, $metricCondition, $metricValue, $report, $reportCondition = '', $reportValue = '')
{
return $this->getModel()->editAlert($idAlert, $name, $idSites, $period, $email, $metric, $metricCondition, $metricValue, $report, $reportCondition, $reportValue);
Expand All @@ -110,5 +108,11 @@ public function deleteAlert($idAlert)
{
$this->getModel()->deleteAlert($idAlert);
}

private function getModel()
{
return new Model();
}

}
?>
59 changes: 14 additions & 45 deletions plugins/CustomAlerts/Controller.php
Expand Up @@ -26,40 +26,17 @@
class Controller extends \Piwik\Plugin\Controller
{

private $alertGroupConditions = array(
'CustomAlerts_MatchesExactly' => 'matches_exactly',
'CustomAlerts_DoesNotMatchExactly' => 'does_not_match_exactly',
'CustomAlerts_MatchesRegularExpression' => 'matches_regex',
'CustomAlerts_DoesNotMatchRegularExpression' => 'does_not_match_regex',
'CustomAlerts_Contains' => 'contains',
'CustomAlerts_DoesNotContain' => 'does_not_contain',
'CustomAlerts_StartsWith' => 'starts_with',
'CustomAlerts_DoesNotStartWith' => 'does_not_start_with',
'CustomAlerts_EndsWith' => 'ends_with',
'CustomAlerts_DoesNotEndWith' => 'does_not_end_with',
);
private $alertMetricConditions = array(
'CustomAlerts_IsLessThan' => 'less_than',
'CustomAlerts_IsGreaterThan' => 'greater_than',
'CustomAlerts_DecreasesMoreThan' => 'decrease_more_than',
'CustomAlerts_IncreasesMoreThan' => 'increase_more_than',
'CustomAlerts_PercentageDecreasesMoreThan' => 'percentage_decrease_more_than',
'CustomAlerts_PercentageIncreasesMoreThan' => 'percentage_increase_more_than',
);

/**
* Shows all Alerts of the current selected idSite.
*/
public function index()
{
$view = new View('@CustomAlerts/index');
$this->setGeneralVariablesView($view);

$idSite = Common::getRequestVar('idSite');
$idSite = Common::getRequestVar('idSite', null, 'int');

$alertList = API::getInstance()->getAlerts(array($idSite));
$view = new View('@CustomAlerts/index');
$this->setGeneralVariablesView($view);

$view->alertList = $alertList;
$view->alerts = API::getInstance()->getAlerts(array($idSite));

return $view->render();
}
Expand All @@ -69,42 +46,34 @@ public function addNewAlert()
$view = new View('@CustomAlerts/addNewAlert');
$this->setGeneralVariablesView($view);

$sitesList = SitesManagerApi::getInstance()->getSitesWithAtLeastViewAccess();
$view->sitesList = $sitesList;

$availableReports = MetadataApi::getInstance()->getReportMetadata();
$view->sitesList = SitesManagerApi::getInstance()->getSitesWithAtLeastViewAccess();

// ToDo need to collect metrics,processedMetrics,goalMetrics, goalProcessedMetric

$view->alertGroups = array();
$view->alerts = $availableReports;
$view->alertGroupConditions = $this->alertGroupConditions;
$view->alertMetricConditions = $this->alertMetricConditions;
$view->alerts = MetadataApi::getInstance()->getReportMetadata();
$view->alertGroupConditions = Processor::getGroupConditions();
$view->alertMetricConditions = Processor::getMetricConditions();

return $view->render();
}

public function editAlert()
{
$idAlert = Common::getRequestVar('idalert');
$idAlert = Common::getRequestVar('idAlert', null, 'int');

$view = new View('@CustomAlerts/editAlert');
$this->setGeneralVariablesView($view);

$alert = API::getInstance()->getAlert($idAlert);
$view->alert = $alert;

$sitesList = SitesManagerApi::getInstance()->getSitesWithAtLeastViewAccess();
$view->sitesList = $sitesList;
$view->alert = API::getInstance()->getAlert($idAlert);
$view->sitesList = SitesManagerApi::getInstance()->getSitesWithAtLeastViewAccess();

$model = new Model();
$view->sitesDefined = $model->fetchSiteIdsTheAlertWasDefinedOn($idAlert);

$availableReports = MetadataApi::getInstance()->getReportMetadata();

$view->alerts = $availableReports;
$view->alertGroupConditions = $this->alertGroupConditions;
$view->alertMetricConditions = $this->alertMetricConditions;
$view->alerts = MetadataApi::getInstance()->getReportMetadata();
$view->alertGroupConditions = Processor::getGroupConditions();
$view->alertMetricConditions = Processor::getMetricConditions();

return $view->render();
}
Expand Down

0 comments on commit 450e861

Please sign in to comment.