PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/life/modules/track/models/m_track.php

https://bitbucket.org/adifaisalr/popmaya
PHP | 282 lines | 170 code | 23 blank | 89 comment | 7 complexity | ceeecccf6005dbaf49a64b0b38dcc6e7 MD5 | raw file
  1. <?php
  2. class M_Track extends CI_Model
  3. {
  4. function save($mode, $whr, $arr){
  5. if($mode=='add'){
  6. $this->db->insert('tr_song', $arr);
  7. return $this->db->insert_id();
  8. }else{
  9. if($whr){
  10. $this->db->where($whr);
  11. }
  12. return $this->db->update('tr_song', $arr);
  13. }
  14. }
  15. /*function get_paged_list($limit, $offset = 0, $whr){
  16. $this->db->select('*');
  17. $this->db->from('tr_song');
  18. if($whr){ $this->db->where($whr); }
  19. $this->db->limit($limit, $offset);
  20. $query = $this->db->get();
  21. return $query->result();
  22. }*/
  23. function get_paged_list($limit, $offset = 0, $whr){
  24. $this->db->select('*');
  25. $this->db->from('tr_song');
  26. if($whr){
  27. $this->db->where($whr);
  28. //echo $whr;
  29. }
  30. $this->db->limit($limit, $offset);
  31. $query = $this->db->get();
  32. return $query->result();
  33. }
  34. //edited by Adi
  35. //27 dec 2011
  36. function item_info($item_id){
  37. $query = $this->db->select('*')
  38. ->from('tr_song')
  39. ->where('s_id', $item_id)
  40. ->get();
  41. if($row = $query->row()){
  42. return $row;
  43. }else{
  44. return false;
  45. }
  46. }
  47. //name : Adi
  48. //27 Dec 2011
  49. //get artist name by song
  50. function get_artist_name($id){
  51. $query = $this->db->select('artist_name')
  52. ->from('tr_member_artist')
  53. ->join('tr_song','tr_member_artist.ID=tr_song.artist_id')
  54. ->where('s_id',$id)
  55. ->get();
  56. if($row = $query->row()){
  57. return $row->artist_name;
  58. }else{
  59. return 'unknown';
  60. }
  61. }
  62. //name : Adi
  63. //27 Dec 2011
  64. //get album name by song
  65. function get_album_name($id){
  66. $query = $this->db->select('tr_album_song.title as album_title')
  67. ->from('tr_album_song')
  68. ->join('tr_song','tr_album_song.as_id=tr_song.albumID')
  69. ->where('s_id',$id)
  70. ->get();
  71. if($row = $query->row()){
  72. return $row->album_title;
  73. }else{
  74. return 'unknown';
  75. }
  76. }
  77. function count_all($whr){
  78. if($whr){ $this->db->where($whr); }
  79. $this->db->select('s_id');
  80. $this->db->from('tr_song');
  81. $query=$this->db->get();
  82. return $query->num_rows();
  83. }
  84. function remove_item($item_id){
  85. return $this->db->delete('tr_song', array('s_id' => $item_id));
  86. }
  87. //Name : Firman
  88. //Date : 18 Des 2011
  89. //Desc : Get image ads
  90. function get_image_ads()
  91. {
  92. $query = $this->db->get_where('tr_ads', array('position' => 'ads'));
  93. $this->db->order_by('RAND()','asc');
  94. $this->db->limit(1);
  95. return $query->result();
  96. }
  97. /*
  98. Nama: Nisa
  99. Tanggal: 21 Nov 2011
  100. Deskripsi: Get all genre
  101. */
  102. function get_genre()
  103. {
  104. $query=$this->db->get('tr_genre');
  105. return $query->result();
  106. }
  107. /*
  108. Nama: Adi
  109. Tanggal: 16 Des 2011
  110. Deskripsi: Get all artist
  111. */
  112. function get_artist()
  113. {
  114. $query=$this->db->get('tr_member_artist');
  115. return $query->result();
  116. }
  117. /*
  118. Nama: Nisa
  119. Tanggal: 24 Nov 2011
  120. Deskripsi: Get fav genre
  121. */
  122. function get_fav_genre($id)
  123. {
  124. $query=$this->db->select('up_favgenre')
  125. ->from('tr_user_profile')
  126. ->where('up_uid', $id)
  127. ->get();
  128. $row=$query->row();
  129. return $row->up_favgenre;
  130. }
  131. /*
  132. Nama: Adi
  133. Tanggal: 16 Desember 2011
  134. Deskripsi: Get fav artist
  135. */
  136. function get_fav_artist($id)
  137. {
  138. $query=$this->db->select('up_favartist')
  139. ->from('tr_user_profile')
  140. ->where('up_uid', $id)
  141. ->get();
  142. $row=$query->row();
  143. return $row->up_favartist;
  144. }
  145. /*
  146. Nama: Nisa
  147. Tanggal: 24 Nov 2011
  148. Deskripsi: Get my fav song list
  149. */
  150. function get_fav_song($id, $limit)
  151. {
  152. $query=$this->db->select('tr_member_artist.title as artist, tr_song.title')
  153. ->from('tr_fave_song')
  154. ->join('tr_song', 'tr_song.s_id=tr_fave_song.songID')
  155. ->join('tr_member_artist', 'tr_member_artist.memberID=tr_song.memberID')
  156. ->where('tr_fave_song.memberID', $id)
  157. ->limit($limit)
  158. ->get();
  159. return $query->result();
  160. }
  161. /* zy. temporary model */
  162. function get_fave($id, $limit)
  163. {
  164. $this->db->where(array('memberID'=>$id));
  165. $query=$this->db->get('tr_fave_song');
  166. return $query->result();
  167. }
  168. /*
  169. Nama: Nisa
  170. Tanggal: 24 Nov 2011
  171. Deskripsi: Get song by genre
  172. */
  173. //??
  174. function get_song_by_genre($id, $limit)
  175. {
  176. $query=$this->db->select('tr_member_artist.title as artist, tr_song.title')
  177. ->from('tr_song')
  178. ->join('tr_member_artist', 'tr_member_artist.memberID=tr_song.memberID')
  179. ->where('tr_song.genreID', $id)
  180. ->limit($limit)
  181. ->get();
  182. return $query->result();
  183. }
  184. /* Adi. 28 Des 2011. komentari song */
  185. function song_comment($comment, $songID, $user_id, $ip_addr)
  186. {
  187. //insert wall comment
  188. $data = array(
  189. 'songID' => $songID,
  190. 'memberID' => $user_id,
  191. 'comment' => $comment,
  192. 'post' => now(),
  193. 'host' => $ip_addr
  194. );
  195. $this->db->insert('tr_song_comment', $data);
  196. /*
  197. //cari tau siapa yg punya wall
  198. $query=$this->db->get_where('tr_wall_item', array('ID'=>$wall_itemID));
  199. $result=$query->row();
  200. $user_have_wall=$result->memberID;
  201. //insert notification
  202. $data = array(
  203. 'n_type' => '1',
  204. 'n_itemid' => $wall_itemID,
  205. 'n_fromuserid' => $user_id,
  206. 'n_foruserid' => $user_have_wall,
  207. 'n_isread' => '0'
  208. );
  209. $this->db->insert('tr_notification', $data);*/
  210. }
  211. /* Adi. 28 Des 2011. ambil komentar2 terhadap suatu song */
  212. function get_song_comment($song_id)
  213. {
  214. $query=$this->db->select('tr_user_profile.up_uid, tr_user_profile.up_name, tr_user_profile.up_membersince, tr_song_comment.*')
  215. ->from('tr_song_comment')
  216. ->join('tr_user_profile', 'tr_user_profile.up_uid=tr_song_comment.memberID')
  217. ->where('tr_song_comment.songID', $song_id)
  218. ->order_by('post')
  219. ->get();
  220. return $query->result();
  221. }
  222. /* Adi. 28 Des 2011. aksi klik like suatu song */
  223. function song_like($s_id, $user_id)
  224. {
  225. //get jumlah like
  226. $query=$this->db->get_where('tr_song', array('s_id'=>$s_id));
  227. $result=$query->row();
  228. $like=$result->like;
  229. //update jumlah like
  230. $data = array(
  231. 'like' => $like+1
  232. );
  233. $this->db->where('s_id', $s_id);
  234. $this->db->update('tr_song', $data);
  235. /*
  236. //cari tau siapa yg punya wall
  237. $query=$this->db->get_where('tr_wall_item', array('ID'=>$wall_id));
  238. $result=$query->row();
  239. $user_have_wall=$result->memberID;
  240. //insert notification
  241. $data = array(
  242. 'n_type' => '3',
  243. 'n_itemid' => $wall_id,
  244. 'n_fromuserid' => $user_id,
  245. 'n_foruserid' => $user_have_wall,
  246. 'n_isread' => '0'
  247. );
  248. $this->db->insert('tr_notification', $data);*/
  249. }
  250. //Adi. 28 Des 2011. ambil jumlah like
  251. function get_song_like($s_id){
  252. $query=$this->db->get_where('tr_song', array('s_id'=>$s_id));
  253. $result=$query->row();
  254. return $result->like;
  255. }
  256. }
  257. ?>