Guest User

Untitled

a guest
Jun 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. <?php
  2. class chartsController extends AppController {
  3.  
  4. var $name = 'charts';
  5. var $helpers = array('Form', 'Html', 'Javascript', 'Time', 'Session');
  6.  
  7. var $components = array('Auth');
  8.  
  9.  
  10. function index() {
  11. $this->set('charts', $this->Chart->find('all' ));
  12. }
  13.  
  14. function view($id) {
  15.  
  16. $this->Chart->id = $id;
  17. $this->Chart->read();
  18. // $charts = $this->Chart->find('all', 'conditions'=> array('ChartsRack.chart_id='.$id) );
  19. //$this->set('chart', $charts);
  20.  
  21. $listings = $this->Chart->ChartItem->find('all', array('contain'=>array('Chart', 'Rack'), 'conditions' => array('ChartItem.chart_id' => $id), 'order' => array('ChartItem.position' => 'ASC')));
  22.  
  23. debug($listings);
  24.  
  25. $this->set('listings', $listings);
  26.  
  27.  
  28. }
  29.  
  30.  
  31. function search(){
  32.  
  33. if($this->data){
  34.  
  35. $likestart ='`id` LIKE \'%\' ';
  36. $likebuild = $likestart;
  37.  
  38. if($this->data['Chart']['whoCreated'] != "" ){
  39.  
  40. $likebuild = $likestart. 'AND Chart.spot LIKE "%' . $this->data['Chart']['spot'] .'%"';
  41.  
  42. }
  43.  
  44. if($this->data['Chart']['name'] != "" ){
  45.  
  46. $likebuild = $likebuild . 'AND Chart.artist LIKE "%' . $this->data['Chart']['artist'] .'%"';
  47.  
  48. }
  49.  
  50.  
  51. $this->set('charts', $this->Chart->find('all', array('conditions' => array($likebuild) ) ));
  52. $this->render('results');
  53.  
  54. }
  55.  
  56. else{
  57. $this->render('search');
  58. }
  59. }
  60.  
  61. function add() {
  62. if (!empty($this->data)) {
  63.  
  64. if ($this->Chart->save($this->data)) {
  65. $this->redirect('/charts');
  66. //$this->Session->write('Chart', $Chart);
  67. }
  68.  
  69. else{
  70. //debug( $this->Chart->validationErrors );
  71. }
  72. }
  73. }
  74.  
  75. function delete($id) {
  76. $this->Chart->del($id);
  77. $this->Session->setFlash('The Chart with id: '.$id.' has been deleted.');
  78. $this->redirect(array('action'=>'index'));
  79. }
  80.  
  81.  
  82. function edit($id = null) {
  83. $this->Chart->id = $id;
  84. if(!$this->Auth->User() or !$this->Chart->exists()){
  85. $this->redirect('/charts');
  86. }
  87.  
  88. if (!empty($this->data)) {
  89.  
  90. $this->Chart->save( $this->data['Chart'] );
  91. }
  92. else{
  93.  
  94. }
  95. //echo("success");
  96.  
  97. /* else {
  98. //$this->data = $this->Chart->read(array('', 'first_name', 'last_name', 'e_mail'));
  99.  
  100. }*/
  101. }
  102.  
  103.  
  104. function beforeFilter(){
  105.  
  106.  
  107. $this->layout = 'general';
  108.  
  109.  
  110. $this->Auth->allow('view', 'index', 'search');
  111.  
  112. if($this->Auth->user()){
  113. $this->Auth->allow = array('add', 'edit');
  114. }
  115.  
  116. $this->Auth->deny('delete');
  117.  
  118. }
  119.  
  120. }
Add Comment
Please, Sign In to add comment