/** * Saves the pool to the database. * * @param \MusicBox\Entity\Like $pool */ public function save($pool) { $poolData = array('address_id' => $pool->getAddress()->getId(), 'access_info' => $pool->getAccessInfo()); if ($pool->getId()) { $this->db->update('pools', $poolData, array('pool_id' => $pool->getId())); $newFile = $this->handleFileUpload($item); if ($newFile) { $poolData['image'] = $pool->getImage(); } } else { // The pool is new, note the creation timestamp. $poolData['created_at'] = time(); $this->db->insert('pools', $poolData); // Get the id of the newly created pool and set it on the entity. $id = $this->db->lastInsertId(); $pool->setId($id); // If a new image was uploaded, update the pool with the new // filename. $newFile = $this->handleFileUpload($pool); if ($newFile) { $newData = array('image' => $pool->getImage()); $this->db->update('pools', $newData, array('pool_id' => $id)); } } }
public function likeAction(Request $request, Application $app) { $artist = $request->attributes->get('artist'); $token = $app['security']->getToken(); $user = $token->getUser(); if (!$artist) { $app->abort(404, 'The requested artist was not found.'); } if ($user == 'anon.') { // Only logged-in users can comment. return; } // Don't allow the user to like the artist twice. $existingLike = $app['repository.like']->findByArtistAndUser($artist->getId(), $user->getId()); if (!$existingLike) { // Save the individual like record. $like = new Like(); $like->setArtist($artist); $like->setUser($user); $app['repository.like']->save($like); // Increase the counter on the artist. $numLikes = $artist->getLikes(); $numLikes++; $artist->setLikes($numLikes); $app['repository.artist']->save($artist); } return ''; }
/** * Saves the lesson to the database. * * @param \MusicBox\Entity\Like $lesson */ public function save($lesson) { $lessonData = array('user_id' => $lesson->getUser()->getId()); if ($lesson->getId()) { $this->db->update('lessons', $lessonData, array('lesson_id' => $lesson->getId())); } else { // The lesson is new, note the creation timestamp. $lessonData['created_at'] = time(); $this->db->insert('lessons', $lessonData); // Get the id of the newly created lesson and set it on the entity. $id = $this->db->lastInsertId(); $lesson->setId($id); } }
/** * Saves the group to the database. * * @param \MusicBox\Entity\Like $group */ public function save($group) { $groupData = array('artist_id' => $group->getArtist()->getId(), 'user_id' => $group->getUser()->getId()); if ($group->getId()) { $this->db->update('groups', $groupData, array('group_id' => $group->getId())); } else { // The group is new, note the creation timestamp. $groupData['created_at'] = time(); $this->db->insert('groups', $groupData); // Get the id of the newly created group and set it on the entity. $id = $this->db->lastInsertId(); $group->setId($id); } }
/** * Instantiates a like entity and sets its properties using db data. * * @param array $likeData * The array of db data. * * @return \MusicBox\Entity\Like */ protected function buildLike($likeData) { // Load the related artist and user. $artist = $this->artistRepository->find($likeData['artist_id']); $user = $this->userRepository->find($likeData['user_id']); $like = new Like(); $like->setId($likeData['like_id']); $like->setArtist($artist); $like->setUser($user); $createdAt = new \DateTime('@' . $likeData['created_at']); $like->setCreatedAt($createdAt); return $like; }
/** * Saves the address to the database. * * @param \MusicBox\Entity\Like $address */ public function save($address) { $addressData = array('user_id' => $address->getUserId(), 'street' => $address->getStreet(), 'street2' => $address->getStreet2(), 'city' => $address->getCity(), 'state' => $address->getState(), 'zip' => $address->getZip(), 'billing' => $address->getType()); if ($address->getId()) { try { $this->db->update('addresses', $addressData, array('address_id' => $address->getId())); } catch (\Exception $e) { return false; } } else { // The address is new, note the creation timestamp. try { $this->db->insert('addresses', $addressData); // Get the id of the newly created address and set it on the entity. $id = $this->db->lastInsertId(); $address->setAddressId($id); } catch (\Exception $e) { dump($e); exit; return false; } } }