/**
  * Add a condition by a defined xml field
  * @param string $field
  * @param mixed $val
  * @param integer $op
  * @return string the id of the condition (for deletion)
  */
 public function setCondition($field, $val, $op = null)
 {
     if ($op === null) {
         $op = AppKitSQLConstants::SQL_OP_IS;
     }
     $operator = AppKitSQLConstants::getOperator($op);
     if ($op == AppKitSQLConstants::SQL_OP_CONTAIN || $op == AppKitSQLConstants::SQL_OP_NOTCONTAIN) {
         if (strpos($val, '*') === false) {
             $val = '%' . $val . '%';
         } else {
             $val = str_replace('*', '%', $val);
         }
     }
     if ($op == AppKitSQLConstants::SQL_OP_IN || $op == AppKitSQLConstants::SQL_OP_NOT_IN) {
         $val = "(" . $val . ")";
     } else {
         $val = str_replace("'", "'", $val);
     }
     $this->parser->addWhere($field, $operator, $val);
 }
 /**
  * Add a condition by a defined xml field
  * @param string $field
  * @param mixed $val
  * @param integer $op
  * @return string the id of the condition (for deletion)
  */
 public function setCondition($field, $val, $op = null)
 {
     if ($op === null) {
         $op = AppKitSQLConstants::SQL_OP_IS;
     }
     $id = 'c-' . AppKitRandomUtil::genSimpleId(15);
     $filter = $this->getTemplate()->getFieldByName($field, 'filter');
     $database = $this->getTemplate()->getFieldByName($field, 'datasource');
     $new_field = null;
     $ff = $this->getAdditionalFilterFields();
     if (array_key_exists($field, $ff) == true) {
         $new_field = $ff[$field];
     } elseif ($filter->getParameter('field', null)) {
         $new_field = $filter->getParameter('field');
     } else {
         $new_field = $database->getParameter('field');
     }
     if (!$new_field) {
         throw new CronkGridTemplateWorkerException('Could not determine the icinga api field for ' . $field);
     }
     // Add or replace some asterix within count
     if ($op == AppKitSQLConstants::SQL_OP_CONTAIN || $op == AppKitSQLConstants::SQL_OP_NOTCONTAIN) {
         if (strpos($val, '*') === false) {
             $val = '%' . $val . '%';
         } else {
             $val = str_replace('*', '%', $val);
         }
     }
     $new_op = AppKitSQLConstants::getIcingaMatch($op);
     if ($new_op == false) {
         throw new CronkGridTemplateWorkerException('No existing icinga search match operator found!');
     }
     $this->conditions[$id] = array('val' => $val, 'field' => $new_field, 'op' => $new_op);
     return $id;
 }