/** * @return bool */ public function valid() { $this->data = $this->db->fetchAssoc($this->res); if (is_array($this->data) && (strpos($this->data['login'], ',') !== false || strpos($this->data['login'], ';') !== false)) { $parts = array_filter(array_map('trim', preg_split("/[ ]*[;,][ ]*/", trim($this->data['login'])))); foreach ($parts as $part) { if (ilStr::strPos(ilStr::strToLower($part), ilStr::strToLower($this->term)) !== false) { $this->users_stack[] = $part; } } if ($this->users_stack) { $this->data = null; } } return is_array($this->data) || count($this->users_stack) > 0; }
public function isKeywordInAnswer($user_answer, $qst_answer) { require_once 'Services/Utilities/classes/class.ilStr.php'; return ilStr::strPos($user_answer, $qst_answer) != FALSE; }
/** * shorten a string to given length. * Adds 3 dots at the end of string (optional) * TODO: do not cut within words (->wordwrap function) * @access public * @param string string to be shortened * @param integer string length in chars * @param boolean adding 3 dots (true) or not (false, default) * @param truncate at first blank after $a_len characters * @return string shortended string * @static * */ public static function shortenText($a_str, $a_len, $a_dots = false, $a_next_blank = false, $a_keep_extension = false) { include_once "./Services/Utilities/classes/class.ilStr.php"; if (ilStr::strLen($a_str) > $a_len) { if ($a_next_blank) { $len = ilStr::strPos($a_str, " ", $a_len); } else { $len = $a_len; } // BEGIN WebDAV // - Shorten names in the middle, before the filename extension // Workaround for Windows WebDAV Client: // Use the unicode ellipsis symbol for shortening instead of // three full stop characters. if ($a_keep_extension) { $p = strrpos($a_str, '.'); // this messes up normal shortening, see bug #6190 } if ($p === false || $p == 0 || strlen($a_str) - $p > $a_len) { $a_str = ilStr::subStr($a_str, 0, $len); if ($a_dots) { $a_str .= "…"; // UTF-8 encoding for Unicode ellipsis character. } } else { if ($a_dots) { $a_str = ilStr::subStr($a_str, 0, $len - (strlen($a_str) - $p + 1)) . "…" . substr($a_str, $p); } else { $a_str = ilStr::subStr($a_str, 0, $len - (strlen($a_str) - $p + 1)) . substr($a_str, $p); } } } return $a_str; }
/** * Checks if one of the keywords matches the answertext * * @param string $answertext The answertext of the user * @param string $a_keyword The keyword which should be checked * @return boolean TRUE if the keyword matches, FALSE otherwise * @access private */ function isKeywordMatching($answertext, $a_keyword) { $result = FALSE; $textrating = $this->getTextRating(); include_once "./Services/Utilities/classes/class.ilStr.php"; switch ($textrating) { case TEXTGAP_RATING_CASEINSENSITIVE: if (ilStr::strPos(ilStr::strToLower($answertext), ilStr::strToLower($a_keyword)) !== false) { return TRUE; } break; case TEXTGAP_RATING_CASESENSITIVE: if (ilStr::strPos($answertext, $a_keyword) !== false) { return TRUE; } break; } // "<p>red</p>" would not match "red" even with distance of 5 $answertext = strip_tags($answertext); $answerwords = array(); if (preg_match_all("/([^\\s.]+)/", $answertext, $matches)) { foreach ($matches[1] as $answerword) { array_push($answerwords, trim($answerword)); } } foreach ($answerwords as $a_original) { switch ($textrating) { case TEXTGAP_RATING_LEVENSHTEIN1: if (levenshtein($a_original, $a_keyword) <= 1) { return TRUE; } break; case TEXTGAP_RATING_LEVENSHTEIN2: if (levenshtein($a_original, $a_keyword) <= 2) { return TRUE; } break; case TEXTGAP_RATING_LEVENSHTEIN3: if (levenshtein($a_original, $a_keyword) <= 3) { return TRUE; } break; case TEXTGAP_RATING_LEVENSHTEIN4: if (levenshtein($a_original, $a_keyword) <= 4) { return TRUE; } break; case TEXTGAP_RATING_LEVENSHTEIN5: if (levenshtein($a_original, $a_keyword) <= 5) { return TRUE; } break; } } return $result; }
/** * Splits the answer string either by space(s) or the separator (eg. ::) and * trims the resulting array elements. * * @param string $in_string OrderElements * @param string $separator to be used for splitting. * * @return array */ private function splitAndTrimOrderElementText($in_string, $separator) { $result = array(); include_once "./Services/Utilities/classes/class.ilStr.php"; if (ilStr::strPos($in_string, $separator) === false) { $result = preg_split("/\\s+/", $in_string); } else { $result = split($separator, $in_string); } foreach ($result as $key => $value) { $result[$key] = trim($value); } return $result; }
/** * * Called by class ilMailFormGUI * * @param string search string surrounded with wildcards * @param string native search string * @return stdClass search result as an object of type stdClass * @access public * */ public function getRecipientAsync($a_search, $a_native_search) { global $ilDB; $query = "SELECT DISTINCT\n\t\t\t\tabook.login login,\n\t\t\t\tabook.firstname firstname,\n\t\t\t\tabook.lastname lastname,\n\t\t\t\t'addressbook' type\n\t\t\tFROM addressbook abook\n\t\t\tWHERE abook.user_id = " . $ilDB->quote($this->user_id, 'integer') . "\n\t\t\tAND abook.login IS NOT NULL\n\t\t\tAND (" . $ilDB->like('abook.login', 'text', $a_search) . "\n\t\t\t\t\tOR " . $ilDB->like('abook.firstname', 'text', $a_search) . "\n\t\t\t\t\tOR " . $ilDB->like('abook.lastname', 'text', $a_search) . "\n\t\t\t)"; $union_query_1 = "SELECT DISTINCT\n\t\t\t\tabook.email login,\n\t\t\t\tabook.firstname firstname,\n\t\t\t\tabook.lastname lastname,\n\t\t\t\t'addressbook' type\n\t\t\tFROM addressbook abook\n\t\t\tWHERE abook.user_id = " . $ilDB->quote($this->user_id, 'integer') . "\n\t\t\tAND abook.login IS NULL\n\t\t\tAND (" . $ilDB->like('abook.email', 'text', $a_search) . "\n\t\t\t\t\tOR " . $ilDB->like('abook.firstname', 'text', $a_search) . "\n\t\t\t\t\tOR " . $ilDB->like('abook.lastname', 'text', $a_search) . "\n\t\t\t)"; $union_query_2 = "SELECT DISTINCT\n\t\t\t\tmail.rcp_to login,\n\t\t\t\t'' firstname,\n\t\t\t\t'' lastname,\n\t\t\t\t'mail' type\n\t\t\tFROM mail\n\t\t\tWHERE " . $ilDB->like('mail.rcp_to', 'text', $a_search) . "\n\t\t\tAND sender_id = " . $ilDB->quote($this->user_id, 'integer') . "\n\t\t\tAND mail.sender_id = mail.user_id"; $queries = array('addressbook_1' => $query, 'mail' => $union_query_2); if ($this->allow_smtp == 1) { $queries['addressbook_2'] = $union_query_1; } include_once 'Services/Utilities/classes/class.ilStr.php'; try { // MySql: Join the array values for mysql to one select statement if ($ilDB->getDbType() != 'oracle') { $queries['all'] = implode(' UNION ', $queries); } foreach ($queries as $type => $query) { // Oracle: Distincts do no work with clobs if ('mail' == $type && $ilDB->getDbType() == 'oracle') { $query = str_replace('DISTINCT', '', $query); } $ilDB->setLimit(0, 20); $query_res = $ilDB->query($query); while ($row = $ilDB->fetchObject($query_res)) { if ($row->type == 'mail') { if (strpos($row->login, ',') || strpos($row->login, ';')) { $parts = preg_split("/[ ]*[;,][ ]*/", trim($row->login)); foreach ($parts as $part) { if (ilStr::strPos(ilStr::strToLower($part), ilStr::strToLower($a_native_search)) !== false) { $this->addResult($part, '', '', 'mail'); } } } else { $this->addResult($row->login, '', '', 'mail'); } } else { $this->addResult($row->login, $row->firstname, $row->lastname, 'addressbook'); } } } } catch (ilException $e) { } return $this->result; }