Example #1
0
 /**
  * Get the display name of the group
  * 
  * @param string $id	group id
  * @return steing 		display name, or id if none found
  */
 public function getGroupDisplayName($id)
 {
     $id = Parser::strtoupper($id);
     //case insensitive
     if (array_key_exists($id, $this->usergroups)) {
         $group = $this->usergroups[$id];
         return (string) $group->display_name;
     } else {
         return $id;
     }
 }
Example #2
0
 /**
  * Return an array of the phrase with all terms AND'd, while 
  * preserving boolean operators and quoted phrases
  * 
  * @return array
  */
 public function normalizedArray($phrase = "")
 {
     if ($phrase == "") {
         $phrase = $this->phrase;
     }
     $bolQuote = false;
     // flags the start and end of a quoted phrase
     $arrWords = array();
     // the query broken into a word array
     $arrFinal = array();
     // final array of words
     $strQuote = "";
     // quoted phrase
     // strip extra spaces
     while (strstr($phrase, "  ")) {
         $phrase = str_replace("  ", " ", $phrase);
     }
     // split words into an array
     $arrWords = explode(" ", $phrase);
     // cycle thru each word in the query
     for ($x = 0; $x < count($arrWords); $x++) {
         if ($bolQuote == true) {
             // we are inside of a quoted phrase
             $strQuote .= " " . $arrWords[$x];
             if (strpos($arrWords[$x], "\"") !== false) {
                 // the end of a quoted phrase
                 $bolQuote = false;
                 if ($x + 1 < count($arrWords)) {
                     if ($arrWords[$x + 1] != "and" && $arrWords[$x + 1] != "or" && $arrWords[$x + 1] != "not") {
                         // the next word is not a boolean operator,
                         // so AND the current one
                         array_push($arrFinal, $strQuote);
                         array_push($arrFinal, "AND");
                     } else {
                         array_push($arrFinal, $strQuote);
                     }
                 } else {
                     array_push($arrFinal, $strQuote);
                 }
                 $strQuote = "";
             }
         } elseif ($bolQuote == false && strpos($arrWords[$x], "\"") !== false) {
             // this is the start of a quoted phrase
             $strQuote .= " " . $arrWords[$x];
             $bolQuote = true;
         } elseif ($arrWords[$x] == "and" || $arrWords[$x] == "or" || $arrWords[$x] == "not") {
             // the current word is a boolean operator
             array_push($arrFinal, Parser::strtoupper($arrWords[$x]));
         } else {
             if ($x + 1 < count($arrWords)) {
                 if ($arrWords[$x + 1] != "and" && $arrWords[$x + 1] != "or" && $arrWords[$x + 1] != "not") {
                     // the next word is not a boolean operator,
                     // so AND the current one
                     array_push($arrFinal, $arrWords[$x]);
                     array_push($arrFinal, "AND");
                 } else {
                     array_push($arrFinal, $arrWords[$x]);
                 }
             } else {
                 array_push($arrFinal, $arrWords[$x]);
             }
         }
     }
     // single quoted phrase
     if (count($arrFinal) == 0 && $strQuote != "") {
         array_push($arrFinal, $strQuote);
     }
     return $arrFinal;
 }