コード例 #1
1
 /**
  * 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));
         }
     }
 }
コード例 #2
0
 /**
  * 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);
     }
 }
コード例 #3
0
 /**
  * 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);
     }
 }
コード例 #4
0
 /**
  * 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;
 }