Example #1
0
 private function CheckCondition($fieldName, $field, $operation, $value, $type = null, $rootActivity = null)
 {
     $result = false;
     $value = $rootActivity->ParseValue($value, $type);
     if ($type == "user") {
         $field = CBPHelper::ExtractUsersFromUserGroups($field, $rootActivity);
         $value = CBPHelper::ExtractUsersFromUserGroups($value, $rootActivity);
     } elseif ($type == "select") {
         if (is_array($field) && CBPHelper::IsAssociativeArray($field)) {
             $field = array_keys($field);
         }
     }
     if (!is_array($field)) {
         $field = array($field);
     }
     if ($operation == "in") {
         foreach ($field as $f) {
             if (is_array($value)) {
                 $result = in_array($f, $value);
             } else {
                 $result = strpos($value, $f) !== false;
             }
             if (!$result) {
                 break;
             }
         }
         return $result;
     }
     if ($operation == "contain") {
         if (!is_array($value)) {
             $value = array($value);
         }
         foreach ($value as $v) {
             foreach ($field as $f) {
                 if (is_array($f)) {
                     $result = in_array($v, $f);
                 } else {
                     $result = strpos($f, $v) !== false;
                 }
                 if ($result) {
                     break;
                 }
             }
             if (!$result) {
                 break;
             }
         }
         return $result;
     }
     if ($operation == 'modified') {
         $modified = $rootActivity->{CBPDocument::PARAM_MODIFIED_DOCUMENT_FIELDS};
         if (!is_array($modified)) {
             return true;
         }
         return in_array($fieldName, $modified);
     }
     if (!is_array($value)) {
         $value = array($value);
     }
     if (CBPHelper::IsAssociativeArray($field)) {
         $field = array_keys($field);
     }
     if (CBPHelper::IsAssociativeArray($value)) {
         $value = array_keys($value);
     }
     $i = 0;
     $fieldCount = count($field);
     $valueCount = count($value);
     $iMax = max($fieldCount, $valueCount);
     while ($i < $iMax) {
         $f1 = $fieldCount > $i ? $field[$i] : $field[$fieldCount - 1];
         $v1 = $valueCount > $i ? $value[$i] : $value[$valueCount - 1];
         if ($type == "datetime" || $type == "date") {
             if (($f1Tmp = MakeTimeStamp($f1, FORMAT_DATETIME)) === false) {
                 if (($f1Tmp = MakeTimeStamp($f1, FORMAT_DATE)) === false) {
                     if (($f1Tmp = MakeTimeStamp($f1, "YYYY-MM-DD HH:MI:SS")) === false) {
                         if (($f1Tmp = MakeTimeStamp($f1, "YYYY-MM-DD")) === false) {
                             $f1Tmp = 0;
                         }
                     }
                 }
             }
             $f1 = $f1Tmp;
             if (($v1Tmp = MakeTimeStamp($v1, FORMAT_DATETIME)) === false) {
                 if (($v1Tmp = MakeTimeStamp($v1, FORMAT_DATE)) === false) {
                     if (($v1Tmp = MakeTimeStamp($v1, "YYYY-MM-DD HH:MI:SS")) === false) {
                         if (($v1Tmp = MakeTimeStamp($v1, "YYYY-MM-DD")) === false) {
                             $v1Tmp = 0;
                         }
                     }
                 }
             }
             $v1 = $v1Tmp;
         }
         switch ($operation) {
             case ">":
                 $result = $f1 > $v1;
                 break;
             case ">=":
                 $result = $f1 >= $v1;
                 break;
             case "<":
                 $result = $f1 < $v1;
                 break;
             case "<=":
                 $result = $f1 <= $v1;
                 break;
             case "!=":
                 $result = $f1 != $v1;
                 break;
             default:
                 $result = $f1 == $v1;
         }
         if (!$result) {
             break;
         }
         $i++;
     }
     return $result;
 }
 private function CheckCondition($field, $operation, $value, $type = null, $rootActivity = null)
 {
     $result = false;
     $value = $rootActivity->ParseValue($value);
     if ($type == "user") {
         $field = CBPHelper::ExtractUsersFromUserGroups($field, $rootActivity);
         $value = CBPHelper::ExtractUsersFromUserGroups($value, $rootActivity);
     }
     if (!is_array($field)) {
         $field = array($field);
     }
     if ($operation == "in") {
         foreach ($field as $f) {
             if (is_array($value)) {
                 $result = in_array($f, $value);
             } else {
                 $result = strpos($value, $f) !== false;
             }
             if (!$result) {
                 break;
             }
         }
         return $result;
     }
     if (!is_array($value)) {
         $value = array($value);
     }
     $i = 0;
     $fieldCount = count($field);
     $valueCount = count($value);
     if ($fieldCount == 0 && $valueCount == 0) {
         return in_array($operation, array("=", ">=", "<="));
     }
     $iMax = max($fieldCount, $valueCount);
     while ($i < $iMax) {
         $f1 = $fieldCount > $i ? $field[$i] : $field[$fieldCount - 1];
         $v1 = $valueCount > $i ? $value[$i] : $value[$valueCount - 1];
         if ($type == "datetime") {
             if (($f1Tmp = MakeTimeStamp($f1, FORMAT_DATETIME)) === false) {
                 if (($f1Tmp = MakeTimeStamp($f1, FORMAT_DATE)) === false) {
                     if (($f1Tmp = MakeTimeStamp($f1, "YYYY-MM-DD HH:MI:SS")) === false) {
                         if (($f1Tmp = MakeTimeStamp($f1, "YYYY-MM-DD")) === false) {
                             $f1Tmp = 0;
                         }
                     }
                 }
             }
             $f1 = $f1Tmp;
             if (($v1Tmp = MakeTimeStamp($v1, FORMAT_DATETIME)) === false) {
                 if (($v1Tmp = MakeTimeStamp($v1, FORMAT_DATE)) === false) {
                     if (($v1Tmp = MakeTimeStamp($v1, "YYYY-MM-DD HH:MI:SS")) === false) {
                         if (($v1Tmp = MakeTimeStamp($v1, "YYYY-MM-DD")) === false) {
                             $v1Tmp = 0;
                         }
                     }
                 }
             }
             $v1 = $v1Tmp;
         }
         switch ($operation) {
             case ">":
                 $result = $f1 > $v1;
                 break;
             case ">=":
                 $result = $f1 >= $v1;
                 break;
             case "<":
                 $result = $f1 < $v1;
                 break;
             case "<=":
                 $result = $f1 <= $v1;
                 break;
             case "!=":
                 $result = $f1 != $v1;
                 break;
             default:
                 $result = $f1 == $v1;
         }
         if (!$result) {
             break;
         }
         $i++;
     }
     return $result;
 }