Пример #1
0
 /**
  * Convert segment expression to an action ID or an SQL expression.
  * 
  * This method is used as a sqlFilter-callback for the segments of this plugin.
  * Usually, these callbacks only return a value that should be compared to the
  * column in the database. In this case, that doesn't work since multiple IDs
  * can match an expression (e.g. "pageUrl=@foo").
  */
 function getIdActionFromSegment($string, $sqlField, $matchType = '==')
 {
     // Field is visit_*_idaction_url or visit_*_idaction_name
     $actionType = strpos($sqlField, '_name') === false ? Piwik_Tracker_Action::TYPE_ACTION_URL : Piwik_Tracker_Action::TYPE_ACTION_NAME;
     // exact matches work by returning the id directly
     if ($matchType == Piwik_SegmentExpression::MATCH_EQUAL || $matchType == Piwik_SegmentExpression::MATCH_NOT_EQUAL) {
         $sql = Piwik_Tracker_Action::getSqlSelectActionId();
         $bind = array($string, $string, $actionType);
         $idAction = Piwik_FetchOne($sql, $bind);
         // if the action is not found, we hack -100 to ensure it tries to match against an integer
         // otherwise binding idaction_name to "false" returns some rows for some reasons (in case &segment=pageTitle==Větrnásssssss)
         if (empty($idAction)) {
             $idAction = -100;
         }
         return $idAction;
     }
     // now, we handle the cases =@ (contains) and !@ (does not contain)
     // build the expression based on the match type
     $sql = 'SELECT idaction FROM ' . Piwik_Common::prefixTable('log_action') . ' WHERE ';
     switch ($matchType) {
         case '=@':
             // use concat to make sure, no %s occurs because some plugins use %s in their sql
             $sql .= '( name LIKE CONCAT("%", ?, "%") AND type = ' . $actionType . ' )';
             break;
         case '!@':
             $sql .= '( name NOT LIKE CONCAT("%", ?, "%") AND type = ' . $actionType . ' )';
             break;
         default:
             throw new Exception("This match type is not available for action-segments.");
             break;
     }
     return array('SQL' => $sql, 'bind' => $string);
 }
Пример #2
0
 function getIdActionFromString($string, $sqlField)
 {
     // Field is visit_*_idaction_url or visit_*_idaction_name
     $actionType = strpos($sqlField, '_name') === false ? Piwik_Tracker_Action::TYPE_ACTION_URL : Piwik_Tracker_Action::TYPE_ACTION_NAME;
     $sql = Piwik_Tracker_Action::getSqlSelectActionId();
     $bind = array($string, $string, $actionType);
     $idAction = Zend_Registry::get('db')->fetchOne($sql, $bind);
     return $idAction;
 }