Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (45 sloc) 1.379 kb
<?php
namespace app\controllers;
use app\models\Ideas;
use app\models\Tweets;
class IdeasController extends \lithium\action\Controller {
protected $_admins = array('gwoo' => true);
public function index() {
$latest = Ideas::all(array('order' => array('date' => 'desc')));
$popular = Ideas::all(array('order' => array('score' => 'desc')));
$tweets = Tweets::search(array('q' => '#phpneeds', 'rpp' => 100));
return compact('latest', 'popular', 'tweets');
}
public function add() {
if (!$this->request->user) {
return $this->redirect('Login::index');
}
$idea = Ideas::create();
$idea->user = $this->request->user;
$idea->date = time();
if (($this->request->data) && $idea->save($this->request->data)) {
return $this->redirect(array('Ideas::index'));
}
return compact('idea');
}
public function vote() {
if (!$this->request->user) {
return $this->redirect('Login::index');
}
$idea = Ideas::find($this->request->id);
if ($idea->hasVoted($this->request->user)) {
return $this->redirect('Ideas::index');
}
if ($idea && $idea->vote($this->request->user)) {
//success maaybe flash a message
}
return $this->redirect('Ideas::index');
}
public function delete() {
if (isset($this->_admins[$this->request->user])) {
Ideas::find($this->request->id)->delete();
}
return $this->redirect('Ideas::index');
}
}
?>
Jump to Line
Something went wrong with that request. Please try again.