コード例 #1
0
 public function saveAlbum($album, $menuId)
 {
     $this->db->begin();
     try {
         if (isset($album->name) && $album->name) {
             $nameId = $this->nameModel->setName($album->name, 'album', TRUE);
             if ($album->text == null) {
                 $album->text = '';
             }
             $textNameId = $this->nameModel->setName($album->text, 'album', FALSE);
             if (!isset($album->imageId)) {
                 $album->imageId = NULL;
             }
             if (!isset($album->year)) {
                 $album->year = date('Y');
             }
             if (isset($album->id) && $album->id) {
                 $this->db->query("UPDATE [album] SET name_id=%i,image_id=%i,[year]=%i,text_name_id=%i,link=%s,price=%i,[count]=%i WHERE id=%i", $nameId, $album->imageId, $album->year, $textNameId, $album->link, $album->price, $album->count, $album->id);
                 $id = $album->id;
             } else {
                 $insert = array('menu_id' => $menuId, 'name_id' => $nameId, 'text_name_id' => $textNameId, 'image_id' => $album->imageId, 'year' => $album->year, 'link' => $album->link, 'price' => $album->price, 'count' => $album->count);
                 $this->db->query("INSERT INTO [album] ", $insert);
                 $id = $this->db->getInsertId();
             }
         }
         foreach ($album->songs as $song) {
             if (!empty($song->name) || !empty($song->text) || !empty($song->fileId)) {
                 $nameId = $this->nameModel->setName($song->name, 'song', FALSE);
                 $textNameId = $this->nameModel->setName($song->text, 'song', FALSE);
                 $fileId = isset($song->fileId) ? $song->fileId : null;
                 $link = isset($song->link) ? $song->link : null;
                 if (isset($song->id) && $song->id) {
                     $this->db->query("UPDATE [song] SET name_id=%i, image_id=%i, text_name_id=%i,sort_key=%i,link=%s WHERE id=%i", $nameId, $fileId, $textNameId, $song->sortKey, $link, $song->id);
                 } else {
                     $insert = array('name_id' => $nameId, 'text_name_id' => $textNameId, 'image_id' => $fileId, 'album_id' => $id, 'link' => $album->link, 'sort_key' => $song->sortKey);
                     $this->db->query("INSERT INTO [song] ", $insert);
                 }
             } else {
                 if (empty($song->name) && !empty($song->id)) {
                     $this->db->query("DELETE FROM song WHERE id=%i", $song->id);
                     $this->nameModel->clear('song', array('name_id', 'text_name_id'));
                 }
             }
         }
     } catch (Exception $ex) {
         $this->db->rollback();
         throw $ex;
     }
     $this->db->commit();
     return $id;
 }
コード例 #2
0
ファイル: PageModel.php プロジェクト: claryaldringen/Backend
 public function setPage($menuId, $text)
 {
     $this->db->begin();
     try {
         $nameId = $this->nameModel->setName($text, 'page', FALSE);
         $this->db->query("INSERT INTO [page] (menu_id, name_id) VALUES (%i, %i) ON DUPLICATE KEY UPDATE name_id=%i", $menuId, $nameId, $nameId);
         $this->nameModel->clear('page');
     } catch (Exception $ex) {
         $this->db->rollback();
         throw $ex;
     }
     $this->db->commit();
     return $this;
 }
コード例 #3
0
ファイル: MenuModel.php プロジェクト: claryaldringen/Backend
 protected function saveMenu(array $items, $parentId)
 {
     foreach ($items as $sort => $item) {
         if (!empty($item->text)) {
             $nameId = $this->nameModel->setName($item->text, 'menu');
             if (isset($item->id)) {
                 $this->db->query("UPDATE [menu] SET name_id=%i,sort=%i WHERE id=%i", $nameId, $sort, $item->id);
             } else {
                 $this->db->query("INSERT INTO [menu]", array('menu_id' => $parentId, 'name_id' => $nameId, 'site_id' => $this->siteId, 'sort' => $sort, 'visibility' => $item->visibility));
             }
         } elseif (isset($item->id)) {
             $this->db->query("DELETE FROM [menu] WHERE id=%i", $item->id);
         }
         if (isset($item->items)) {
             $this->saveMenu($item->items, $item->id);
         }
     }
 }
コード例 #4
0
 public function setArticle($menuId, $text, $id = NULL)
 {
     $this->db->begin();
     try {
         $nameId = $this->nameModel->setName($text, 'article', FALSE);
         if ($id) {
             $this->db->query("UPDATE [article] SET name_id=%i WHERE id=%i", $nameId, $id);
         } else {
             $this->db->query("INSERT INTO [article] (menu_id, name_id) VALUES (%i, %i)", $menuId, $nameId);
             $id = $this->db->getInsertId();
         }
         $this->setArticleUrl($text, $menuId, $id, $nameId);
         $this->moveArticleUp($menuId);
         $this->nameModel->clear('article');
     } catch (Exception $ex) {
         $this->db->rollback();
         throw $ex;
     }
     $this->db->commit();
     return $id;
 }
コード例 #5
0
 public function setFolderText($folderId, $text)
 {
     $this->db->begin();
     try {
         $nameId = $this->nameModel->setName($text, 'folder_has_name', FALSE);
         $this->db->query("INSERT INTO [folder_has_name]", array('folder_id' => $folderId, 'name_id' => $nameId), "ON DUPLICATE KEY UPDATE name_id=%i", $nameId);
     } catch (Exception $ex) {
         $this->db->rollback();
         throw $ex;
     }
     $this->db->commit();
     return $this;
 }
コード例 #6
0
 public function saveConcert($data)
 {
     $this->db->begin();
     try {
         $nameId = $this->nameModel->setName($data->name, 'concert', FALSE);
         $placeId = $this->nameModel->setName($data->place, 'concert', FALSE);
         $textId = $this->nameModel->setName($data->text, 'concert', FALSE);
         if ($data->id) {
             $id = $data->id;
             $sql = "UPDATE concert SET name_id=%i,text_name_id=%i,place_name_id=%i,image_id=%i,start_time=%s,ticket_uri=%s WHERE id=%i";
             $this->db->query($sql, $nameId, $textId, $placeId, $data->image_id, date('Y-m-d H:i:s', strtotime($data->start_time)), $data->ticket_uri, $id);
         } else {
             $insert = array('name_id' => $nameId, 'menu_id' => $data->menu_id, 'place_name_id' => $placeId, 'text_name_id' => $textId, 'image_id' => $data->image_id, 'start_time' => $data->start_time, 'ticket_uri' => $data->ticket_uri);
             $this->db->query("INSERT INTO concert", $insert);
             $id = $this->db->getInsertId();
         }
         $this->nameModel->clear('concert', array('name_id', 'place_name_id', 'text_name_id'));
         $this->db->commit();
     } catch (Exception $ex) {
         $this->db->rollback();
         throw $ex;
     }
     return $id;
 }