setTable( new ListingsWatchTable()); } /** * * create or update a row in the listings watch table * * @param array $data * * @return $this */ public function save($data) { $row = null; $data = $this->_prepareSaveData($data); if (array_key_exists('id', $data)) { $select = $this->_table->select() ->where("id = ?", $data['id']); unset($data['id']); $row = $this->_table->fetchRow($select); } if (count($row) > 0) { $this->_table->update($data, "id='{$row['id']}'"); } else { $data['created_at'] = new Expr('now()'); $this->_table->insert($data); } return $this; } /** * * delete data from the table * * @param int|array $listingIds the id of the listing(s) * @param int $userId the id of the user that is watching the listing * @param string $userToken user token cookie * * @return int returns the number of affected rows */ public function delete($listingIds, $userId, $userToken) { $adapter = $this->_table->getAdapter(); if (!is_array($listingIds)) { $listingIds = array($listingIds); } $where[] = $adapter->quoteInto('listing_id IN (?)', $listingIds); if ($userId !== null) { $where[] = 'user_token = "' . $userToken . '" OR user_id = "' . $userId . '"'; } else { $where[] = $adapter->quoteInto('user_token = ?', $userToken); } return $this->_table->delete($where); } }