public function save(Feed $feed, $folderid) { $title = $feed->getTitle(); $url = $feed->getUrl(); $url_hash = md5($url); if (empty($title)) { $l = \OC_L10N::get('news'); $title = $l->t('no title'); } $favicon = $feed->getFavicon(); //FIXME: Detect when feed contains already a database id $feedid = $this->findIdFromUrl($url); if ($feedid === null) { $query = \OCP\DB::prepare("\n\t\t\t\tINSERT INTO " . self::tableName . "(url, url_hash, title, favicon_link, folder_id, user_id, added, lastmodified)\n\t\t\t\tVALUES (?, ?, ?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())\n\t\t\t\t"); $params = array($url, $url_hash, $title, $favicon, $folderid, $this->userid); $query->execute($params); $feedid = \OCP\DB::insertid(self::tableName); } else { //update the db. it needs to be done, since it might be the first save after a full fetch $stmt = \OCP\DB::prepare(' UPDATE ' . self::tableName . ' SET favicon_link = ? , lastmodified = UNIX_TIMESTAMP() , folder_id = ? WHERE id = ? '); $params = array($favicon, $folderid, $feedid); $stmt->execute($params); } $feed->setId($feedid); $itemMapper = new ItemMapper(); $items = $feed->getItems(); if ($items !== null) { foreach ($items as $item) { $itemMapper->save($item, $feedid); } } return $feedid; }
// New Item $app->get('/item/new', function ($request, $response, $args) { $this->logger->info("Creating new item"); $mapper = new ColorMapper($this->db); $colors = $mapper->getColors(); return $this->renderer->render($response, 'item/item.phtml', [$args, "colors" => $colors]); }); // New Item POST $app->post('/item/new', function ($request, $response) { $post_data = $request->getParsedBody(); $data = []; $data['Name'] = filter_var($post_data['name'], FILTER_SANITIZE_STRING); $data['Color'] = filter_var($post_data['color'], FILTER_SANITIZE_STRING); $item = new ItemEntity($data); $mapper = new ItemMapper($this->db); $mapper->save($item); $response = $response->withRedirect("/index.php/items"); return $response; }); //Edit Item GET $app->get('/item/{id}/edit', function ($request, $response, $args) { $id = (int) $args['id']; $mapper = new ItemMapper($this->db); $item = $mapper->getItemById($id); $this->logger->info("Edit Item " . $id); $color_mapper = new ColorMapper($this->db); $colors = $color_mapper->getColors(); return $this->renderer->render($response, 'item/edit_item.phtml', [$args, "item" => $item, "colors" => $colors]); }); // EDIT Item POST $app->post('/item/edit', function ($request, $response) {