Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class chartsController extends AppController {
- var $name = 'charts';
- var $helpers = array('Form', 'Html', 'Javascript', 'Time', 'Session');
- var $components = array('Auth');
- function index() {
- $this->set('charts', $this->Chart->find('all' ));
- }
- function view($id) {
- $this->Chart->id = $id;
- $this->Chart->read();
- // $charts = $this->Chart->find('all', 'conditions'=> array('ChartsRack.chart_id='.$id) );
- //$this->set('chart', $charts);
- $listings = $this->Chart->ChartItem->find('all', array('contain'=>array('Chart', 'Rack'), 'conditions' => array('ChartItem.chart_id' => $id), 'order' => array('ChartItem.position' => 'ASC')));
- debug($listings);
- $this->set('listings', $listings);
- }
- function search(){
- if($this->data){
- $likestart ='`id` LIKE \'%\' ';
- $likebuild = $likestart;
- if($this->data['Chart']['whoCreated'] != "" ){
- $likebuild = $likestart. 'AND Chart.spot LIKE "%' . $this->data['Chart']['spot'] .'%"';
- }
- if($this->data['Chart']['name'] != "" ){
- $likebuild = $likebuild . 'AND Chart.artist LIKE "%' . $this->data['Chart']['artist'] .'%"';
- }
- $this->set('charts', $this->Chart->find('all', array('conditions' => array($likebuild) ) ));
- $this->render('results');
- }
- else{
- $this->render('search');
- }
- }
- function add() {
- if (!empty($this->data)) {
- if ($this->Chart->save($this->data)) {
- $this->redirect('/charts');
- //$this->Session->write('Chart', $Chart);
- }
- else{
- //debug( $this->Chart->validationErrors );
- }
- }
- }
- function delete($id) {
- $this->Chart->del($id);
- $this->Session->setFlash('The Chart with id: '.$id.' has been deleted.');
- $this->redirect(array('action'=>'index'));
- }
- function edit($id = null) {
- $this->Chart->id = $id;
- if(!$this->Auth->User() or !$this->Chart->exists()){
- $this->redirect('/charts');
- }
- if (!empty($this->data)) {
- $this->Chart->save( $this->data['Chart'] );
- }
- else{
- }
- //echo("success");
- /* else {
- //$this->data = $this->Chart->read(array('', 'first_name', 'last_name', 'e_mail'));
- }*/
- }
- function beforeFilter(){
- $this->layout = 'general';
- $this->Auth->allow('view', 'index', 'search');
- if($this->Auth->user()){
- $this->Auth->allow = array('add', 'edit');
- }
- $this->Auth->deny('delete');
- }
- }
Add Comment
Please, Sign In to add comment