function _gs_utf8_get_map() { $map = array(); $lines = @file(dirName(__FILE__) . '/Translit.txt'); if (!is_array($lines)) { return $map; } foreach ($lines as $line) { $line = trim($line); if ($line == '' || subStr($line, 0, 1) == '#') { continue; } $tmp = explode(';', $line, 3); $char = rTrim(@$tmp[0]); $translit = trim(@$tmp[1]); if (!$translit) { $map[$char] = ''; } else { $char = hexUnicodeToUtf8($char); $tmp = @preg_split('/\\s+/S', $translit); if (!is_array($tmp)) { continue; } $t = ''; foreach ($tmp as $translit) { $t .= hexUnicodeToUtf8($translit); } $map[$char] = $t; } } return $map; }
function _generate_settings($model, $appl, $rtfs, $lnux) { global $firmware_url, $firmware_path, $mac, $phone_type, $user; $file = ''; if (!empty($appl)) { $file = $model . '-' . $appl . '.bin'; } elseif (!empty($rtfs)) { $file = $model . '-' . $rtfs; } elseif (!empty($lnux)) { $file = $model . '-' . $lnux . '-l.bin'; } if ($file != '') { if (subStr($firmware_path, -1) != '/') { $firmware_path .= '/'; } $realfile = $firmware_path . $file; if (!file_exists($realfile) || !is_readable($realfile)) { # It's important to make sure we don't point the phone to a # non-existent file or else the phone needs manual interaction # (something like "File not found. Press any key to continue.") gs_log(GS_LOG_WARNING, "File \"{$realfile}\" not found"); } else { $url = $firmware_url . rawUrlEncode($file); gs_log(GS_LOG_NOTICE, "Snom {$mac} ({$phone_type}, user {$user}): Update file: \"{$file}\""); //$ob = 'pnp_config$: off' ."\n"; $ob = 'firmware: ' . $url . "\n"; if (!headers_sent()) { header('Content-Length: ' . strLen($ob)); # avoid chunked transfer-encoding } echo $ob; } } exit; }
function get_google_weather($city) { $url = 'http://www.google.com/ig/api?hl=en&weather=' . $city; $file = file_get_contents($url); $file = utf8_encode($file); $response = simplexml_load_string($file); $data = array(); # city / state $tmp = explode(',', $response->weather->forecast_information->city->attributes()->data); $data['city'] = trim($tmp[0]); $data['state'] = trim($tmp[1]); # temperature $data['temperature'] = $response->weather->current_conditions->temp_c->attributes()->data; # time $data['time'] = subStr($response->weather->forecast_information->current_date_time->attributes()->data, 0, 19); # date $tmp = explode('-', $response->weather->forecast_information->forecast_date->attributes()->data); $data['date'] = $tmp[1] . '/' . $tmp[2] . '/' . $tmp[0]; # weather //$tmp = $response->weather->current_conditions->condition->attributes()->data; switch ($response->weather->current_conditions->condition->attributes()->data) { case 'Mostly Cloudy': $data['weather'] = 'Mostly Cloudy'; break; case 'Chance of Rain': $data['weather'] = 'Rain'; break; case 'Partly Sunny': $data['weather'] = 'Sunny'; break; } return $data; }
function onOpen() { $key = $this->getAttribute('key'); $obj = $this->getDocument()->getVariable($key); if(is_object($obj) || is_array($obj)) { foreach($obj as $k=>$v) { $this->getDocument()->setVariable($k, $v); } if(is_object($obj)){ // Loop thru each method to detect it's a getter and include its ret value $rClass = new ReflectionClass($obj); foreach($rClass->getMethods() as $rMethod){ ($mn = $rMethod->getName()); if($rMethod->isPublic() && ('get' === substr($mn,0,3)) && (0 == count($rMethod->getParameters()))) { $var = subStr($mn,3); //extract the variable name $var[0] = strToLower($var[0]); //lower first letter case $this->getDocument()->setVariable($var, $rMethod->invoke($obj) ); } } } return self::PROCESS_BODY; } return self::SKIP_BODY; }
function conv_ringtone($infile, $outbase) { /* $outfile = $outbase .'.wav'; */ $outfile = $outbase . '.mp3'; if (strToLower(subStr($infile, -4, 4)) === '.mp3') { if (fileSize($infile) <= 1000000) { # 1 MB if (!@copy($infile, $outfile)) { return false; } return $outfile; } } /* if (is_executable( '/usr/local/bin/mpg123' )) $mpg123 = '/usr/local/bin/mpg123'; elseif (is_executable( '/usr/bin/mpg123' )) $mpg123 = '/usr/bin/mpg123'; elseif (is_executable( '/bin/mpg123' )) $mpg123 = '/bin/mpg123'; else $mpg123 = 'mpg123'; if (strToLower(subStr($infile, -4, 4)) === '.mp3') { # convert mp3 to wav first $wavfile = $infile .'.wav'; $cmd = $mpg123 .' -m -w - -n 1000 -q '. qsa($infile) .' > '. qsa($wavfile) .' 2>>/dev/null'; # cuts file after 1000 frames (around 2.3 MB, depending on the rate) # don't use -r 8000 as that doesn't really work for VBR encoded MP3s @exec($cmd, $out, $err); if ($err != 0) { if (is_file($wavfile)) @unlink( $wavfile ); return false; } $infile = $wavfile; $rm_tmp = $wavfile; } else $rm_tmp = false; $cmd = 'sox '. qsa($infile) .' -r 8000 -c 1 -w '. qsa($outfile) .' trim 0 125000s 2>>/dev/null'; # WAV, PCM, 8 kHz, 16 bit, mono # "The time for loading the file should not be longer then 3 seconds. # Size < 250 KByte." # cuts file after 125000 samples (around 245 kB, 15 secs) @exec($cmd, $out, $err); if ($err != 0) { # $err == 2 would be unknown format if (is_file($outfile)) @unlink( $outfile ); if ($rm_tmp && is_file($rm_tmp)) @unlink($rm_tmp); return false; } return $outfile; */ //return false; return null; # not implemented }
function setRerunFlag($status) { $result = $status; if (strlen($status) >= 5) { $result = subStr($status, 0, 3) . '1' . subStr($status, 4, 1); } return $result; }
/** * @return \Nano\Route\Common * @param string $location * @param string $controller * @param string $action * @param string $module * @param array $params */ public static function create($location, $controller = 'index', $action = 'index', $module = null, array $params = array()) { if ('' === $location || null === $location) { return new \Nano\Route\StaticLocation($location, $controller, $action, $module, $params); } if (self::PREFIX_REGEXP == $location[0]) { return new \Nano\Route\RegExp(subStr($location, 1), $controller, $action, $module, $params); } return new \Nano\Route\StaticLocation($location, $controller, $action, $module, $params); }
/** * @return string * @param string $name * @param boolean $controller * @param string|null $module */ public static function formatName($name, $controller = true, $module = null) { if ($controller) { return \Nano\Names::controllerClass($name, $module); } $result = \Nano::stringToName($name); $result = strToLower($result[0]) . subStr($result, 1); $result .= self::SUFFIX_ACTION; return $result; }
function grandstream_binary_output_checksum($str) { $sum = 0; for ($i = 0; $i <= (strLen($str) - 1) / 2; $i++) { $sum += ord(subStr($str, 2 * $i, 1)) << 8; $sum += ord(subStr($str, 2 * $i + 1, 1)); $sum &= 0xffff; } $sum = 0x10000 - $sum; return array($sum >> 8 & 0xff, $sum & 0xff); }
function setView($viewURI) { if (@file_exists($viewURI)) { $this->view = $viewURI; } else { if (APP_VIEWS_LOCATION . $viewURI) { $this->view = APP_VIEWS_LOCATION . $viewURI; } } $this->type = strToLower(subStr($this->view, strRPos($this->view, ".") + 1)); }
protected function getObjects() { /** @var \Pharborist\NodeCollection $objects */ $objects = $this->target->getIndexer($this->configuration['type'])->get($this->configuration['id']); if (isset($this->configuration['where'])) { $where = $this->configuration['where']; // If the first character of the filter is an exclamation point, negate it. return $where[0] == '!' ? $objects->not(subStr($where, 1)) : $objects->filter($where); } else { return $objects; } }
function verifyLCCN() { ## remove "-" and fill with "0" to make 8 char long $pos = strPos($lookupVal, "-"); if ($pos > 0) { $lccnLeft = subStr($lookupVal, 0, $pos); $lccnRight = subStr($lookupVal, $pos + 1, 6); $lccnRight = str_pad($lccnRight, 6, "0", STR_PAD_LEFT); $lookupVal = $lccnLeft . $lccnRight; } return $lookupVal; }
/** * {@inheritdoc} */ public function id() { if (empty($this->id)) { $dir = $this->getBasePath(); $info = (new Finder())->in($dir)->depth('== 0')->name('*.info')->getIterator(); $info->rewind(); if ($info_file = $info->current()) { $this->id = subStr($info_file->getFilename(), 0, -5); } else { throw new \RuntimeException(SafeMarkup::format('Could not find info file in @dir', ['@dir' => $dir])); } } return $this->id; }
public static function formatName($name, $controller = true) { $result = strToLower($name); $result = str_replace('-', ' ', $result); $result = ucWords($result); $result = str_replace(' ', '', $result); $result = trim($result); if ($controller) { $result .= self::SUFFIX_CONTROLLER; } else { $result = strToLower($result[0]) . subStr($result, 1); $result .= self::SUFFIX_ACTION; } return $result; }
function conv_ringtone($infile, $outbase) { $outfile = $outbase . '.ul'; if (is_executable('/usr/local/bin/mpg123')) { $mpg123 = '/usr/local/bin/mpg123'; } elseif (is_executable('/usr/bin/mpg123')) { $mpg123 = '/usr/bin/mpg123'; } elseif (is_executable('/bin/mpg123')) { $mpg123 = '/bin/mpg123'; } else { $mpg123 = 'mpg123'; } if (strToLower(subStr($infile, -4, 4)) === '.mp3') { # convert mp3 to wav first $wavfile = $infile . '.wav'; $cmd = $mpg123 . ' -m -w - -n 1000 -q ' . qsa($infile) . ' > ' . qsa($wavfile) . ' 2>>/dev/null'; # cuts file after 1000 frames (around 2.3 MB, depending on the rate) # don't use -r 8000 as that doesn't really work for VBR encoded MP3s @exec($cmd, $out, $err); if ($err != 0) { if (is_file($wavfile)) { @unlink($wavfile); } return false; } $infile = $wavfile; $rm_tmp = $wavfile; } else { $rm_tmp = false; } $cmd = 'sox ' . qsa($infile) . ' -r 8000 -c 1 ' . qsa($outfile) . ' trim 0 65000s 2>>/dev/null'; # WAV, PCM, 16 kHz, 8 bit, mono # cuts file after 65000 samples (around 65 kB) @exec($cmd, $out, $err); if ($err != 0) { # $err == 2 would be unknown format if (is_file($outfile)) { @unlink($outfile); } if ($rm_tmp && is_file($rm_tmp)) { @unlink($rm_tmp); } return false; } return $outfile; //return false; //return null; # not implemented }
function find_executable($basename, $paths) { if (!is_array($paths)) { return false; } foreach ($paths as $path) { if (subStr($path, -1) != '/') { $path .= '/'; } $full = $path . $basename; if (is_executable($full)) { return $full; } } return false; }
/** PSR-0 class loading function */ public function tryLoadClass($className) { $toReplace = strpos($className, '\\') === false ? '_' : '\\'; $relativePath = str_replace($toReplace, DIRECTORY_SEPARATOR, $className) . '.php'; foreach ($this->spaceMap as $space => $dir) { if (subStr($className, 0, strLen($space)) == $space) { $filePath = $dir . DIRECTORY_SEPARATOR . $relativePath; //print "<br>\n looking for '$filePath'"; if (file_exists($filePath)) { //print " FOUND"; include $filePath; return true; } } } return false; }
/** * @return void * @param string $url */ public static function run($url = null) { self::instance(); include SETTINGS . DS . 'routes.php'; if (null === $url) { $url = $_SERVER['REQUEST_URI']; if (false !== strPos($url, '?')) { $url = subStr($url, 0, strPos($url, '?')); } if (self::config('web')->url && 0 === strPos($url, self::config('web')->url)) { $url = subStr($url, strLen(self::config('web')->url)); } if (self::config('web')->index) { $url = preg_replace('/' . preg_quote(self::config('web')->index) . '$/', '', $url); } } echo self::instance()->dispatcher->dispatch(self::instance()->routes, $url); }
/** * Instantiates a new version of the GFPhone object * @method __construct * @param string $phoneNumber Phone numnber */ function __construct($phoneNumber = "") { if ($phoneNumber != "") { // extract only the digits from the passed value $this->rawNumber = (string) intval(preg_replace('/[^0-9]+/', '', $phoneNumber), 10); if (strlen($this->rawNumber) == 10) { $this->forceRaw = false; $this->countryCode = 1; // default to NA $this->areaCode = substr($this->rawNumber, 0, 3); $this->prefix = subStr($this->rawNumber, 3, 3); $this->extension = substr($this->rawNumber, 6, 4); $this->local = ""; } elseif (strlen($this->rawNumber) == 11) { $this->forceRaw = false; $this->countryCode = substr($this->rawNumber, 0, 1); $this->areaCode = substr($this->rawNumber, 0, 3); $this->prefix = subStr($this->rawNumber, 3, 3); $this->extension = substr($this->rawNumber, 6, 4); $this->local = ""; } elseif (strlen($this->rawNumber) > 11) { $this->countryCode = substr($this->rawNumber, 0, 1); $this->areaCode = substr($this->rawNumber, 0, 3); $this->prefix = subStr($this->rawNumber, 3, 3); $this->extension = substr($this->rawNumber, 6, 4); $this->local = substr($this->rawNumber, 10); } else { $this->forceRaw = true; $this->countryCode = ""; $this->areaCode = ""; $this->prefix = ""; $this->extension = ""; $this->local = ""; } } else { $this->forceRaw = true; $this->rawNumber = $phoneNumber; $this->countryCode = ""; $this->areaCode = ""; $this->prefix = ""; $this->extension = ""; } }
public function test_mod_ratingallocate_generated_module() { $record = mod_ratingallocate_generator::get_default_values(); foreach ($record as $name => $value) { if (subStr($name, strlen($name) - 7, 7) === 'maxsize') { $record[$name] = 10; } if (subStr($name, strlen($name) - 6, 6) === 'active') { $record[$name] = true; } } $record['num_students'] = 22; $test_module = new mod_ratingallocate_generated_module($this, $record); $this->assertCount($record['num_students'], $test_module->students); $this->assertCount(20, $test_module->allocations); $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $test_module->mod_db, $test_module->teacher); foreach ($ratingallocate->get_choices_with_allocationcount() as $choice) { $this->assertEquals(10, $choice->{'usercount'}); } }
function getButtonValHack() { if (!array_key_exists('whichform', $_REQUEST)) { return null; } $whichform = $_REQUEST['whichform']; $buttonval_key = 'buttonval'; if ($whichform == 4) { if (array_key_exists('buttonval4a', $_REQUEST)) { $buttonval_key = 'buttonval4a'; } elseif (array_key_exists('buttonval4b', $_REQUEST)) { $buttonval_key = 'buttonval4b'; } } if (array_key_exists($buttonval_key, $_REQUEST) && subStr($_REQUEST[$buttonval_key], 0, 5) === 'test-') { return $_REQUEST[$buttonval_key]; } elseif (array_key_exists($buttonval_key, $_REQUEST) && preg_match('/test-[0-9a-z]+/', $_REQUEST[$buttonval_key], $m)) { return $m[0]; } }
protected function getSingleComment(Comment $comment) { $text = $this->text; $id = $comment->getId(); $contextUrl = $text->e($text->getUrlPage("article", $comment->getArticleId())->withFragment('comment_' . $id)); $returnValue = '<article class="comment_preview">'; // Get author name (and link) and use it as the title $authorName = htmlSpecialChars($comment->getUserDisplayName()); $authorId = $comment->getUserId(); if ($authorId > 0) { // Add link to author profile $authorName = '<a href="' . $text->e($text->getUrlPage("account", $authorId)) . '">' . $authorName . "</a>"; } $returnValue .= '<header><h3 class="comment_title">' . $authorName . "</h3></header>\n"; // Get body text and limit its length // (Whole body links to context of comment) $bodyRaw = $comment->getBodyRaw(); if (strLen($bodyRaw) > self::MAX_TEXT_LENGTH) { $bodyRaw = subStr($bodyRaw, 0, self::MAX_TEXT_LENGTH - 3) . '...'; } $body = htmlSpecialChars($bodyRaw); $returnValue .= <<<EOT <p> <a class="disguised_link" href="{$contextUrl}"> {$body} </a> </p> EOT; // Add a link for some context $returnValue .= <<<EOT <footer> <p> <a class="arrow" href="{$contextUrl}"> {$text->t("comments.view_context")} </a> </p> </footer> EOT; $returnValue .= "</article>"; return $returnValue; }
private function getSQLQuery($isSearch, $pageArray, $userQuery, $playlist) { $db = new db(); $db->connect(); if ($playlist == 'playlistList') { if ($isSearch) { $searchTerm = '%' . mysql_real_escape_string($userQuery) . '%'; return 'SELECT * from playlists WHERE name LIkE \'' . $searchTerm . '\' LIMIT ' . $pageArray[0] . ', ' . $pageArray[1] . ';'; } else { return 'SELECT * from playlists WHERE 1 LIMIT ' . $pageArray[0] . ', ' . $pageArray[1] . ';'; } } else { $playlistQuery = $this->queryPlaylist($playlist); if ($isSearch) { $searchTerm = '%' . mysql_real_escape_string($userQuery) . '%'; return 'SELECT * FROM videos WHERE `id` = "' . subStr($searchTerm, 1, 11) . '" OR title LIKE \'' . $searchTerm . '\' AND ' . $playlistQuery . ' OR keywords LIKE \'' . $searchTerm . '\' AND ' . $playlistQuery . ' ORDER BY publishedOrder DESC LIMIT ' . $pageArray[0] . ', ' . $pageArray[1] . ';'; } else { return 'SELECT * FROM videos WHERE ' . $playlistQuery . ' ORDER BY publishedOrder DESC LIMIT ' . $pageArray[0] . ', ' . $pageArray[1] . ';'; } } }
/** * {@inheritdoc} */ public function rewrite(FunctionCallNode $call, TargetInterface $target) { $arguments = $call->getArguments(); // We'll call a specific method on the logger object, depending on the // severity passed in the original function call (if any). If there are // at least four arguments, a severity was passed. We check $arguments[3] // to ensure it's a valid severity constant, and if it's not, we default // to the notice() severity. // // @TODO Leave a FIXME for an invalid severity, since changing it to a // notice alters the intent of the original code. // if (sizeof($arguments) > 3 && $arguments[3] instanceof ConstantNode && in_array($arguments[3]->getConstantName()->getText(), static::$severityConstants)) { $method = strtolower(subStr($arguments[3], 9)); } else { $method = 'notice'; } // If there is a third argument, and it's an array, a context array // was passed. $context = sizeof($arguments) > 2 && $arguments[2] instanceof ArrayNode ? clone $arguments[2] : ArrayNode::create([]); return ClassMethodCallNode::create('\\Drupal', 'logger')->appendArgument(clone $arguments[0])->appendMethodCall($method)->appendArgument(clone $arguments[1])->appendArgument($context); }
function aastra_push_str($phone_ip, $xml) { $prov_host = gs_get_conf('GS_PROV_HOST'); //FIXME - call wget or something. this function should not block // for so long! // see _gs_prov_phone_checkcfg_by_ip_do_aastra() in // opt/gemeinschaft/inc/gs-fns/gs_prov_phone_checkcfg.php //$xml = utf8_decode($xml); if (subStr($xml, 0, 5) !== '<' . '?xml') { $xmlpi = '<' . '?xml version="1.0" encoding="UTF-8"?' . '>' . "\n"; } else { $xmlpi = ''; } $data = "POST / HTTP/1.1\r\n"; $data .= "Host: {$phone_ip}\r\n"; $data .= "Referer: {$prov_host}\r\n"; $data .= "Connection: Close\r\n"; $data .= "Content-Type: text/xml; charset=utf-8\r\n"; $data .= "Content-Length: " . (strLen('xml=') + strLen($xmlpi) + strLen($xml)) . "\r\n"; $data .= "\r\n"; $data .= 'xml=' . $xmlpi . $xml; $socket = @fSockOpen($phone_ip, 80, $error_no, $error_str, 4); if (!$socket) { gs_log(GS_LOG_NOTICE, "Aastra: Failed to open socket - IP: {$phone_ip}"); return 0; } stream_set_timeout($socket, 4); $bytes_written = (int) @fWrite($socket, $data, strLen($data)); @fFlush($socket); $response = @fGetS($socket); @fClose($socket); if (strPos($response, '200') === false) { gs_log(GS_LOG_WARNING, "Aastra: Failed to push XML to phone {$phone_ip}"); return 0; } gs_log(GS_LOG_DEBUG, "Aastra: Pushed {$bytes_written} bytes to phone {$phone_ip}"); return $bytes_written; }
/** * @return string * @param string $string */ public static function parse($string) { $toParse = mb_subStr($string, 2, -2, 'UTF-8'); $toParse = trim($toParse); $toParse = preg_replace('/^\\s*\\*[^@]/m', '', $toParse); $parts = preg_split('/(@(?:description|param))\\s*/', $toParse, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $count = count($parts); $result = array(); for ($i = 0; $i < $count; ++$i) { $tag = strToLower(subStr($parts[$i], 1)); if ($i + 1 >= $count) { continue; } if ('@' != $parts[$i + 1][0]) { $function = 'parse' . ucFirst($tag); $item = self::$function($parts[$i + 1]); $item['name'] = $tag; $result[] = $item; ++$i; } } return $result; }
function _po_to_php($pofile) { $lines = file($pofile); if (!is_array($lines)) { return false; } $trans = array(); $msgid = null; $msgstr = ''; $context = 'msgstr'; foreach ($lines as $line) { $line = trim($line); if ($line == '' || subStr($line, 0, 1) === '#') { continue; } if (preg_match('/^msgid\\s*"(.*)"/iS', $line, $m)) { if ($msgid !== null) { _po_to_php_store_msg($trans, $msgid, $msgstr); } $context = 'msgid'; $msgid = $m[1]; } elseif (preg_match('/^msgstr\\s*"(.*)"/iS', $line, $m)) { $context = 'msgstr'; $msgstr = $m[1]; } else { if ($context === 'msgstr') { $msgstr .= trim($line, '"'); } else { $msgid .= trim($line, '"'); } } } if ($msgid !== null) { _po_to_php_store_msg($trans, $msgid, $msgstr); } return $trans; }
\'iax\', \'gw_tmp_' . rand(100000, 999999) . '\', \'\', 0, \'' . $DB->escape($default_dialstrs[$gw_type]) . '\', \'\', NULL, \'\', \'\', 0 )'); $gwid = (int) $DB->getLastInsertId(); } $iax_friend_name = strToLower(@$_REQUEST['gw-title']); $iax_friend_name = preg_replace('/[^a-z0-9]/', '', $iax_friend_name); $iax_friend_name = subStr('gw_' . $gwid . '_' . $iax_friend_name, 0, 20); $host = preg_replace('/[^a-zA-Z0-9\\-_.]/', '', @$_REQUEST['gw-host']); $query = 'UPDATE `gates` SET `grp_id` = ' . ((int) @$_REQUEST['gw-grp_id'] > 0 ? (int) @$_REQUEST['gw-grp_id'] : 'NULL') . ', `name` = \'' . $DB->escape($iax_friend_name) . '\', `title` = \'' . $DB->escape(trim(@$_REQUEST['gw-title'])) . '\', `allow_out` = ' . (@$_REQUEST['gw-allow_out'] ? 1 : 0) . ', `dialstr` = \'' . $DB->escape(trim(@$_REQUEST['gw-dialstr'])) . '\', `host` = \'' . $DB->escape($host) . '\', `proxy` = NULL, `user` = \'' . $DB->escape(preg_replace('/[^a-zA-Z0-9\\-_.@]/', '', @$_REQUEST['gw-user'])) . '\', `pwd` = \'' . $DB->escape(preg_replace('/[^a-zA-Z0-9\\-_.#*]/', '', @$_REQUEST['gw-pwd'])) . '\', `register` = ' . (@$_REQUEST['gw-register'] ? 1 : 0) . ' WHERE `id`=' . (int) $gwid; //echo "<pre>$query</pre>\n"; $DB->execute($query);
public function test_simple() { global $DB, $USER; core_php_time_limit::raise(); $this->resetAfterTest(); $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); $teacher = mod_ratingallocate_generator::create_user_and_enrol($this, $course, true); $this->setUser($teacher); // There should not be any module for that course first $this->assertFalse($DB->record_exists(this_db\ratingallocate::TABLE, array(this_db\ratingallocate::COURSE => $course->id))); //set default data for category $data = mod_ratingallocate_generator::get_default_values(); $data['course'] = $course; foreach ($data as $name => $value) { if (subStr($name, strlen($name) - 7, 7) === 'maxsize') { $data[$name] = 2; } if (subStr($name, strlen($name) - 6, 6) === 'active') { $data[$name] = true; } } // create activity $mod = $this->getDataGenerator()->create_module(ratingallocate_MOD_NAME, $data); $this->assertEquals(2, $DB->count_records(this_db\ratingallocate_choices::TABLE), array(this_db\ratingallocate_choices::ID => $mod->id)); $student_1 = mod_ratingallocate_generator::create_user_and_enrol($this, $course); $student_2 = mod_ratingallocate_generator::create_user_and_enrol($this, $course); $student_3 = mod_ratingallocate_generator::create_user_and_enrol($this, $course); $student_4 = mod_ratingallocate_generator::create_user_and_enrol($this, $course); $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $teacher); $choices = $ratingallocate->get_rateable_choices(); $choice1 = reset($choices); $choice2 = end($choices); //Create preferences $prefers_non = array(); foreach ($choices as $choice) { $prefers_non[$choice->{this_db\ratingallocate_choices::ID}] = array(this_db\ratingallocate_ratings::CHOICEID => $choice->{this_db\ratingallocate_choices::ID}, this_db\ratingallocate_ratings::RATING => 0); } $prefers_first = json_decode(json_encode($prefers_non), true); $prefers_first[$choice1->{this_db\ratingallocate_choices::ID}][this_db\ratingallocate_ratings::RATING] = true; $prefers_second = json_decode(json_encode($prefers_non), true); $prefers_second[$choice2->{this_db\ratingallocate_choices::ID}][this_db\ratingallocate_ratings::RATING] = true; //assign preferences mod_ratingallocate_generator::save_rating_for_user($this, $mod, $student_1, $prefers_first); mod_ratingallocate_generator::save_rating_for_user($this, $mod, $student_2, $prefers_first); mod_ratingallocate_generator::save_rating_for_user($this, $mod, $student_3, $prefers_second); mod_ratingallocate_generator::save_rating_for_user($this, $mod, $student_4, $prefers_second); // allocate choices $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $teacher); $time_needed = $ratingallocate->distrubute_choices(); $this->assertGreaterThan(0, $time_needed); $this->assertLessThan(0.1, $time_needed, 'Allocation is very slow'); $allocation_count = $ratingallocate->get_choices_with_allocationcount(); $this->assertCount(2, $allocation_count); //Test allocations $num_allocations = $DB->count_records(this_db\ratingallocate_allocations::TABLE); $this->assertEquals(4, $num_allocations, 'There should be only 4 allocations, since there are only 4 choices.'); $allocations = $DB->get_records(this_db\ratingallocate_allocations::TABLE, array(this_db\ratingallocate_allocations::RATINGALLOCATEID => $mod->{this_db\ratingallocate::ID}), ''); // '' /*sort*/, /*fields*/ this_db\ratingallocate_allocations::USERID . ',' . this_db\ratingallocate_allocations::CHOICEID ); $map_user_id = function ($elem) { return $elem->{this_db\ratingallocate_allocations::USERID}; }; $alloc1 = self::filter_allocations_by_choice($allocations, $choice1->{this_db\ratingallocate_choices::ID}); $alloc2 = self::filter_allocations_by_choice($allocations, $choice2->{this_db\ratingallocate_choices::ID}); //Assert, that student 1 was allocated to choice 1 $this->assertContains($student_1->id, array_map($map_user_id, $alloc1)); //Assert, that student 2 was allocated to choice 1 $this->assertContains($student_2->id, array_map($map_user_id, $alloc1)); //Assert, that student 3 was allocated to choice 2 $this->assertContains($student_3->id, array_map($map_user_id, $alloc2)); //Assert, that student 4 was allocated to choice 2 $this->assertContains($student_4->id, array_map($map_user_id, $alloc2)); }
<td class="transp xs gray"> </td> </tr> </thead> <tbody> <tr> <th><?php echo __('Nebenstelle'); ?> :</th> <td> <?php if ($r['hp_route_prefix'] != '' && subStr($r['ext'], 0, strLen($r['hp_route_prefix'])) === $r['hp_route_prefix']) { echo '<span style="color:#888;">', subStr($r['ext'], 0, strLen($r['hp_route_prefix'])), '</span>'; echo subStr($r['ext'], strLen($r['hp_route_prefix'])); } else { echo $r['ext']; } ?> </td> <td class="transp xs gray"> ← <?php echo htmlEnt(__("der SIP-Benutzername")); ?> </td> </tr> <tr> <th><?php echo __('Nachname'); ?>