Example #1
0
 /**
  * Saves a link into the database.
  * 
  * $param \WebLinks\Domain\Link $link The link to save
  */
 public function save(Link $link)
 {
     $linkData = array('link_title' => $link->getTitle(), 'link_url' => $link->getUrl(), 'user_id' => $link->getAuthor()->getId());
     if ($link->getId()) {
         // The link has already been saved : update it
         $this->getDb()->update('t_link', $linkData, array('link_id' => $link->getId()));
     } else {
         // The link has never been saved : insert it
         $this->getDb()->insert('t_link', $linkData);
         // Get the id of the newly created link and set it on the entity
         $id = $this->getDb()->lastInsertId();
         $link->setId($id);
     }
 }
Example #2
0
 /**
  * Converts an Link object into an associative array for JSON encoding
  * 
  * @param Link $link Link object
  * 
  * @return array Associative array whose fields are the link properties.
  */
 private function buildLinkArray(Link $link)
 {
     $data = array('id' => $link->getId(), 'title' => $link->getTitle(), 'url' => $link->getUrl(), 'author' => $link->getAuthor()->getUsername());
     return $data;
 }