function index() { $url = $this->url; $webpage = $this->webpage->create($url); $tutor = $webpage->get_tutor(); $annotation = new Annotation(1017); $user = $annotation->get_user(); $unread_count = $user->get_unread_notification_count(); $this->unit->run($unread_count, 'is_int', '先看一下user的未讀通知有幾封'); $tutor->setup_recommend($annotation); $recommend = $annotation->get_recommend(); $this->unit->run($recommend->get_id(), 'is_int', '有取得建議'); $recommend_annotation = $recommend->get_recommend_by(); $this->unit->run($recommend_annotation, NULL, '沒有推薦標註'); $tips = $recommend->get_tips_text_array(); $this->unit->run_false(count($tips), 0, '有建議'); //------------------------------------------------ $recommend_annotation = new Annotation(783); $recommend_annotation->set_score(0, 3); $recommend_annotation->update(); $scope = new Annotation_scope(129); $recommend_scope = new Annotation_scope_collection(); $recommend_scope->add_scope($scope); $annotation->set_recommend_scopes($recommend_scope); $tutor->setup_recommend($annotation); $recommend->reload(); $recommend_annotation = $recommend->get_recommend_by(); $this->unit->run($recommend_annotation->get_id(), 783, '有找到推薦標註'); $this->unit->run($user->get_unread_notification_count(TRUE), $unread_count + 2, '因為新增了兩次推薦,所以應該有兩封通知?'); // $this->unit->run($test_result // , $expected_result // , $test_name); //context_complete(); unit_test_report($this, __METHOD__); }
/** * @test */ public function throwsReflectionExceptionForMethodCallsWithoutGetOrIsOnSpecialValue() { expect(function () { $annotation = new Annotation('Example', 'someFunction()', ['__value' => 'true']); $annotation->invalid(); })->throws(\ReflectionException::class)->withMessage('The value with name "invalid" for annotation @Example at someFunction() does not exist'); }
/** * Generates the actual interfaces */ public function generate() { $interfacesData = json_decode($this->json, true); foreach ($interfacesData as $interface) { $filename = $interface['name'] . '.java'; $interfaceObject = new JAVAInterfaceObject(); $interfaceObject->setName($interface['name']); foreach ($interface['methods'] as $method) { $methodObject = new JAVAMethod(); $methodObject->setName($method['name']); $methodObject->setReturnValue($method['returnType']); $methodObject->setScope($method['scope']); $methodObject->setComment($method['comment']); foreach ($method['parameters'] as $parameter) { $parameterObject = new Parameter(); $parameterObject->setName($parameter['name']); $parameterObject->setType($parameter['type']); $methodObject->addParameter($parameterObject); } foreach ($method['annotations'] as $annotation) { $annotationObject = new Annotation(); $annotationObject->setName($annotation['name']); $annotationObject->setValue($annotation['value']); $annotationObject->setInterpreter('@'); $methodObject->addAnnotation($annotationObject); } $interfaceObject->addMethod($methodObject); } file_put_contents($this->folder . DIRECTORY_SEPARATOR . $filename, $interfaceObject->toString()); } }
public function parse($text) { $ret = new Collection(); if (preg_match_all('/@([^@\\n\\r\\t]*)/', $text, $globalMatches) > 0) { foreach ($globalMatches[1] as $annotationText) { preg_match('/([a-zA-Z0-9]+)/', $annotationText, $localMatches); if (in_array($localMatches[1], self::$ignoredAnnotations)) { continue; } $annotation = new Annotation($localMatches[1]); $optsStart = strpos($annotationText, '('); if ($optsStart !== false) { $optsEnd = strrpos($annotationText, ')'); $optsLength = $optsEnd - $optsStart - 1; $opts = trim(substr($annotationText, $optsStart + 1, $optsLength)); foreach ($this->_parseOptions($opts) as $key => $values) { foreach ($values as $value) { $annotation->addOption($key, $value); } } } $ret->add($annotation); } } return $ret; }
protected function get_feature(Annotation $annotation) { //if ($annotation->get_id() == 2363) // test_msg('Language_variable_consensus', array($annotation->get_id(), $annotation->get_consensus_count())); $feature = $annotation->get_consensus_count(); return $feature; }
/** * @param Annotation $annotation */ protected function annotationDeleted(Annotation $annotation) { $children = $annotation->getChildren(); foreach ($children as $child) { $child->setStatus($annotation->getStatus()); $child->save(); } }
function annotations_from_hits($uri, $page, $hits) { $EXTEND_BY = 3; $annotations = array(); foreach ($hits as $hit) { print_r($hit); // what word does hit start in? $starting_word = $page->characters[$hit->start]; // offset with respect to the starting word $starting_position = $hit->start - $page->word_start[$starting_word] - 1; // what word does hit end in? $ending_word = $page->characters[$hit->end]; // offset with respect to the ending word $ending_position = $hit->end - $page->word_start[$ending_word]; echo $starting_word . ' ' . $starting_position . "\n"; echo $ending_word . ' ' . $ending_position . "\n"; $prefix_words = array(); if ($starting_word > 0) { $prefix_pos = max(0, $starting_word - $EXTEND_BY); $prefix_count = $starting_word - $prefix_pos; $prefix_words = array_slice($page->words, $prefix_pos, $prefix_count); $prefix = substr($page->words[$starting_word], 0, $starting_position); if ($prefix != '') { $prefix_words[] = $prefix; } } $num_words = count($page->words); $suffix_words = array(); if ($ending_word < $num_words - 1) { $suffix_pos = min($ending_word + $EXTEND_BY, $num_words); $suffix_count = $suffix_pos - $ending_word; $suffix_words = array_slice($page->words, $ending_word + 1, $suffix_count); $suffix = substr($page->words[$ending_word], $ending_position); if ($suffix != '') { array_unshift($suffix_words, $suffix); } } $a = new Annotation($uri); $a->add_permissions("acct:rdmpage@hypothes.is"); $a->add_text_quote(str_replace(" ", "\n", $hit->mid), join("\n", $prefix_words), join("\n", $suffix_words)); // Not sure that we need this, and doesn't seme to be working /* $a->add_range( "//div[@id='" . ($starting_word + 1) . "']", $starting_position, "//div[@id='" . ($ending_word + 1) . "']", $ending_position ); */ $a->add_tag($hit->type); if (isset($hit->text)) { $a->set_text($hit->text); } $annotations[] = $a; } return $annotations; }
public static function process(Annotation $a) { $classes = $a->getValues(); foreach ($classes as $class) { $classFile = "../{$class}.class.php"; if (file_exists($classFile)) { include_once $classFile; } else { throw new Exception("{$classFile} DO NOT EXIST"); } } }
function punish_comments($hours = 6) { global $globals, $db; $log = new Annotation('punish-comment'); if ($log->read() && $log->time > time() - 3600 * $hours) { echo "Comments already verified at: " . get_date_time($log->time) . "\n"; return false; } if ($globals['min_karma_for_comments'] > 0) { $min_karma = $globals['min_karma_for_comments']; } else { $min_karma = 4.5; } $votes_from = time() - $hours * 3600; // 'date_sub(now(), interval 6 hour)'; $comments_from = time() - 2 * $hours * 3600; //'date_sub(now(), interval 12 hour)'; echo "Starting karma_comments...\n"; $users = "SELECT SQL_NO_CACHE distinct comment_user_id as user_id from comments, users where comment_date > from_unixtime({$comments_from}) and comment_karma < -50 and comment_user_id = user_id and user_level != 'disabled' and user_karma >= {$min_karma}"; $result = $db->get_results($users); $log->store(); if (!$result) { return; } foreach ($result as $dbuser) { $user = new User(); $user->id = $dbuser->user_id; $user->read(); printf("%07d %s\n", $user->id, $user->username); $punish = 0; $comment_votes_count = (int) $db->get_var("SELECT SQL_NO_CACHE count(*) from votes, comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from}) and vote_type='comments' and vote_link_id = comment_id and vote_date > from_unixtime({$votes_from}) and vote_user_id != {$user->id}"); if ($comment_votes_count > 5) { $votes_karma = (int) $db->get_var("SELECT SQL_NO_CACHE sum(vote_value) from votes, comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from}) and vote_type='comments' and vote_link_id = comment_id and vote_date > from_unixtime({$votes_from}) and vote_user_id != {$user->id}"); if ($votes_karma < 50) { $distinct_votes_count = (int) $db->get_var("SELECT SQL_NO_CACHE count(distinct comment_id) from votes, comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from}) and vote_type='comments' and vote_link_id = comment_id and vote_date > from_unixtime({$votes_from}) and vote_user_id != {$user->id}"); $comments_count = (int) $db->get_var("SELECT SQL_NO_CACHE count(*) from comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from})"); $comment_coeff = min($comments_count / 10, 1) * min($distinct_votes_count / ($comments_count * 0.75), 1); $punish = max(-2, round($votes_karma * $comment_coeff * 1 / 1000, 2)); } } if ($punish < -0.1) { echo "comments: {$comments_count} votes distinct: {$distinct_votes_count} karma: {$votes_karma} coef: {$comment_coeff} -> {$punish}\n"; $user->karma += $punish; //$user->store(); $annotation = new Annotation("karma-{$user->id}"); //$annotation->append(_('Penalización por comentarios').": $punish, nuevo karma: $user->karma\n"); echo _('Penalización por comentarios') . ": {$punish}, nuevo karma: {$user->karma}\n"; $log->append(_('Penalización') . " {$user->username}: {$punish}, nuevo karma: {$user->karma}\n"); } $db->barrier(); } }
function do_load() { global $db, $current_user; $annotation = new Annotation('ec2-autoscaler'); if (!$annotation->read()) { return _('no hay estadísticas disponibles'); } $group = unserialize($annotation->text); $str = "web instances: $group->instances, "; $str .= "cpu average load: ".round($group->load, 2) . "%, "; $str .= "cpu max average ($group->measures periods): ".round($group->load_max, 2)."%, "; $str .= "stored at: ". get_date_time($annotation->time); return $str; }
function do_load() { global $db, $current_user; $annotation = new Annotation('ec2_watch'); if (!$annotation->read()) { return _('no hay estadísticas disponibles'); } $group = json_decode($annotation->text); $str = "web instances: {$group->instances}, "; $str .= "cpu average load: " . round($group->avg_load, 2) . "%, "; $str .= "last action: {$group->action} "; $str .= "last change: " . get_date_time($group->changed_ts) . " "; $str .= "stored at: " . get_date_time($annotation->time); return $str; }
/** * This functions builds an array (key\value) with entity data, to later insert on the db * * @param Entity $entity * * @return array */ private function getKeyValuePropertiesByEntity(Entity $entity) { $properties = array_keys($entity->getProperties()); $keyValueProperties = array(); foreach ($properties as $property) { $method = $this->getterMethodToGetPropertyValue($property); $propertyValue = $entity->{$method}(); if (is_null($propertyValue)) { continue; } $annotations = $this->annotation->getAnnotationsByProperty($property, $entity); $propertyKey = $this->getValueOfAnnotation($annotations, self::PROPERTY_ANNOTATION); $keyValueProperties[$propertyKey] = $propertyValue; } return $keyValueProperties; }
/** * Discovers all the annotations of a given class file * * @param string $class a class file * @return array */ public static function discover($class) { try { if (!file_exists($class)) { throw new Exception($class . " does not exist"); } $text = file($class, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $annotations = array(); $currentAnnotations = array(); foreach ($text as $key => $line) { if (strpos($line, "* @annotation") !== false) { $currentAnnotations[] = trim(str_replace("* @annotation", "", $line)); } else { $functionName = ""; if (count($currentAnnotations) > 0 && Annotation::discoverFunctionName($line, $functionName)) { $annotations[$functionName] = $currentAnnotations; $currentAnnotations = array(); } unset($text[$key]); } } return $annotations; } catch (Exception $e) { Functions::dump($e->getMessage()); return NULL; } }
public static function calculate_type($reflection) { $annotations = Annotation::parse($reflection); if (isset($annotations['type'])) { return $annotations['type']; } else { $defaults = $reflection->getDeclaringClass()->getDefaultProperties(); $default_value = $defaults[$reflection->getName()]; if (is_null($default_value)) { return 'null'; } if (is_string($default_value)) { return 'string'; } else { if (is_integer($default_value)) { return 'integer'; } else { if (is_float($default_value)) { return 'float'; } else { if (is_bool($default_value)) { return 'boolean'; } else { if (is_array($default_value)) { return 'array'; } } } } } } }
/** * Ler um model e gera um SQL referente * @param Model $model instância do model para gerar o SQL * @return string retorna o SQL do model */ protected function getTable(Model $model) { $annotation = Annotation::get(get_class($model)); $class = $annotation->getClass(); if ($class->Entity) { $table = new stdClass(); $table->Name = $class->Entity->Name ? $class->Entity->Name : get_class($model); $table->Columns = array(); $table->Keys = array(); foreach ($model as $field => $value) { $property = $annotation->getProperty($field); if ($this->isField($property)) { $column = new stdClass(); $column->Name = $this->getField($field, $property); if (!$column->Name) { $column->Name = $field; } $column->Type = $this->getType($property); $column->Nullable = $this->getNullable($property); $table->Columns[] = $column; if ($this->isKey($property)) { $table->Keys[] = $this->getKey($field, $property); } } } return $this->getSql($table); } }
public function checkConstraints($target) { parent::checkConstraints($target); if (is_null($this->name)) { throw new \Exception("L'attribut name est obligatoire pour une annotation de type JoinTable"); } }
static function insert($type, $ref_id, $user_id = 0, $annotation = false) { global $db, $globals; $ip = $globals['user_ip']; $ip_int = $globals['user_ip_int']; $sub = SitesMgr::my_id(); // Get this subsite's parent id (or itself if it's a parent) $res = $db->query("insert into logs (log_sub, log_date, log_type, log_ref_id, log_user_id, log_ip_int, log_ip) values ({$sub}, now(), '{$type}', {$ref_id}, {$user_id}, {$ip_int}, '{$ip}')"); if ($res && $annotation) { $a = new Annotation('log-' . $db->insert_id); $a->text = $annotation; $a->store(time() + 86400 * 30); // Valid for one month } return $res; }
public function save() { $annotation = new Annotation($this); $table = $annotation->getClassAnnotation('table'); $reflector = new ReflectionClass($this); $properties = $reflector->getProperties(); $data = array(); foreach ($properties as $property) { $isPersistent = $annotation->getPropertyAnnotation($property->getName(), 'persistent'); $field_name = $annotation->getPropertyAnnotation($property->getName(), 'field'); var_dump($field_name); if (true === $isPersistent) { $data[$field_name] = $property->getValue(); } } var_dump($data); }
/** * Initialize the annotation. */ public function initAnnotation($properties) { $this->_map($properties, array('format')); parent::initAnnotation($properties); if (!isset($this->format)) { throw new AnnotationException('FormatAnnotation requires a format property'); } }
/** * Resolve if callable is closure or function * * @param $callable * @return Invokable */ public static function ofFunction($callable) { if ($callable instanceof \Closure or is_string($callable) and function_exists($callable)) { $annotations = Annotation::ofFunction($callable); $reflector = new \ReflectionFunction($callable); return new Invokable($callable, Invokable::CLOSURE, $annotations, $reflector); } }
/** * Execute the console command. * * @return mixed */ public function fire() { $doc_id = $this->argument('doc_id'); $filename = $this->argument('filename'); $doc = Doc::where('id', $doc_id)->first(); $this->info("Exporting activity for " . $doc->title); $annotations = Annotation::where('doc_id', $this->argument('doc_id'))->with('user')->with('comments')->get(); $comments = Comment::where('doc_id', $this->argument('doc_id'))->with('user')->get(); $headers = array("Created At", "Link", "Display Name", "Full Name", "Email", "Type", "Quote", "Text"); $toExport = array(); foreach ($annotations as $annotation) { $annotationArray = array(); $annotationArray['date'] = $annotation->created_at; $annotationArray['link'] = URL::to('/') . $annotation->uri . '#annotation_' . $annotation->id; $annotationArray['display_name'] = $annotation->user->fname . " " . substr($annotation->user->lname, 0, 1); $annotationArray['full_name'] = $annotation->user->fname . " " . $annotation->user->lname; $annotationArray['email'] = $annotation->user->email; $annotationArray['type'] = 'Annotation'; $annotationArray['quote'] = $annotation->quote; $annotationArray['text'] = $annotation->text; array_push($toExport, $annotationArray); foreach ($annotation->comments as $comment) { $user = User::find($comment->user_id); $commentArray = array(); $commentArray['date'] = $comment->created_at; $commentArray['link'] = ""; $commentArray['display_name'] = $user->fname . " " . substr($user->lname, 0, 1); $commentArray['full_name'] = $user->fname . " " . $user->lname; $commentArray['email'] = $user->email; $commentArray['type'] = "Annotation Comment"; $commentArray['quote'] = ""; $commentArray['text'] = $comment->text; array_push($toExport, $commentArray); } } foreach ($comments as $comment) { $commentArray = array(); $commentArray['date'] = $comment->created_at; $commentArray['link'] = ""; $commentArray['display_name'] = $comment->user->fname . " " . substr($comment->user->lname, 0, 1); $commentArray['full_name'] = $comment->user->fname . " " . $comment->user->lname; $commentArray['email'] = $comment->user->email; $commentArray['type'] = $comment->parent_id === null ? "Comment" : "Sub-comment"; $commentArray['quote'] = ""; $commentArray['text'] = $comment->text; array_push($toExport, $commentArray); } $this->info('Saving export to ' . $filename); $fp = fopen($filename, 'w'); fputcsv($fp, $headers); foreach ($toExport as $row) { fputcsv($fp, $row); } fclose($fp); $this->info('Done.'); }
public function __construct($value) { if (preg_match('/^\'?([a-z]+)\'? (?:{([a-z]+)} )?(.*)/', $value, $match)) { $this->option = $match[1]; $this->datatype = !empty($match[2]) ? $match[2] : 'mixed'; parent::__construct($match[3]); } else { parent::__construct("'" . $value . "'"); } }
public function getAnnotations($docComment) { $result = new AnnotationCollection(); if (preg_match_all('/@(.*?)\\n/is', $docComment, $matches)) { array_shift($matches); foreach ($matches[0] as $match) { $parts = explode(' ', $match); $x = new Annotation(); $x->setName($parts[0]); if (count($parts) > 1) { for ($i = 1; $i != count($parts); $i++) { $x->addValue($parts[$i]); } } $result->add($x); } } return $result; }
/** * Constructor * * @param Annotation $annotation * The Loomp annotation that has to be used as base. * @param integer $begin * The begin of the annotated area within the referenced text. * @param integer $end * The end of the annotated area within the referenced text. * @param string $about[optional] * The URI to the described resource. * @param string $seeAlso[optional] * The URI to an resource that contains more information about this one. * @return ARS_LocatedAnnotation */ public function __construct($annotation, $begin, $end, $about = null, $seeAlso = null) { parent::__construct($annotation->getUri(), $annotation->getLabel(), $annotation->getDescription(), $annotation->getType(), $annotation->getAnnDomain(), $annotation->getAnnRange()); $this->begin = $begin; $this->end = $end; $this->about = $about; $this->seeAlso = $seeAlso; return $this; }
public function outputDescription() { $this->description = ''; if (!empty($this->annotations)) { $this->description .= '{' . self::$newline; foreach ($this->annotations as $annotation) { $this->description .= self::$indent . $annotation->output() . self::$newline; } $this->description .= '}'; } return parent::outputDescription(); }
/** * Default constructor * * @param string $fileLocation full path location of file * @param string $method the current method whose annotations should be used * @param string $caller determine if the caller is the built in beforeAction or afterAction */ public function __construct($fileLocation, $method, $caller = NULL) { $this->callerAnnotations = array(); $this->dependenciesLocations = array(); $annotations = Annotation::discover($fileLocation); if (isset($annotations[Functions::escapeCamel($method)])) { $this->callerAnnotations = $annotations[Functions::escapeCamel($method)]; } if (!isset($annotations[$method]) && ($caller == "beforeAction" || $caller == "afterAction")) { $this->callerAnnotations = $annotations[$caller]; } $this->dispatchAnnotations(); }
static function insert($type, $ref_id, $user_id = 0, $annotation = false) { global $db, $globals; if ($globals['behind_load_balancer'] && $globals['form_user_ip']) { // If the page stored the "real IP" in a form $ip = $globals['form_user_ip']; $ip_int = inet_ptod($globals['form_user_ip']); } else { $ip = $globals['user_ip']; $ip_int = $globals['user_ip_int']; } $sub = SitesMgr::my_parent(); // Get this subsite's parent id (or itself if it's a parent) $res = $db->query("insert into logs (log_sub, log_date, log_type, log_ref_id, log_user_id, log_ip_int, log_ip) values ({$sub}, now(), '{$type}', {$ref_id}, {$user_id}, {$ip_int}, '{$ip}')"); if ($res && $annotation) { $a = new Annotation('log-' . $db->insert_id); $a->text = $annotation; $a->store(time() + 86400 * 30); // Valid for one month } return $res; }
protected function getIdentityProperty($entity) { $className = get_class($entity); $listAnnotations = Annotation::extractAnnotations($className); foreach ($listAnnotations[Annotation::PROPERTIES] as $property=>$propertiesAnnotations) { foreach ($propertiesAnnotations as $annotation) { if ($annotation[Annotation::BEHAVIOR] == Annotation::T_ID) { return $property; } } } throw new \core\exception\AnnotationException('Identity annotation @Id not found'); }
protected function _post_update() { parent::_post_update(); //假如是喜歡的話…… $canceled = $this->get_field('canceled'); if ($canceled === FALSE or $canceled == 'FALSE' or $canceled == 'f') { $annotation_id = intval($this->get_field('annotation_id')); $user_id = intval($this->get_field('user_id')); if ($annotation_id != 0 && $user_id != 0) { $this->_CI_load('library', 'kals_resource/Annotation', 'annotation'); $this->_CI_load('library', 'kals_actor/User', 'user'); $trigger_resource = new Annotation($annotation_id); $association_user = $trigger_resource->get_user(); $trigger_actor = new User($user_id); $this->_CI_load('library', 'kals_actor/Notification_liked', 'notification_liked'); $notification = $this->CI->notification_liked->create_notification($association_user, $trigger_resource, $trigger_actor); if (is_null($notification)) { handle_error($this->lang->line('notification.liked.create_notification.exception')); } } } //if ($canceled == FALSE OR $canceled == 'FALSE') }
public function getDescription() { $description = ''; $description .= '"' . self::implode('", "', $this->parameters) . '"'; if (!empty($this->optionalParameters)) { foreach ($this->optionalParameters as $k => $v) { if (is_array($v)) { $description .= ', ' . $k . '={"' . implode('", "', $v) . '"}'; } else { $description .= ', ' . $k . '="' . $v . '"'; } } } return parent::getDescription(); }