Example #1
0
 public function insert(Category $category, Subcategory $subcategory, Brand $brand, Item $item)
 {
     //        $sql = "INSERT INTO item values (null, 'aalluu', 'asdfasd',true,true, '2015-10-10','asdfasf', 'asdfasd', 1, 1 ,1, 1)";
     $sql = "INSERT INTO item values (null, '" . $item->getTitle() . "','" . $item->getDetail() . "',true,false, '" . $item->getDate() . "', '" . $item->getLocation() . "','asfasf'," . $category->getId() . "," . $subcategory->getId() . ", 1 ," . $brand->getId() . ")";
     echo $sql;
     if ($this->conn->query($sql) === TRUE) {
         echo "Insert operation successful";
     } else {
         echo "Error inserting: ";
     }
 }
Example #2
0
    /**
     * @brief Save the feed and all its items into the database
     * @returns The id of the feed in the database table.
     */
    public function save(Item $item, $feedid)
    {
        $guid = $item->getGuid();
        $guid_hash = md5($guid);
        $status = $item->getStatus();
        $itemid = $this->findIdFromGuid($guid_hash, $guid, $feedid);
        if ($itemid == null) {
            $title = $item->getTitle();
            $body = $item->getBody();
            $author = $item->getAuthor();
            $stmt = \OCP\DB::prepare('
				INSERT INTO ' . self::tableName . '(url, title, body, author, guid, guid_hash, pub_date, feed_id, status)
				VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
				');
            if (empty($title)) {
                $l = \OC_L10N::get('news');
                $title = $l->t('no title');
            }
            if (empty($body)) {
                $l = \OC_L10N::get('news');
                $body = $l->t('no body');
            }
            $pub_date = Utils::unixtimeToDbtimestamp($item->getDate());
            $params = array($item->getUrl(), $title, $body, $author, $guid, $guid_hash, $pub_date, $feedid, $status);
            $stmt->execute($params);
            $itemid = \OCP\DB::insertid(self::tableName);
        } else {
            $this->update($item);
        }
        $item->setId($itemid);
        return $itemid;
    }