/**
  * Adds where and having conditions
  */
 public function addWhere()
 {
     $time = microtime(true);
     $where = array();
     if (!empty($this->config['where'])) {
         $tmp = $this->config['where'];
         if (is_string($tmp) && ($tmp[0] == '{' || $tmp[0] == '[')) {
             $tmp = $this->modx->fromJSON($tmp);
         }
         if (!is_array($tmp)) {
             $tmp = array($tmp);
         }
         $where = $this->replaceTVCondition($tmp);
     }
     $where = $this->additionalConditions($where);
     if (!empty($where)) {
         $this->query->where($where);
         $condition = array();
         foreach ($where as $k => $v) {
             if (is_array($v)) {
                 if (isset($v[0])) {
                     $condition[] = is_array($v) ? $k . '(' . implode(',', $v) . ')' : $k . '=' . $v;
                 } else {
                     foreach ($v as $k2 => $v2) {
                         $condition[] = is_array($v2) ? $k2 . '(' . implode(',', $v2) . ')' : $k2 . '=' . $v2;
                     }
                 }
             } else {
                 $condition[] = $k . '=' . $v;
             }
         }
         $this->addTime('Added where condition: <b>' . implode(', ', $condition) . '</b>', microtime(true) - $time);
     }
     $time = microtime(true);
     if (!empty($this->config['having'])) {
         $tmp = $this->config['having'];
         if (is_string($tmp) && ($tmp[0] == '{' || $tmp[0] == '[')) {
             $tmp = $this->modx->fromJSON($tmp);
         }
         $having = $this->replaceTVCondition($tmp);
         $this->query->having($having);
         $condition = array();
         foreach ($having as $k => $v) {
             if (is_array($v)) {
                 $condition[] = $k . '(' . implode(',', $v) . ')';
             } else {
                 $condition[] = $k . '=' . $v;
             }
         }
         $this->addTime('Added having condition: <b>' . implode(', ', $condition) . '</b>', microtime(true) - $time);
     }
 }