PageRenderTime 86ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/app/controllers/analytics_controller.php

https://github.com/hilkeros/MMM-php-cake
PHP | 3520 lines | 2417 code | 839 blank | 264 comment | 250 complexity | a97a5f3d268ddc9a30cfe58331463575 MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. class AnalyticsController extends AppController {
  3. var $name = 'Analytics';
  4. var $etime = NULL;
  5. var $uses = array('User','Band','Lfm','Lfmtrack','Lfmalbum','Lfmlistener','Mss','Mssstat','Msscomm','Msslogin','Fb','Fbpage','Yt','Ytstat','Ytcommstat');
  6. var $helpers = array('Html', 'Error', 'Javascript' , 'FlashChart');
  7. var $components = array('Cookie'); // use component email
  8. /**
  9. * Name: beforeFilter
  10. * Desc: Performs necessary steps and function calls prior to executing
  11. * any view function calls.
  12. */
  13. function beforeFilter() {
  14. $this->auth();
  15. } // function beforeFilter() {
  16. /* Name: index
  17. * Desc: set MySpace , Facebook , Last.fm , Youtube ID's by select option box.
  18. */
  19. function index()
  20. {
  21. $this->layout = "analytics";
  22. if($this->data)
  23. {
  24. $this->Session->write('mssvideo', $this->data['data']['mssvideo']);
  25. $this->Session->write('video', $this->data['data']['video']);
  26. $this->Session->write('topalbum', $this->data['data']['album']);
  27. $this->Session->write('toptrack', $this->data['data']['tracks']);
  28. $this->redirect('/analytics/cmslist/');
  29. exit;
  30. } // if($this->data)
  31. else
  32. {
  33. $mmm_id = $this->Session->read('id');
  34. if(@$this->params['url']['bandid'])
  35. {
  36. $band_id = $this->params['url']['bandid'];
  37. } // if(@$this->params['url']['bandid'])
  38. else
  39. {
  40. $band = $this->Band->find(array('mmm_id'=>$mmm_id,'status'=>'1'));
  41. if($band)
  42. {
  43. $band_id = $band['Band']['band_id'];
  44. }
  45. else
  46. {
  47. $this->Session->setFlash('Please Add Band');
  48. $this->redirect('/band/index/');
  49. }
  50. } // if(@$this->params['url']['bandid'])
  51. $band = $this->Band->findAll(array('mmm_id'=>$mmm_id,'status'=>'1'));
  52. if($band)
  53. {
  54. $this->set('band',$band);
  55. foreach($band as $bandkey =>$bandval)
  56. {
  57. if($bandval['Band']['band_id']==$band_id)
  58. {
  59. $bandname = $bandval['Band']['name'];
  60. break;
  61. }
  62. }
  63. $this->set('bandname',$bandname);
  64. $this->Session->write('bandname',$bandname);
  65. }
  66. $this->Session->write('band_id',$band_id);
  67. $qry_mss = "select p.title from mss_play_stat p , mss_login m where p.mss_id = m.mss_id and m.mmm_id='$mmm_id' and m.band_id=$band_id";
  68. $mss_plays = $this->Mssstat->findBySql($qry_mss);
  69. if($mss_plays)
  70. {
  71. $this->set('mss_plays',$mss_plays);
  72. } // if($results)
  73. else
  74. {
  75. $mss_plays[0]['p']['title'] = 'No data';
  76. $this->set('mss_plays',$mss_plays);
  77. }
  78. $qry_lfm_album = "select a.name from lfm_top_album a , lfm_music m where a.lfm_m_id = m.lfm_m_id and m.mmm_id='$mmm_id' and m.band_id=$band_id";
  79. $lfm_album = $this->Lfmalbum->findBySql($qry_lfm_album);
  80. if($lfm_album)
  81. {
  82. $this->set('lfm_album',$lfm_album);
  83. } // if($results)
  84. else
  85. {
  86. $lfm_album[0]['a']['name'] = 'No data';
  87. $this->set('lfm_album',$lfm_album);
  88. }
  89. $qry_lfm_track = "select t.name from lfm_top_tracks t , lfm_music m where t.lfm_m_id = m.lfm_m_id and m.mmm_id='$mmm_id' and m.band_id=$band_id";
  90. $lfm_track = $this->Lfmalbum->findBySql($qry_lfm_track);
  91. if($lfm_track)
  92. {
  93. $this->set('lfm_track',$lfm_track);
  94. } // if($results)
  95. else
  96. {
  97. $lfm_track[0]['t']['name'] = 'No data';
  98. $this->set('lfm_track',$lfm_track);
  99. }
  100. $qry_yt_video= "select y.title from yt_comments_stat y , yt_login l where y.yt_id = l.yt_id and l.mmm_id='$mmm_id' and l.band_id=$band_id";
  101. $ytvideo = $this->Ytcommstat->findBySql($qry_yt_video);
  102. if($ytvideo)
  103. {
  104. $this->set('ytvideo',$ytvideo);
  105. } // if($results)
  106. else
  107. {
  108. $ytvideo[0]['y']['title'] = 'No data';
  109. $this->set('ytvideo',$ytvideo);
  110. }
  111. $fb = $this->Fb->find(array('mmm_id'=>$mmm_id , 'band_id'=>$band_id , 'status'=>1));
  112. if($fb)
  113. {
  114. $page = $fb['Fb']['page'];
  115. $group = $fb['Fb']['group'];
  116. if($page)
  117. {
  118. $this->Session->write('fbpages', $page);
  119. }
  120. else
  121. {
  122. $page = 'No data';
  123. $this->Session->write('fbpages', $page);
  124. }
  125. if($group)
  126. {
  127. $this->Session->write('fbgroups', $group);
  128. }
  129. else
  130. {
  131. $group = 'No data';
  132. $this->Session->write('fbgroups', $group);
  133. }
  134. } // if($results)
  135. else
  136. {
  137. $page = 'No data';
  138. $group = 'No data';
  139. $this->Session->write('fbpages', $page);
  140. $this->Session->write('fbgroups', $group);
  141. }
  142. } // if($this->data)
  143. } // function index()
  144. /*
  145. Name : album
  146. Desc : Ajax Album to get top album against last.fm Music Group
  147. */
  148. function album()
  149. {
  150. if(!empty($this->params['url']['id']))
  151. {
  152. $id = $this->params['url']['id'];
  153. $qry="select distinct l.name from lfm_top_album l where l.lfm_m_id = $id";
  154. $result = $this->Lfmalbum->findBySql($qry);
  155. $data = "[";
  156. foreach($result as $key =>$val)
  157. {
  158. $nm = str_replace(array("\"","'"),array(" "," "),$val['l']['name']);
  159. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  160. }
  161. $data= substr($data,0,strlen($data)-1);
  162. $data.="]";
  163. echo $data;
  164. exit;
  165. }
  166. } // function album
  167. /*
  168. Name : tracks
  169. Desc : Ajax Album to get top tracks against last.fm Music Group
  170. */
  171. function tracks()
  172. {
  173. if(!empty($this->params['url']['id']))
  174. {
  175. $id = $this->params['url']['id'];
  176. $qry="select distinct l.name from lfm_top_tracks l where l.lfm_m_id = $id";
  177. $result = $this->Lfmalbum->findBySql($qry);
  178. $data = "[";
  179. foreach($result as $key =>$val)
  180. {
  181. $nm = str_replace(array("\"","'"),array(" "," "),$val['l']['name']);
  182. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  183. }
  184. $data= substr($data,0,strlen($data)-1);
  185. $data.="]";
  186. echo $data;
  187. exit;
  188. }
  189. } // function tracks
  190. /*
  191. Name : comments
  192. Desc : Ajax to get youtube video title
  193. */
  194. function comments()
  195. {
  196. if(!empty($this->params['url']['id']))
  197. {
  198. $id = $this->params['url']['id'];
  199. $qry="select distinct y.title from yt_comments_stat y where y.yt_id = $id";
  200. $result = $this->Lfmalbum->findBySql($qry);
  201. $data = "[";
  202. foreach($result as $key =>$val)
  203. {
  204. $nm = str_replace(array("\"","'"),array(" "," "),$val['y']['title']);
  205. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  206. }
  207. $data= substr($data,0,strlen($data)-1);
  208. $data.="]";
  209. echo $data;
  210. exit;
  211. }
  212. } // function comments()
  213. /*
  214. Name : mssplays
  215. Desc : Ajax to get Myspace title
  216. */
  217. function mssplays()
  218. {
  219. if(!empty($this->params['url']['id']))
  220. {
  221. $id = $this->params['url']['id'];
  222. $qry="select distinct m.title from mss_play_stat m where m.mss_id = $id";
  223. $result = $this->Lfmalbum->findBySql($qry);
  224. $data = "[";
  225. foreach($result as $key =>$val)
  226. {
  227. $nm = str_replace(array("\"","'"),array(" "," "),$val['m']['title']);
  228. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  229. }
  230. $data= substr($data,0,strlen($data)-1);
  231. $data.="]";
  232. echo $data;
  233. exit;
  234. }
  235. } // function comments()
  236. /*
  237. Name : Facebook Pages
  238. Desc : Ajax to get Fbs pages
  239. */
  240. function fbspages()
  241. {
  242. if(!empty($this->params['url']['id']))
  243. {
  244. $id = $this->params['url']['id'];
  245. $qry="select distinct f.name from fb_pages f where f.login_id = $id and f.is_admin=1";
  246. $result = $this->Lfmalbum->findBySql($qry);
  247. $data = "[";
  248. foreach($result as $key =>$val)
  249. {
  250. $nm = str_replace(array("\"","'"),array(" "," "),$val['f']['name']);
  251. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  252. }
  253. $data= substr($data,0,strlen($data)-1);
  254. $data.="]";
  255. echo $data;
  256. exit;
  257. }
  258. } // function fbspages()
  259. /*
  260. Name : Facebook Groups
  261. Desc : Ajax to get Fbs Groups
  262. */
  263. function fbsgroups()
  264. {
  265. if(!empty($this->params['url']['id']))
  266. {
  267. $id = $this->params['url']['id'];
  268. $qry="select distinct f.name from fb_group f where f.login_id = $id and f.isCreator='Yes'";
  269. $result = $this->Lfmalbum->findBySql($qry);
  270. $data = "[";
  271. foreach($result as $key =>$val)
  272. {
  273. $nm = str_replace(array("\"","'"),array(" "," "),$val['f']['name']);
  274. $data.= "{ optionValue:'$nm' , optionDisplay:'$nm'},";
  275. }
  276. $data= substr($data,0,strlen($data)-1);
  277. $data.="]";
  278. echo $data;
  279. exit;
  280. }
  281. } // function fbspages()
  282. /*
  283. Name : cmslist
  284. Desc : link hits , view , plays and comments
  285. */
  286. function cmslist()
  287. {
  288. if($this->Session->check('id') and $this->Session->check('band_id') and $this->Session->check('bandname') and $this->Session->check('toptrack') and $this->Session->check('topalbum') and $this->Session->check('video') and $this->Session->check('mssvideo'))
  289. {
  290. $bandname = $this->Session->read('bandname');
  291. $this->set('bandname',$bandname);
  292. if($this->Session->read('mssvideo')!='No data')
  293. { $this->Session->write('msh','msh');
  294. $this->Session->write('msv','msv');
  295. $this->Session->write('msp','msp');
  296. $this->Session->write('msc','msc');
  297. }
  298. if($this->Session->read('video')!='No data')
  299. {
  300. $this->Session->write('yth','yth');
  301. $this->Session->write('ytv','ytv');
  302. $this->Session->write('ytp','ytp');
  303. $this->Session->write('ytc','ytc');
  304. }
  305. if(($this->Session->read('topalbum')!='No data') and ($this->Session->read('toptrack')!='No data'))
  306. {
  307. $this->Session->write('lfmsh','lfmsh');
  308. $this->Session->write('lfmsv','lfmsv');
  309. $this->Session->write('lfmsp','lfmsp');
  310. }
  311. if($this->Session->read('fbpages')!='No data')
  312. $this->Session->write('fbspages','fbspages');
  313. if($this->Session->read('fbgroups')!='No data')
  314. $this->Session->write('fbsgroups','fbsgroups');
  315. $this->layout = 'analyticcms';
  316. } // if($this->Session->check('id') and $this->Session->check('band_id') and $this->Session->check('bandname') and $this->Session->check('toptrack') and $this->Session->check('topalbum') and $this->Session->check('video') and $this->Session->check('mssvideo'))
  317. else
  318. {
  319. $this->redirect('/analytics/index');
  320. } // if($this->Session->check('email') and $this->Session->check('band_id') and $this->Session->check('bandname') and $this->Session->check('toptrack') and $this->Session->check('topalbum') and $this->Session->check('video') and $this->Session->check('mssvideo'))
  321. } // function cmslist()
  322. /*
  323. name : chart
  324. set : get and set data for fans , hits , tracks & comments
  325. */
  326. function chart()
  327. {
  328. /*
  329. get and set light box & graph width & height
  330. */
  331. if(!empty($this->params['url']['width']) and !empty($this->params['url']['height']))
  332. {
  333. $width = $this->params['url']['width'] ;
  334. $height = $this->params['url']['height'] ;
  335. }
  336. else
  337. {
  338. $width = 600;
  339. $height=400;
  340. }
  341. $this->set('cwidth',$width);
  342. $this->set('cheight',$height);
  343. $this->set('width',round($width/1.25));
  344. $this->set('height',round($height/1.5));
  345. // End get and set light box & graph width & height
  346. $mmm_id = $this->Session->read('id');
  347. // get and set band ID
  348. if(!empty($this->params['url']['bandid']))
  349. {
  350. $band_id = $this->params['url']['bandid'];
  351. $this->Session->write('band_id',$band_id);
  352. } // if(@$this->params['url']['bandid'])
  353. elseif($this->Session->check('band_id'))
  354. {
  355. $band_id = $this->Session->read('band_id');
  356. }
  357. else
  358. {
  359. $this->set('flag',1);
  360. }//if(@$this->params['url']['bandid'])
  361. $band = $this->Band->find(array('mmm_id'=>$mmm_id,'status'=>'1','band_id'=>$band_id));
  362. if($band)
  363. {
  364. $bandname = $band['Band']['name'];
  365. $this->set('bandname',$bandname);
  366. $this->Session->write('bandname',$bandname);
  367. }
  368. $this->Session->write('band_id',$band_id);
  369. // Get and set values for Myspace , youtube , last.fm
  370. // Get and set values for MySpace Tracks Tab
  371. $qry_mss = "select distinct p.title from mss_play_stat p , mss_login m where p.mss_id = m.mss_id and m.mmm_id='$mmm_id' and m.band_id=$band_id and m.status=1";
  372. $mss_plays = $this->Mssstat->findBySql($qry_mss);
  373. $mss = NULL;
  374. if($mss_plays)
  375. {
  376. if(!empty($this->params['url']['mss'])) // if option select from light box
  377. {
  378. $this->Session->write('mssvideo', $this->params['url']['mss']);
  379. $this->set('mssval',$this->params['url']['mss']); // to select dropdown list value
  380. }
  381. else
  382. {
  383. $this->Session->write('mssvideo', $mss_plays[0]['p']['title']);
  384. $this->set('mssval',$mss_plays[0]['p']['title']);
  385. }
  386. foreach($mss_plays as $key => $mssval)
  387. {
  388. $mss[$mssval['p']['title']] = $mssval['p']['title'] ;
  389. }
  390. $this->set('mss',$mss);
  391. } // if($results)
  392. else
  393. {
  394. $mss_plays[0]['p']['title'] = 'No data';
  395. $this->Session->write('mssvideo', $mss_plays[0]['p']['title']);
  396. $mss['No data'] = 'No data';
  397. $this->set('mssval','No data');
  398. $this->set('mss',$mss);
  399. }
  400. // Get and set values for Last.fm Tracks Tab
  401. $qry_lfm_track = "select distinct t.name from lfm_top_tracks t , lfm_music m where t.lfm_m_id = m.lfm_m_id and m.mmm_id='$mmm_id' and m.band_id=$band_id and m.status=1";
  402. $lfm_track = $this->Lfmalbum->findBySql($qry_lfm_track);
  403. $lfmt=NULL;
  404. if($lfm_track)
  405. {
  406. if(!empty($this->params['url']['lfmt']))
  407. {
  408. $this->Session->write('toptrack', $this->params['url']['lfmt']);
  409. $this->set('lfmtval',$this->params['url']['lfmt']);
  410. }
  411. else
  412. {
  413. $this->Session->write('toptrack', $lfm_track[0]['t']['name']);
  414. $this->set('lfmtval',$lfm_track[0]['t']['name']);
  415. }
  416. foreach($lfm_track as $key => $lfmval)
  417. {
  418. $lfmt[$lfmval['t']['name']] = $lfmval['t']['name'];
  419. }
  420. $this->set('lfmt',$lfmt);
  421. } // if($results)
  422. else
  423. {
  424. $lfm_track[0]['t']['name'] = 'No data';
  425. $this->Session->write('toptrack', $lfm_track[0]['t']['name']);
  426. $lfmt['No data'] = 'No data';
  427. $this->set('lfmt',$lfmt);
  428. $this->set('lfmtval','No data');
  429. }
  430. // Get and set values for Youtubne Tracks & comments Tab
  431. $qry_yt_video= "select distinct y.title from yt_comments_stat y , yt_login l where y.yt_id = l.yt_id and l.mmm_id='$mmm_id' and l.band_id=$band_id and l.status=1";
  432. $ytvideo = $this->Ytcommstat->findBySql($qry_yt_video);
  433. $yt=NULL;
  434. if($ytvideo)
  435. {
  436. if(!empty($this->params['url']['yt']))
  437. {
  438. $this->Session->write('video', $this->params['url']['yt']);
  439. $this->set('ytval',$this->params['url']['yt']);
  440. }
  441. else
  442. {
  443. $this->Session->write('video', $ytvideo[0]['y']['title']);
  444. $this->set('ytval',$ytvideo[0]['y']['title']);
  445. }
  446. foreach($ytvideo as $key => $ytval)
  447. {
  448. $yt[$ytval['y']['title']] = $ytval['y']['title'];
  449. }
  450. $this->set('yt',$yt);
  451. } // if($results)
  452. else
  453. {
  454. $ytvideo[0]['y']['title'] = 'No data';
  455. $this->Session->write('video', $ytvideo[0]['y']['title']);
  456. $yt['No data'] = 'No data';
  457. $this->set('yt',$yt);
  458. $this->set('ytval','No data');
  459. }
  460. // Get and set facebook pages & group data for Fans Tab
  461. $fb = $this->Fb->find(array('mmm_id'=>$mmm_id , 'band_id'=>$band_id , 'status'=>1));
  462. if($fb)
  463. {
  464. $page = $fb['Fb']['page'];
  465. $group = $fb['Fb']['group'];
  466. if($page)
  467. {
  468. $this->Session->write('fbpages', $page);
  469. }
  470. else
  471. {
  472. $page = 'No data';
  473. $this->Session->write('fbpages', $page);
  474. }
  475. if($group)
  476. {
  477. $this->Session->write('fbgroups', $group);
  478. }
  479. else
  480. {
  481. $group = 'No data';
  482. $this->Session->write('fbgroups', $group);
  483. }
  484. } // if($results)
  485. else
  486. {
  487. $page = 'No data';
  488. $group = 'No data';
  489. $this->Session->write('fbpages', $page);
  490. $this->Session->write('fbgroups', $group);
  491. }
  492. /*
  493. if in case chart call within the chart
  494. else in case of chart first time call without dates then default date & option applied
  495. */
  496. if(!empty($this->params['url']['date']))
  497. {
  498. $lastdate = $this->params['url']['date'];
  499. $this->Session->write('lastdate',$lastdate);
  500. $this->set('lastdate',$lastdate );
  501. if(!empty($this->params['url']['id']))
  502. {
  503. $id = $this->params['url']['id'];
  504. // set On / Off buttons
  505. switch($id)
  506. {
  507. case 'hall' :
  508. $this->Session->write('msv','msv');// Myspace hits
  509. $this->Session->write('ytv','ytv');// Youtube hits
  510. $this->Session->write('lfmsv','lfmsv'); // last.fm hits
  511. $this->Session->write('hnone',0);
  512. break;
  513. case 'hnone' :
  514. $this->Session->delete('msv');// Myspace hits
  515. $this->Session->delete('ytv');// Youtube hits
  516. $this->Session->delete('lfmsv');// last.fm hits
  517. if($this->Session->read('hnone')==1)
  518. {
  519. $this->Session->write('hnone',0);
  520. }
  521. else
  522. {
  523. $this->Session->write('hnone',1);
  524. }
  525. break;
  526. case 'fall' :
  527. $this->Session->write('msh','msh');// Myspace fans
  528. $this->Session->write('yth','yth');// Youtube fans
  529. $this->Session->write('lfmsh','lfmsh'); // last.fm fans
  530. $this->Session->write('fbspages','fbspages'); // facebook page flag
  531. $this->Session->write('fbsgroups','fbsgroups'); // facebook group flag
  532. $this->Session->write('fnone',0);
  533. break;
  534. case 'fnone' :
  535. $this->Session->delete('msh');// Myspace fans
  536. $this->Session->delete('yth');// Youtube fans
  537. $this->Session->delete('lfmsh'); // last.fm fans
  538. $this->Session->delete('fbspages'); // facebook page flag
  539. $this->Session->delete('fbsgroups'); // facebook group flag
  540. if($this->Session->read('fnone')==1)
  541. {
  542. $this->Session->write('fnone',0);
  543. }
  544. else
  545. {
  546. $this->Session->write('fnone',1);
  547. }
  548. break;
  549. case 'tall' :
  550. $this->Session->write('msp','msp');// Myspace tracks
  551. $this->Session->write('ytp','ytp');// Youtube tracks
  552. $this->Session->write('lfmsp','lfmsp'); // last.fm tracks
  553. $this->Session->write('tnone',0);
  554. break;
  555. case 'tnone' :
  556. $this->Session->delete('msp');// Myspace tracks
  557. $this->Session->delete('ytp');// Youtube tracks
  558. $this->Session->delete('lfmsp'); // last.fm tracks
  559. if($this->Session->read('tnone')==1)
  560. {
  561. $this->Session->write('tnone',0);
  562. }
  563. else
  564. {
  565. $this->Session->write('tnone',1);
  566. }
  567. break;
  568. case 'call' :
  569. $this->Session->write('msc','msc');// Myspace comments
  570. $this->Session->write('ytc','ytc');// Youtube comments
  571. $this->Session->write('cnone',0);
  572. break;
  573. case 'cnone' :
  574. $this->Session->delete('msc');// Myspace comments
  575. $this->Session->delete('ytc');// Youtube comments
  576. if($this->Session->read('cnone')==1)
  577. {
  578. $this->Session->write('cnone',0);
  579. }
  580. else
  581. {
  582. $this->Session->write('cnone',1);
  583. }
  584. break;
  585. default :
  586. $type = $this->params['url']['type'];
  587. if($type=='fans')
  588. {
  589. $this->Session->write('fnone',0);
  590. }
  591. elseif($type=='hits')
  592. {
  593. $this->Session->write('hnone',0);
  594. }
  595. elseif($type=='tracks')
  596. {
  597. $this->Session->write('tnone',0);
  598. }
  599. elseif($type=='comments')
  600. {
  601. $this->Session->write('cnone',0);
  602. }
  603. if (!$this->Session->check($id))
  604. {
  605. $this->Session->write($id,$id);
  606. }
  607. else
  608. {
  609. $this->Session->delete($id);
  610. }
  611. break;
  612. }
  613. $this->set('id',$id);
  614. } // if(!empty($this->params['url']['id']))
  615. $this->sethitschart(); // get fans for facebook pages & groups , youtueb , myspace , last.fm
  616. if($this->params['url']['type']=='fans')
  617. {
  618. $this->Session->write('type','fans');
  619. }
  620. $this->setviewschart(); // get hits for youtube , myspace , last.fm
  621. if($this->params['url']['type']=='hits')
  622. {
  623. $this->Session->write('type','hits');
  624. }
  625. $this->setplayschart(); // get tracks for youtube , myspace , last.fm
  626. if($this->params['url']['type']=='tracks')
  627. {
  628. $this->Session->write('type','tracks');
  629. }
  630. $this->setcommentchart(); // get comments for youtube , myspace
  631. if($this->params['url']['type']=='comments')
  632. {
  633. $this->Session->write('type','comments');
  634. }
  635. } // if(!empty($this->params['url']['date']) and !empty($this->params['url']['opt']))
  636. else
  637. {
  638. if($this->Session->check('lastdate'))
  639. {
  640. $this->Session->delete('lastdate');
  641. }
  642. $this->Session->write('lastdate','w');
  643. $this->set('lastdate','w');
  644. $this->Session->write('msh','msh');// Myspace fans
  645. $this->Session->write('msv','msv');// Myspace hits
  646. $this->Session->write('msp','msp');// Myspace tracks
  647. $this->Session->write('msc','msc');// Myspace comments
  648. $this->Session->write('yth','yth');// Youtube fans
  649. $this->Session->write('ytv','ytv');// Youtube hits
  650. $this->Session->write('ytp','ytp');// Youtube tracks
  651. $this->Session->write('ytc','ytc');// Youtube comments
  652. $this->Session->write('lfmsh','lfmsh'); // last.fm fans
  653. $this->Session->write('lfmsv','lfmsv'); // last.fm hits
  654. $this->Session->write('lfmsp','lfmsp'); // last.fm tracks
  655. $this->Session->write('fbspages','fbspages'); // facebook page flag
  656. $this->Session->write('fbsgroups','fbsgroups'); // facebook group flag
  657. $this->Session->write('type','fans');
  658. $this->setcommentchart(); // get comments for youtube , myspace
  659. $this->setviewschart(); // get hits for youtube , myspace , last.fm
  660. $this->setplayschart(); // get tracks for youtube , myspace , last.fm
  661. $this->sethitschart(); // get fans for facebook , youtube , myspace & last.fm
  662. } // if(!empty($this->params['url']['date']) and !empty($this->params['url']['opt']))
  663. $this->layout="stats";
  664. } // function chart()
  665. /*
  666. Name : commentchart
  667. Desc : Get graph values from sessions and display graph
  668. */
  669. function commentchart()
  670. {
  671. $dt = $this->Session->read('dt');
  672. $mscomment = $this->Session->read('mscomment');
  673. $ytcomment = $this->Session->read('ytcomment');
  674. $this->set('dt',$dt);
  675. $this->set('mscomment',$mscomment);
  676. $this->set('ytcomment',$ytcomment);
  677. } // function setcommentchart()
  678. /*
  679. Name : setcommentchart
  680. Desc : Get graph values and return to comment()
  681. */
  682. function setcommentchart()
  683. {
  684. if($this->Session->check('id') and $this->Session->check('band_id') and $this->Session->check('video'))
  685. {
  686. $mmm_id = $this->Session->read('id');
  687. $band_id = $this->Session->read('band_id');
  688. $video = $this->Session->read('video');
  689. }
  690. else
  691. {
  692. //$this->Session->setFlash('Session Expired');
  693. //$this->redirect('/analytics/index/');
  694. return ;
  695. } // if($this->Session->check('email') and $this->Session->check('band_id') and $this->Session->check('video'))
  696. $mss= NULL;
  697. $yt=NULL;
  698. $album=NULL;
  699. if($this->Session->read('lastdate')=='w') // weekly graphs quries
  700. {
  701. $qry_mss = "select s.comments , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  702. $qry_yt = "select y.total_comments comments , y.etime from yt_comments_stat y , yt_login l where title='$video' and y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  703. if(!empty($this->params['url']['id']))
  704. {
  705. if ($this->Session->check('msc'))
  706. {
  707. $mss = $this->Mss->findBySql($qry_mss);
  708. }
  709. if ($this->Session->check('ytc'))
  710. {
  711. $yt = $this->Ytstat->findBySql($qry_yt);
  712. }
  713. } // if(!empty($this->params['url']['id']))
  714. else
  715. {
  716. $mss = $this->Mss->findBySql($qry_mss);
  717. $yt = $this->Ytstat->findBySql($qry_yt);
  718. } // if(!empty($this->params['url']['id']))
  719. $qry= "select DATE_SUB(CURDATE(), INTERVAL 7 DAY) last, CURDATE() curr";
  720. $tfdate = $this->Ytstat->findBySql($qry);
  721. $dt =NULL;
  722. $date = NULL;
  723. $c=0;
  724. $dt[$c]=$tfdate['0']['0']['last'];
  725. while($tfdate['0']['0']['curr']!=$date)
  726. {
  727. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  728. $c ++;
  729. if($c==7) // i.e 0-6 last 7 days
  730. {
  731. break;
  732. }
  733. $dt[$c]= $date;
  734. } // while($tfdate['0']['0']['curr']!=$date)
  735. } // if($this->Session->read('lastdate')=='w') // weekly graphs quries
  736. elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  737. {
  738. $qry_mss = "select s.comments , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  739. $qry_yt = "select y.total_comments comments , y.etime from yt_comments_stat y , yt_login l where y.title='$video' and y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  740. if(!empty($this->params['url']['id']))
  741. {
  742. if ($this->Session->check('msc'))
  743. {
  744. $mss = $this->Mss->findBySql($qry_mss);
  745. }
  746. if ($this->Session->check('ytc'))
  747. {
  748. $yt = $this->Ytstat->findBySql($qry_yt);
  749. }
  750. } // if(!empty($this->params['url']['id']))
  751. else
  752. {
  753. $mss = $this->Mss->findBySql($qry_mss);
  754. $yt = $this->Ytstat->findBySql($qry_yt);
  755. } // if(!empty($this->params['url']['id']))
  756. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Month) last, CURDATE() curr";
  757. $tfdate = $this->Ytstat->findBySql($qry);
  758. $dt =NULL;
  759. $date = NULL;
  760. $c=0;
  761. $cdate= $tfdate['0']['0']['curr'];
  762. $curdate = date('Y-m-d',strtotime(date("Y-m-d", strtotime($cdate)) . " -1 day"));
  763. $d=$tfdate['0']['0']['last'];
  764. $dt[$c]=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d)) . " +1 day"));
  765. while($curdate!=$date)
  766. {
  767. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  768. $c ++;
  769. $dt[$c]= $date;
  770. } // while($tfdate['0']['0']['curr']!=$date)
  771. $this->Session->write('mm',count($dt));
  772. } // elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  773. elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  774. {
  775. $qry_mss = "select s.comments , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  776. $qry_yt = "select y.total_comments comments , y.etime from yt_comments_stat y , yt_login l where y.title='$video' and y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  777. if(!empty($this->params['url']['id']))
  778. {
  779. if ($this->Session->check('msc'))
  780. {
  781. $mss = $this->Mss->findBySql($qry_mss);
  782. $mss_data = $this->getyear($mss,'s','comments');
  783. }
  784. if ($this->Session->check('ytc'))
  785. {
  786. $yt = $this->Ytstat->findBySql($qry_yt);
  787. $yt_data =$this->getyear($yt,'y','comments');
  788. }
  789. } // if(!empty($this->params['url']['id']))
  790. else
  791. {
  792. /*
  793. select sum(s.views) , date_format(FROM_UNIXTIME(s.etime),'%m') from mss_stat s group by date_format(FROM_UNIXTIME(s.etime),'%m')
  794. */
  795. $mss = $this->Mss->findBySql($qry_mss);
  796. $yt = $this->Ytstat->findBySql($qry_yt);
  797. $mss_data = $this->getyear($mss,'s','comments');
  798. $yt_data =$this->getyear($yt,'y','comments');
  799. } // if(!empty($this->params['url']['id']))
  800. /*
  801. Month Wise Yearly date create
  802. */
  803. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Year) last, CURDATE() curr";
  804. $tfdate = $this->Ytstat->findBySql($qry);
  805. $dt =NULL;
  806. $date = NULL;
  807. $c=0;
  808. $td= $tfdate['0']['0']['curr'];
  809. $td=date('M',strtotime(date("Y-m-d", strtotime($td))));
  810. $d=$tfdate['0']['0']['last'];
  811. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  812. $dt[$c]=date('M',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  813. while($td!=$date)
  814. {
  815. $date = date('M',strtotime(date("Y-m-d", strtotime($edate)) . " +1 Month"));
  816. $c ++;
  817. $dt[$c]= $date;
  818. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($edate)). " +1 Month"));
  819. if($c>12)
  820. {
  821. break;
  822. } // if($c>12)
  823. } // while($tfdate['0']['0']['curr']!=$date)
  824. } // elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  825. $mscommentcount=NULL;
  826. $ytcommentcount=NULL;
  827. if($this->Session->read('lastdate')=='y') // set data according to date for yearly graph
  828. {
  829. $flg=0;
  830. if(empty($mss_data))
  831. {
  832. $mscount = 0;
  833. }
  834. else
  835. {
  836. $mscount = count($mss_data);
  837. }
  838. if(empty($yt_data))
  839. {
  840. $ytcount = 0;
  841. }
  842. else
  843. {
  844. $ytcount = count($yt_data);
  845. }
  846. $cnt=0;
  847. $ycnt=0;
  848. $lfcnt=0;
  849. foreach($dt as $key => $val) // main date loop
  850. {
  851. $flg=0;
  852. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  853. {
  854. if($mss_data[$i]['s']['etime']==$val)
  855. {
  856. $mscomment[$cnt]= $mss_data[$i]['s']['comments'] ;
  857. $mscommentcount += $mscomment[$cnt] ;
  858. $flg=1;
  859. $cnt++;
  860. break;
  861. } // if($mss_data[$i]['s']['etime'])==$val)
  862. } // for($i=0 ; $i < $mscount-1 ; $i++)
  863. if($flg==0)
  864. {
  865. $mscomment[$cnt]=0;
  866. $cnt++;
  867. }
  868. $flg=0;
  869. $count=0;
  870. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  871. {
  872. if($yt_data[$i]['y']['etime']==$val)
  873. {
  874. $ytcomment[$ycnt]= $yt_data[$i]['y']['comments'] ;
  875. $ytcommentcount+=$ytcomment[$ycnt] ;
  876. $flg=1;
  877. $ycnt ++;
  878. break;
  879. } // if($yt_data[$i]['y']['etime']==$val)
  880. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  881. if($flg==0)
  882. {
  883. $ytcomment[$ycnt]=0;
  884. $ycnt++;
  885. }
  886. /* if($flg==0 and $albumcount!=0)
  887. {
  888. $album_play[]= 0;
  889. } // if($flg==0)
  890. */
  891. } // foreach($dt as $key => $val)
  892. } // if($this->Session->read('lastdate')=='y')
  893. else // // set data according to date for Weekly & Monthly Graph
  894. {
  895. $flg=0;
  896. $mscount = count($mss);
  897. $ytcount = count($yt);
  898. $mscomment = NULL;
  899. $ytcomment=NULL;
  900. $flg=0;
  901. $cnt=0;
  902. $ycnt=0;
  903. $lfcnt=0;
  904. foreach($dt as $key => $val) // main date loop
  905. {
  906. $flg=0;
  907. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  908. {
  909. if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  910. {
  911. if($i!=0)
  912. {
  913. $mscomment[$cnt]= $mss[$i]['s']['comments']-$mss[$i-1]['s']['comments'];
  914. $mscommentcount += $mscomment[$cnt] ;
  915. }
  916. else
  917. {
  918. $mscomment[$cnt] = 0;
  919. }
  920. $flg=1;
  921. $cnt++;
  922. break;
  923. } // if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  924. } // for($i=0 ; $i < $mscount-1 ; $i++)
  925. if($flg==0)
  926. {
  927. $mscomment[$cnt]=0;
  928. $cnt++;
  929. }
  930. $flg=0;
  931. $count=0;
  932. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  933. {
  934. if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  935. {
  936. if($i!=0)
  937. {
  938. $ytcomment[$ycnt]= $yt[$i]['y']['comments']-$yt[$i-1]['y']['comments'];
  939. $ytcommentcount = $ytcomment[$ycnt] ;
  940. }else
  941. {
  942. $ytcomment[$ycnt]=0;
  943. }
  944. $flg=1;
  945. $ycnt ++;
  946. break;
  947. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  948. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  949. if($flg==0)
  950. {
  951. $ytcomment[$ycnt]=0;
  952. $ycnt++;
  953. }
  954. } // foreach($dt as $key => $val)
  955. } // if($this->Session->read('lastdate')=='y')
  956. /*
  957. * Session to set Average hits
  958. */
  959. $this->Session->write('ytcommentcount',$ytcommentcount);
  960. $this->Session->write('mscommentcount',$mscommentcount);
  961. /*
  962. * youtube and myspace data
  963. */
  964. $this->Session->write('dt',$dt);
  965. $this->Session->write('mscomment',$mscomment);
  966. $this->Session->write('ytcomment',$ytcomment);
  967. $msaverage = 0;
  968. $ytaverage = 0;
  969. $lfmaverage = 0;
  970. if($this->Session->read('lastdate')=='w')
  971. {
  972. $msaverage = round($mscommentcount/7,2);
  973. $ytaverage = round($ytcommentcount/7,2);
  974. }
  975. elseif($this->Session->read('lastdate')=='m')
  976. {
  977. $mm=$this->Session->read('mm');
  978. $msaverage = round($mscommentcount/$mm,2);
  979. $ytaverage = round($ytcommentcount/$mm,2);
  980. }
  981. elseif($this->Session->read('lastdate')=='y')
  982. {
  983. $msaverage = round($mscommentcount/12,2);
  984. $ytaverage = round($ytcommentcount/12,2);
  985. }
  986. $this->Session->write('msaverage',$msaverage);
  987. $this->Session->write('ytaverage',$ytaverage);
  988. $this->Session->write('lfmaverage',$lfmaverage);
  989. return true;
  990. } // function setcommentchart()
  991. /*
  992. Name : viewschart
  993. Desc : Get graph values from Session and display graph
  994. */
  995. function viewschart()
  996. {
  997. $dt = $this->Session->read('dt');
  998. $msview = $this->Session->read('msview');
  999. $ytview = $this->Session->read('ytview');
  1000. $lfmplay = $this->Session->read('lfmplay');
  1001. $this->set('dt',$dt);
  1002. $this->set('msview',$msview);
  1003. $this->set('ytview',$ytview);
  1004. $this->set('lfmplay',$lfmplay);
  1005. }
  1006. /*
  1007. Name : setviewschart
  1008. Desc : Get graph values and return to views()
  1009. */
  1010. function setviewschart()
  1011. {
  1012. if($this->Session->check('id') and $this->Session->check('band_id'))
  1013. {
  1014. $mmm_id = $this->Session->read('id');
  1015. $band_id = $this->Session->read('band_id');
  1016. }
  1017. else
  1018. {
  1019. //$this->Session->setFlash('Session Expired');
  1020. //$this->redirect('/analytics/index/');
  1021. return ;
  1022. } // if($this->Session->check('music') and $this->Session->check('profile') and $this->Session->check('channel') and $this->Session->check('email') and $this->Session->check('topalbum'))
  1023. $mss= NULL;
  1024. $yt=NULL;
  1025. $album=NULL;
  1026. if($this->Session->read('lastdate')=='w') // weekly graphs quries
  1027. {
  1028. $qry_mss = "select s.views , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1029. $qry_yt = "select y.views , y.etime from yt_stat y , yt_login l where y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1030. $qry_lfm = "select sum(t.playcount) playcount , t.etime from lfm_top_tracks t , lfm_music l where l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) group by t.etime order by etime";
  1031. if(!empty($this->params['url']['id']))
  1032. {
  1033. if ($this->Session->check('msv'))
  1034. {
  1035. $mss = $this->Mss->findBySql($qry_mss);
  1036. }
  1037. if ($this->Session->check('ytv'))
  1038. {
  1039. $yt = $this->Ytstat->findBySql($qry_yt);
  1040. }
  1041. if ($this->Session->check('lfmsv'))
  1042. {
  1043. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1044. }
  1045. } // if(!empty($this->params['url']['id']))
  1046. else
  1047. {
  1048. $mss = $this->Mss->findBySql($qry_mss);
  1049. $yt = $this->Ytstat->findBySql($qry_yt);
  1050. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1051. } // if(!empty($this->params['url']['id']))
  1052. $qry= "select DATE_SUB(CURDATE(), INTERVAL 7 DAY) last, CURDATE() curr";
  1053. $tfdate = $this->Ytstat->findBySql($qry);
  1054. $dt =NULL;
  1055. $date = NULL;
  1056. $c=0;
  1057. $dt[$c]=$tfdate['0']['0']['last'];
  1058. while($tfdate['0']['0']['curr']!=$date)
  1059. {
  1060. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  1061. $c ++;
  1062. if($c==7) // i.e 0-6 last 7 days
  1063. {
  1064. break;
  1065. }
  1066. $dt[$c]= $date;
  1067. } // while($tfdate['0']['0']['curr']!=$date)
  1068. } // if($this->Session->read('lastdate')=='w') // weekly graphs quries
  1069. elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  1070. {
  1071. $qry_mss = "select s.views , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id ='$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1072. $qry_yt = "select y.views , y.etime from yt_stat y , yt_login l where y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) order by etime";
  1073. $qry_lfm = "select sum(t.playcount) playcount , t.etime from lfm_top_tracks t , lfm_music l where l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Month) AND CURDATE( ) group by t.etime order by etime";
  1074. if(!empty($this->params['url']['id']))
  1075. {
  1076. if ($this->Session->check('msv'))
  1077. {
  1078. $mss = $this->Mss->findBySql($qry_mss);
  1079. }
  1080. if ($this->Session->check('ytv'))
  1081. {
  1082. $yt = $this->Ytstat->findBySql($qry_yt);
  1083. }
  1084. if ($this->Session->check('lfmsv'))
  1085. {
  1086. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1087. }
  1088. } // if(!empty($this->params['url']['id']))
  1089. else
  1090. {
  1091. $mss = $this->Mss->findBySql($qry_mss);
  1092. $yt = $this->Ytstat->findBySql($qry_yt);
  1093. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1094. } // if(!empty($this->params['url']['id']))
  1095. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Month) last, CURDATE() curr";
  1096. $tfdate = $this->Ytstat->findBySql($qry);
  1097. $dt =NULL;
  1098. $date = NULL;
  1099. $c=0;
  1100. $cdate= $tfdate['0']['0']['curr'];
  1101. $curdate = date('Y-m-d',strtotime(date("Y-m-d", strtotime($cdate)) . " -1 day"));
  1102. $d=$tfdate['0']['0']['last'];
  1103. $dt[$c]=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d))));
  1104. while($curdate!=$date)
  1105. {
  1106. $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime($dt[$c])) . " +1 day"));
  1107. $c ++;
  1108. $dt[$c]= $date;
  1109. } // while($tfdate['0']['0']['curr']!=$date)
  1110. $this->Session->write('mm',count($dt));
  1111. } // elseif($this->Session->read('lastdate')=='m') // monthly graphs quries
  1112. elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  1113. {
  1114. $qry_mss = "select s.views , s.etime from mss_stat s , mss_login l where s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1115. $qry_yt = "select y.views , y.etime from yt_stat y , yt_login l where y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) order by etime";
  1116. // special condition applied in getyear function because of sum(t.playcount) reutrn [0][playcount] instead of [t][playcount]
  1117. $qry_lfm = "select sum(t.playcount) playcount , t.etime etime from lfm_top_tracks t , lfm_music l where l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 1 Year) AND CURDATE( ) group by t.etime order by t.etime";
  1118. if(!empty($this->params['url']['id']))
  1119. {
  1120. if ($this->Session->check('msv'))
  1121. {
  1122. $mss = $this->Mss->findBySql($qry_mss);
  1123. $mss_data = $this->getyear($mss,'s','views');
  1124. }
  1125. if ($this->Session->check('ytv'))
  1126. {
  1127. $yt = $this->Ytstat->findBySql($qry_yt);
  1128. $yt_data =$this->getyear($yt,'y','views');
  1129. }
  1130. if ($this->Session->check('lfmsv'))
  1131. {
  1132. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1133. $album_data = $this->getyear($album,'t','playcount');
  1134. }
  1135. } // if(!empty($this->params['url']['id']))
  1136. else
  1137. {
  1138. $mss = $this->Mss->findBySql($qry_mss);
  1139. $yt = $this->Ytstat->findBySql($qry_yt);
  1140. $album = $this->Lfmalbum->findBySql($qry_lfm);
  1141. $mss_data = $this->getyear($mss,'s','views');
  1142. $yt_data =$this->getyear($yt,'y','views');
  1143. $album_data = $this->getyear($album,'t','playcount');
  1144. } // if(!empty($this->params['url']['id']))
  1145. /*
  1146. Month Wise Yearly date create
  1147. */
  1148. $qry= "select DATE_SUB(CURDATE(), INTERVAL 1 Year) last, CURDATE() curr";
  1149. $tfdate = $this->Ytstat->findBySql($qry);
  1150. $dt =NULL;
  1151. $date = NULL;
  1152. $c=0;
  1153. $td= $tfdate['0']['0']['curr'];
  1154. $td=date('M',strtotime(date("Y-m-d", strtotime($td))));
  1155. $d=$tfdate['0']['0']['last'];
  1156. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  1157. $dt[$c]=date('M',strtotime(date("Y-m-d", strtotime($d)). " +1 Month"));
  1158. while($td!=$date)
  1159. {
  1160. $date = date('M',strtotime(date("Y-m-d", strtotime($edate)) . " +1 Month"));
  1161. $c ++;
  1162. $dt[$c]= $date;
  1163. $edate=date('Y-m-d',strtotime(date("Y-m-d", strtotime($edate)). " +1 Month"));
  1164. if($c>12)
  1165. {
  1166. break;
  1167. } // if($c>12)
  1168. } // while($tfdate['0']['0']['curr']!=$date)
  1169. } // elseif($this->Session->read('lastdate')=='y') // yearly graphs quries
  1170. $msviewscount = NULL;
  1171. $ytviewscount = NULL;
  1172. $lfmviewscount = NULL;
  1173. if($this->Session->read('lastdate')=='y') // set data according to date for yearly graph
  1174. {
  1175. $flg=0;
  1176. if(empty($mss_data))
  1177. {
  1178. $mscount = 0;
  1179. }
  1180. else
  1181. {
  1182. $mscount = count($mss_data);
  1183. }
  1184. if(empty($yt_data))
  1185. {
  1186. $ytcount = 0;
  1187. }
  1188. else
  1189. {
  1190. $ytcount = count($yt_data);
  1191. }
  1192. if(empty($album_data))
  1193. {
  1194. $albumcount = 0;
  1195. }
  1196. else
  1197. {
  1198. $albumcount = count($album_data);
  1199. }
  1200. $flg=0;
  1201. $cnt=0;
  1202. $ycnt=0;
  1203. $lfcnt=0;
  1204. foreach($dt as $key => $val) // main date loop
  1205. {
  1206. $flg=0;
  1207. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  1208. {
  1209. if($mss_data[$i]['s']['etime']==$val)
  1210. {
  1211. $msview[$cnt]= $mss_data[$i]['s']['views'] ;
  1212. $msviewscount+=$msview[$cnt];
  1213. $flg=1;
  1214. $cnt++;
  1215. break;
  1216. } // if($mss_data[$i]['s']['etime'])==$val)
  1217. } // for($i=0 ; $i < $mscount-1 ; $i++)
  1218. if($flg==0)
  1219. {
  1220. $msview[$cnt]=0;
  1221. $cnt++;
  1222. }
  1223. $flg=0;
  1224. $count=0;
  1225. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  1226. {
  1227. if($yt_data[$i]['y']['etime']==$val)
  1228. {
  1229. $ytview[$ycnt]= $yt_data[$i]['y']['views'] ;
  1230. $ytviewscount+=$ytview[$ycnt];
  1231. $flg=1;
  1232. $ycnt ++;
  1233. break;
  1234. } // if($yt_data[$i]['y']['etime']==$val)
  1235. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1236. if($flg==0)
  1237. {
  1238. $ytview[$ycnt]=0;
  1239. $ycnt++;
  1240. }
  1241. $flg=0;
  1242. for($i=0 ; $i < $albumcount ; $i++) // set Las.fm top album playcount according to main loop date
  1243. {
  1244. if($album_data[$i]['t']['etime']==$val)
  1245. {
  1246. $lfmplay[$lfcnt]= $album_data[$i]['t']['playcount'];
  1247. $lfmviewscount+=$album_play[$lfcnt];
  1248. $flg=1;
  1249. $lfcnt++;
  1250. break;
  1251. } // if($album_data[$i]['t']['etime']==$val)
  1252. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1253. if($flg==0)
  1254. {
  1255. $lfmplay[$lfcnt]=0;
  1256. $lfcnt++;
  1257. }
  1258. /* if($flg==0 and $albumcount!=0)
  1259. {
  1260. $album_play[]= 0;
  1261. } // if($flg==0)
  1262. */
  1263. } // foreach($dt as $key => $val)
  1264. } // if($this->Session->read('lastdate')=='y')
  1265. else // // set data according to date for Weekly & Monthly Graph
  1266. {
  1267. $flg=0;
  1268. $mscount = count($mss);
  1269. $ytcount = count($yt);
  1270. $albumcount = count($album);
  1271. $flg=0;
  1272. $cnt=0;
  1273. $ycnt=0;
  1274. $lfcnt=0;
  1275. foreach($dt as $key => $val) // main date loop
  1276. {
  1277. $flg=0;
  1278. for($i=0 ; $i < $mscount ; $i++) // set Myspace views according to main loop date
  1279. {
  1280. if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  1281. {
  1282. if($i!=0)
  1283. {
  1284. $msview[$cnt]= $mss[$i]['s']['views']-$mss[$i-1]['s']['views'];
  1285. $msviewscount+=$msview[$cnt];
  1286. }
  1287. else
  1288. {
  1289. $msview[$cnt] = 0;
  1290. }
  1291. $flg=1;
  1292. $cnt++;
  1293. break;
  1294. } // if(date('Y-m-d',$mss[$i]['s']['etime'])==$val)
  1295. } // for($i=0 ; $i < $mscount-1 ; $i++)
  1296. if($flg==0)
  1297. {
  1298. $msview[$cnt]=0;
  1299. $cnt++;
  1300. }
  1301. $flg=0;
  1302. $count=0;
  1303. for($i=0 ; $i < $ytcount ; $i++) // set Youtube views according to main loop date
  1304. {
  1305. if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  1306. {
  1307. if($i!=0)
  1308. {
  1309. $ytview[$ycnt]= $yt[$i]['y']['views']-$yt[$i-1]['y']['views'];
  1310. $ytviewscount+=$ytview[$ycnt];
  1311. }else
  1312. {
  1313. $ytview[$ycnt]=0;
  1314. }
  1315. $flg=1;
  1316. $ycnt ++;
  1317. break;
  1318. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  1319. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1320. if($flg==0)
  1321. {
  1322. $ytview[$ycnt]=0;
  1323. $ycnt++;
  1324. }
  1325. $flg=0;
  1326. for($i=0 ; $i < $albumcount ; $i++) // set Las.fm top album playcount according to main loop date
  1327. {
  1328. if(date('Y-m-d',$album[$i]['t']['etime'])==$val)
  1329. {
  1330. if($i!=0)
  1331. {
  1332. $lfmplay[$lfcnt]= $album[$i][0]['playcount']-$album[$i-1][0]['playcount'];
  1333. $lfmviewscount+=$lfmplay[$lfcnt];
  1334. }
  1335. else
  1336. {
  1337. $lfmplay[$lfcnt]=0;
  1338. }
  1339. $flg=1;
  1340. $lfcnt++;
  1341. break;
  1342. } // if(date('Y-m-d',$yt[$i]['y']['etime'])==$val)
  1343. } // for($i=0 ; $i < $ytcount-1 ; $i++)
  1344. if($flg==0)
  1345. {
  1346. $lfmplay[$lfcnt]=0;
  1347. $lfcnt++;
  1348. }
  1349. /* if($flg==0 and $albumcount!=0)
  1350. {
  1351. $album_play[]= 0;
  1352. } // if($flg==0)
  1353. */
  1354. } // foreach($dt as $key => $val)
  1355. } // if($this->Session->read('lastdate')=='y')
  1356. /*
  1357. * Session set to get weekly , monthly & yearly average / Percentage
  1358. */
  1359. $this->Session->write('msviewscount',$msviewscount);
  1360. $this->Session->write('ytviewscount',$ytviewscount);
  1361. $this->Session->write('lfmviewscount',$lfmviewscount);
  1362. /*
  1363. * Session to set Graph data
  1364. */
  1365. $this->Session->write('dt',$dt);
  1366. $this->Session->write('msview',$msview);
  1367. $this->Session->write('ytview',$ytview);
  1368. $this->Session->write('lfmplay',$lfmplay);
  1369. $msaverage = 0;
  1370. $ytaverage = 0;
  1371. $lfmaverage = 0;
  1372. if($this->Session->read('lastdate')=='w')
  1373. {
  1374. $msaverage = round($msviewscount/7,2);
  1375. $ytaverage = round($ytviewscount/7,2);
  1376. $lfmaverage = round($lfmviewscount/7,2);
  1377. }
  1378. elseif($this->Session->read('lastdate')=='m')
  1379. {
  1380. $mm=$this->Session->read('mm');
  1381. $msaverage = round($msviewscount/$mm,2);
  1382. $ytaverage = round($ytviewscount/$mm,2);
  1383. $lfmaverage = round($lfmviewscount/$mm,2);
  1384. }
  1385. elseif($this->Session->read('lastdate')=='y')
  1386. {
  1387. $msaverage = round($msviewscount/12,2);
  1388. $ytaverage = round($ytviewscount/12,2);
  1389. $lfmaverage = round($lfmviewscount/12,2);
  1390. }
  1391. $this->Session->write('msaverage',$msaverage);
  1392. $this->Session->write('ytaverage',$ytaverage);
  1393. $this->Session->write('lfmaverage',$lfmaverage);
  1394. return true;
  1395. } // function viewschart()
  1396. /*
  1397. Name : playschart
  1398. Desc : Get graph values from sessions and display graph
  1399. */
  1400. function playschart()
  1401. {
  1402. $dt = $this->Session->read('dt');
  1403. $msplays = $this->Session->read('msplays');
  1404. $ytplays = $this->Session->read('ytplays');
  1405. $lfmplays = $this->Session->read('lfmplays');
  1406. $this->set('dt',$dt);
  1407. $this->set('msplays',$msplays);
  1408. $this->set('ytplays',$ytplays);
  1409. $this->set('lfmplays',$lfmplays);
  1410. } // function playschart()
  1411. /*
  1412. Name : setplayschart
  1413. Desc : Get graph values and return to plays()
  1414. */
  1415. function setplayschart()
  1416. {
  1417. if($this->Session->check('id') and $this->Session->check('band_id') and $this->Session->check('mssvideo') and $this->Session->check('video') and $this->Session->check('toptrack'))
  1418. {
  1419. $mmm_id = $this->Session->read('id');
  1420. $band_id = $this->Session->read('band_id');
  1421. $mssvideo = addslashes($this->Session->read('mssvideo'));
  1422. $video = addslashes($this->Session->read('video'));
  1423. $lfm_track = addslashes($this->Session->read('toptrack'));
  1424. }
  1425. else
  1426. {
  1427. //$this->Session->setFlash('Session Expired');
  1428. //$this->redirect('/analytics/index/');
  1429. return ;
  1430. } // if($this->Session->check('music') and $this->Session->check('profile') and $this->Session->ch
  1431. $mss= NULL;
  1432. $yt=NULL;
  1433. $album=NULL;
  1434. if($this->Session->read('lastdate')=='w') // weekly graphs quries
  1435. {
  1436. $qry_mss = "select s.plays , s.etime from mss_play_stat s , mss_login l where s.title='$mssvideo' and s.mss_id = l.mss_id and l.band_id=$band_id and l.mmm_id = '$mmm_id' and l.status=1 and FROM_UNIXTIME(s.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1437. $qry_yt = "select y.views plays , y.etime from yt_comments_stat y , yt_login l where title='$video' and y.yt_id = l.yt_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(y.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1438. $qry_lfm = "select t.playcount plays , t.etime from lfm_top_tracks t , lfm_music l where t.name='$lfm_track' and l.lfm_m_id =t.lfm_m_id and l.band_id=$band_id and l.mmm_id='$mmm_id' and l.status=1 and FROM_UNIXTIME(t.etime) between DATE_SUB(CURDATE(), INTERVAL 9 DAY) AND CURDATE( ) order by etime";
  1439. if(!empty($this->params['url']['id']))
  1440. {
  1441. if ($this->Session->check('msp'))
  1442. {
  1443. $mss = $this->Mss->findBySql($qry_mss);
  1444. }
  1445. if ($this->Session->check('ytp'))
  1446. {
  1447. $yt = $this->Ytstat->findBySql($qry_yt);
  1448. }
  1449. if ($this->Session->check('lfmsp'))
  1450. {
  1451. $lfm = $this->Ytstat->findBySql($qry_lfm);
  1452. }
  1453. } // if(!empty($this->params['url']['id']))
  1454. else
  1455. {
  1456. $mss = $this->Mss->findBySql($qry_mss);
  1457. $yt = $this->Ytstat->findBySql($qry_yt);
  1458. $lfm = $this->Ytstat->findBySql($qry_lfm);
  1459. } // if(!empty($this->params['…

Large files files are truncated, but you can click here to view the full file