Example #1
0
 public function get($index, $default = null)
 {
     $path = $this->getPath($index);
     $value = $this->root->get($path, $default);
     if ($value instanceof Leaf) {
         return $value->getValue();
     }
     return $default;
 }
Example #2
0
 function get_from_scad_txt($s)
 {
     //разделяем документ на строки и удаляем последнюю
     $mas = explode('/', $s);
     array_splice($mas, -1, 1);
     //перебор строк
     foreach ($mas as $value) {
         $node = new Node();
         $node->get($value);
         //запись в базу данных
         mysql_query("INSERT INTO " . nodes . " SET\n                      removed = '{$node->removed}',\n                      x = '{$node->x}',\n                      y = '{$node->y}',\n                      z = '{$node->z}'");
     }
 }
Example #3
0
File: DataSet.php Project: fieg/knn
 /**
  * Calculates distances
  *
  * @param Node   $node
  * @param Node[] $neighbors
  */
 protected function calculateDistances(Node $node, array $neighbors)
 {
     $this->calculateRanges();
     foreach ($neighbors as $neighbor) {
         $deltas = array();
         foreach ($this->schema->getFields() as $field) {
             list($min, $max) = $this->ranges[$field];
             $range = $max - $min;
             $delta = $neighbor->get($field) - $node->get($field);
             $delta = $delta / $range;
             $deltas[$field] = $delta;
         }
         $total = 0;
         foreach ($deltas as $delta) {
             $total += $delta * $delta;
         }
         $neighbor->setDistance(sqrt($total));
     }
 }
Example #4
0
File: post.php Project: kenjs/Goteo
 public static function getList($filters = array(), $published = true)
 {
     $values = array(':lang' => \LANG);
     $list = array();
     $sql = "\n                SELECT\n                    post.id as id,\n                    post.blog as blog,\n                    IFNULL(post_lang.title, post.title) as title,\n                    IFNULL(post_lang.text, post.text) as `text`,\n                    IFNULL(post_lang.legend, post.legend) as `legend`,\n                    post.image as `image`,\n                    post.media as `media`,\n                    DATE_FORMAT(post.date, '%d-%m-%Y') as fecha,\n                    post.publish as publish,\n                    post.home as home,\n                    post.footer as footer,\n                    post.author as author,\n                    blog.type as owner_type,\n                    blog.owner as owner_id\n                FROM    post\n                INNER JOIN blog\n                    ON  blog.id = post.blog\n                LEFT JOIN post_lang\n                    ON  post_lang.id = post.id\n                    AND post_lang.lang = :lang\n                ";
     if (in_array($filters['show'], array('all', 'home', 'footer'))) {
         $sql .= " WHERE blog.id IS NOT NULL\n                ";
     } elseif ($filters['show'] == 'updates') {
         $sql .= " WHERE blog.type = 'project'\n                ";
     } else {
         $sql .= " WHERE blog.type = 'node'\n                ";
     }
     if (!empty($filters['blog'])) {
         $sql .= " AND post.blog = :blog\n                ";
         $values[':blog'] = $filters['blog'];
     }
     if (!empty($filters['tag'])) {
         $sql .= " AND post.id IN (SELECT post FROM post_tag WHERE tag = :tag)\n                ";
         $values[':tag'] = $filters['tag'];
     }
     if (!empty($filters['author'])) {
         $sql .= " AND post.author = :author\n                ";
         $values[':author'] = $filters['author'];
     }
     // solo las publicadas
     if ($published || $filters['show'] == 'published') {
         $sql .= " AND post.publish = 1\n                ";
         if (empty($filters['blog'])) {
             $sql .= " AND blog.owner IN (SELECT id FROM node WHERE active = 1)\n                    AND blog.owner != 'testnode'\n                ";
         }
     }
     // solo las del propio blog
     if ($filters['show'] == 'owned') {
         $sql .= " AND blog.owner = :node\n                ";
         $values[':node'] = $filters['node'];
     }
     // solo las de la portada
     if ($filters['show'] == 'home') {
         if ($filters['node'] == \GOTEO_NODE) {
             $sql .= " AND post.home = 1\n                    ";
         } else {
             $sql .= " AND post.id IN (SELECT post FROM post_node WHERE node = :node)\n                    ";
             $values[':node'] = $filters['node'];
         }
     }
     if ($filters['show'] == 'footer') {
         if ($filters['node'] == \GOTEO_NODE) {
             $sql .= " AND post.footer = 1\n                    ";
         }
     }
     $sql .= "\n                ORDER BY post.date DESC, post.id DESC\n                ";
     $query = static::query($sql, $values);
     foreach ($query->fetchAll(\PDO::FETCH_CLASS, __CLASS__) as $post) {
         // galeria
         $post->gallery = Image::getAll($post->id, 'post');
         $post->image = $post->gallery[0];
         // video
         if (isset($post->media)) {
             $post->media = new Media($post->media);
         }
         $post->num_comments = Post\Comment::getCount($post->id);
         // datos del autor del  post
         switch ($post->owner_type) {
             case 'project':
                 $proj_blog = Project::getMini($post->owner_id);
                 $post->author = $proj_blog->owner;
                 $post->user = $proj_blog->user;
                 $post->owner_name = $proj_blog->name;
                 break;
             case 'node':
                 $post->user = User::getMini($post->author);
                 $node_blog = Node::get($post->owner_id);
                 $post->owner_name = $node_blog->name;
                 break;
         }
         $list[$post->id] = $post;
     }
     return $list;
 }
Example #5
0
 /**
  * @test
  */
 public function nodePropertiesAreHandledCaseInsensitively()
 {
     $node = new Node(array('id' => 1, 'foo' => 'Foo', 'BAR' => 'Bar'));
     $this->assertSame('Foo', $node->foo);
     $this->assertSame('Foo', $node->get('foo'));
     $this->assertSame('Foo', $node->getFoo());
     $this->assertSame('Bar', $node->bar);
     $this->assertSame('Bar', $node->get('bar'));
     $this->assertSame('Bar', $node->getBar());
 }
Example #6
0
 /**
  * Generated from @assert ('37.5 0 0.3') ==  array (37.5,0,0.3).
  */
 public function testGet4()
 {
     $this->assertEquals(array(37.5, 0, 0.3), $this->object->get('37.5 0 0.3'));
 }