Example #1
0
 public static function updateCategory(MapFolder $category, $items, $projection = null, $parentCategoryId = null)
 {
     $categoryId = $category->getId();
     $name = $category->getTitle();
     $description = $category->getSubtitle();
     $isStored = $category instanceof MapDBCategory && $category->isStored();
     if (!$isStored) {
         $sql = 'SELECT * FROM ' . self::CATEGORY_TABLE . ' WHERE category_id=?';
         $params = array($categoryId);
         $results = self::connection()->query($sql, $params);
         if ($results->fetch()) {
             $isStored = true;
         }
     }
     if (!$isStored) {
         if ($parentCategoryId === null) {
             $sql = 'INSERT INTO ' . self::CATEGORY_TABLE . ' (category_id, name, description) VALUES (?, ?, ?)';
             $params = array($categoryId, $name, $description);
         } else {
             $sql = 'INSERT INTO ' . self::CATEGORY_TABLE . ' (category_id, name, description, parent_category_id) VALUES (?, ?, ?, ?)';
             $params = array($categoryId, $name, $description, $parentCategoryId);
         }
     } else {
         if ($parentCategoryId === null) {
             $sql = 'UPDATE ' . self::CATEGORY_TABLE . '   SET name=?, description=? WHERE category_id=?';
             $params = array($name, $description, $categoryId);
         } else {
             $sql = 'UPDATE ' . self::CATEGORY_TABLE . '   SET name=?, description=?, parent_category_id=? WHERE category_id=?';
             $params = array($name, $description, $parentCategoryId, $categoryId);
         }
     }
     self::connection()->query($sql, $params);
     if ($projection === null || $projection instanceof MapProjector) {
         $projector = $projection;
     } else {
         $projector = new MapProjector();
         $projector->setSrcProj($projection);
     }
     foreach ($items as $item) {
         if ($item instanceof MapFolder) {
             self::updateCategory($item, $item->getListItems(), $projector, $categoryId);
         } elseif ($item instanceof Placemark) {
             self::updateFeature($item, $categoryId, $projector);
         }
     }
 }
Example #2
0
 protected function addFolder(MapFolder $folder)
 {
     $folder->setParent($this);
     $this->folders[] = $folder;
 }
    protected static function getCategoryNodesForItem(MapFolder $item) {
        $nodes = array();
        foreach ($item->getListItems() as $innerItem) {
            if ($innerItem instanceof MapFolder && $innerItem instanceof MapListElement) {
                $node = array(
                    'title' => $innerItem->getTitle(),
                    'id' => $innerItem->getCategory(),
                    //'subtitle' => $innerItem->getSubtitle(),
                    );

                $subcategories = self::getCategoryNodesForItem($innerItem);
                if ($subcategories) {
                    $node['subcategories'] = $subcategories;
                }

                $nodes[] = $node;
            }
        }
        return $nodes;
    }