Permalink
Browse files

Pluralize model to follow Lithium's conventions

  • Loading branch information...
1 parent 9d86c1a commit 4e1b7dba1ad094b1d9544976ce2369961424ffa4 @mehlah mehlah committed with mehlah Jun 19, 2012
@@ -17,7 +17,7 @@
Connections::add('test', array(
'adapter' => 'MongoDb',
'host' => 'localhost',
- 'database' => 'test'
+ 'database' => 'lithosphere_test'
));
Connections::add('li3_users', array(
@@ -2,7 +2,7 @@
namespace app\controllers;
-use app\models\Post;
+use app\models\Posts;
use lithium\storage\Session;
class PostsController extends \lithium\action\Controller {
@@ -15,7 +15,7 @@ public function add() {
}
$errors = false;
if (!empty($this->request->data)) {
- $post = Post::create($this->request->data);
+ $post = Posts::create($this->request->data);
if ($post->save()) {
return $this->redirect(array(
'controller' => 'posts', 'action' => 'comment',
@@ -26,20 +26,19 @@ public function add() {
}
}
if (empty($post)) {
- $post = Post::create();
+ $post = Posts::create();
}
- $tags = Post::$tags;
+ $tags = Posts::$tags;
return compact('post','tags','errors');
}
public function comment() {
$user = Session::read('user', array('name' => 'li3_user'));
- $post = Post::first($this->request->params['_id']);
+ $post = Posts::first($this->request->params['_id']);
if (empty($post)) {
return $this->redirect(array('controller' => 'posts', 'action' => 'index'));
}
- //print_r($post->data()); die();
$endorsed =
($user['_id'] == $post->user_id) ||
@@ -72,7 +71,7 @@ public function endorse($_id = null) {
));
}
- $post = Post::first($_id);
+ $post = Posts::first($_id);
if (empty($post)) {
return $this->redirect(array('controller' => 'posts', 'action' => 'index'));
}
@@ -86,7 +85,7 @@ public function endorse($_id = null) {
}
public function edit($_id = null) {
- $post = Post::find($_id);
+ $post = Posts::find($_id);
if (empty($post)) {
return $this->redirect(array('controller' => 'posts', 'action' => 'index'));
}
@@ -2,7 +2,7 @@
namespace app\controllers;
-use app\models\Post;
+use app\models\Posts;
class SearchController extends \lithium\action\Controller {
@@ -28,8 +28,8 @@ public function index() {
$limit = $this->_limit;
$offset = ($page - 1) * $limit;
- $count = Post::find('count', compact('conditions'));
- $results = Post::find('all', compact('conditions','limit','offset'));
+ $count = Posts::find('count', compact('conditions'));
+ $results = Posts::find('all', compact('conditions','limit','offset'));
$url = $this->request->params + $data;
return compact('q','results','count','url','page','limit');
@@ -88,8 +88,8 @@ public function filter() {
$limit = $this->_limit;
$offset = ($page - 1) * $limit;
- $count = Post::find('count', compact('conditions'));
- $results = Post::find('all', compact('conditions','order','offset','limit'));
+ $count = Posts::find('count', compact('conditions'));
+ $results = Posts::find('all', compact('conditions','order','offset','limit'));
$url = $this->request->params;
@@ -117,8 +117,8 @@ public function latest() {
$limit = $this->_limit;
$offset = ($page - 1) * $limit;
- $count = Post::find('count', compact('conditions'));
- $results = Post::find('all', compact('conditions', 'order','offset','limit'));
+ $count = Posts::find('count', compact('conditions'));
+ $results = Posts::find('all', compact('conditions', 'order','offset','limit'));
return compact('results','count','url','page','limit');
}
@@ -42,7 +42,7 @@ public function row($post, $options = array()) {
$category = null;
if (!empty($post->tags)) {
foreach ($post->tags as $tag) {
- if (!in_array($tag, \app\models\Post::$tags)) {
+ if (!in_array($tag, \app\models\Posts::$tags)) {
continue;
}
$category = $tag;
@@ -118,7 +118,7 @@ public function tag($tag, $options = array()) {
$title = String::insert($title, compact('tag'));
$url = array('controller' => 'search', 'action' => 'filter') + compact('tag');
- if (in_array($tag, \app\models\Post::$tags)) {
+ if (in_array($tag, \app\models\Posts::$tags)) {
$url = $tag;
}
$html = $this->_context->helper('html');
@@ -19,7 +19,7 @@
)
),
'adapter' => 'Form',
- 'model' => '\li3_users\models\User',
+ 'model' => '\li3_users\models\Users',
'fields' => array('_id', 'password'),
'validators' => array(
'password' => function($submitted, $actual) {
@@ -8,7 +8,7 @@
namespace li3_users\controllers;
-use li3_users\models\User;
+use li3_users\models\Users;
use lithium\security\Auth;
use lithium\storage\Session;
use li3_swiftmailer\mailer\Transports;
@@ -22,7 +22,7 @@ class UsersController extends \lithium\action\Controller {
protected $_cooldown = 6;
public function index() {
- $users = User::all();
+ $users = Users::all();
return compact('users');
}
@@ -70,14 +70,14 @@ public function logout() {
}
public function view($_id = null) {
- $user = User::find($_id);
+ $user = Users::find($_id);
return compact('user');
}
public function register() {
$errors = false;
if (!empty($this->request->data)) {
- $user = User::create($this->request->data);
+ $user = Users::create($this->request->data);
if ($user->save()) {
Session::write('attempts', 0, array('name' => 'cooldown'));
return $this->redirect(array(
@@ -87,13 +87,13 @@ public function register() {
$errors = $user->errors();
}
if (empty($user)) {
- $user = User::create();
+ $user = Users::create();
}
return compact('user', 'errors');
}
public function edit($_id = null) {
- $user = User::find($_id);
+ $user = Users::find($_id);
if (empty($user)) {
$this->redirect(array('controller' => 'users', 'action' => 'index'));
}
@@ -127,8 +127,8 @@ public function reset($token = null) {
$title = "update your password";
if (!empty($this->request->data['_id']) && !empty($this->request->data['password'])) {
$_id = $this->request->data['_id'];
- if (User::reset(compact('token','_id'))) {
- $user = User::first($this->request->data['_id']);
+ if (Users::reset(compact('token','_id'))) {
+ $user = Users::first($this->request->data['_id']);
$user->set(array('password' => $this->request->data['password']));
$success = $user->save();
$title = 'password updated!';
@@ -149,7 +149,7 @@ public function reset($token = null) {
}
if (empty($token) && !empty($this->request->data['_id'])) {
- if ($user = User::first($this->request->data['_id'])) {
+ if ($user = Users::first($this->request->data['_id'])) {
$user->token();
if ($this->_emailToken($user->data())) {
$emailed = true;
@@ -21,12 +21,12 @@
}
$conditions['_id'] = array('$ne' => $options['values']['_id']);
}
- return !(boolean) User::find('count', compact('conditions'));
+ return !(boolean) Users::find('count', compact('conditions'));
}
return false;
});
-class User extends \lithium\data\Model {
+class Users extends \lithium\data\Model {
protected $_meta = array(
'key' => '_id',
@@ -11,7 +11,7 @@
use lithium\data\Connections;
use lithium\data\model\Query;
-class User extends \li3_users\models\User {
+class Users extends \li3_users\models\Users {
protected $_meta = array(
'key' => '_id',
@@ -26,12 +26,12 @@ class User extends \li3_users\models\User {
}
-class UserTest extends \lithium\test\Unit {
+class UsersTest extends \lithium\test\Unit {
public function setUp() {}
public function tearDown() {
- User::find('all')->each(function($i) {
+ Users::find('all')->each(function($i) {
$i->delete();
});
}
@@ -42,7 +42,7 @@ public function testToken() {
'email' => 'user@example.com',
'password' => 'my_password'
);
- $user = User::create();
+ $user = Users::create();
$user->save($data);
$this->assertTrue(empty($user->token));
@@ -74,28 +74,28 @@ public function testReset() {
'password' => 'my_password'
);
- $result = User::reset();
+ $result = Users::reset();
$expected = false;
$this->assertEqual($expected, $result);
- $user = User::create();
+ $user = Users::create();
$user->save($data);
$token = $user->token();
- $result = User::reset(compact('token'));
+ $result = Users::reset(compact('token'));
$this->assertFalse($result);
$_id = $data['_id'];
- $result = User::reset(compact('_id'));
+ $result = Users::reset(compact('_id'));
$this->assertFalse($result);
- $result = User::reset(compact('token','_id'));
+ $result = Users::reset(compact('token','_id'));
$this->assertTrue($result);
$token = $user->token(strtotime('-15 minutes'));
- $result = User::reset(compact('token','_id'));
+ $result = Users::reset(compact('token','_id'));
$this->assertFalse($result);
}
@@ -2,7 +2,7 @@
namespace app\models;
-class Comment extends \lithium\data\Model {
+class Comments extends \lithium\data\Model {
public $validates = array(
'content' => array('notEmpty', 'message' => 'Please supply some content.'),
@@ -2,7 +2,7 @@
namespace app\models;
-class Post extends \lithium\data\Model {
+class Posts extends \lithium\data\Model {
public $validates = array(
'title' => array('notEmpty', 'message' => 'Please supply a title.'),
@@ -54,8 +54,8 @@ class Post extends \lithium\data\Model {
'inflector' => 'lithium\util\Inflector',
'set' => 'lithium\data\collection\DocumentSet',
'session' => 'lithium\storage\Session',
- 'user' => 'li3_users\models\User',
- 'comment' => 'app\models\Comment',
+ 'users' => 'li3_users\models\Users',
+ 'comments' => 'app\models\Comments',
);
public static function __init(array $options = array()) {
@@ -115,7 +115,7 @@ public static function __init(array $options = array()) {
if (!empty($result->comments)) {
$comments = new $classes['set'](array(
'data' => $result->comments->data(),
- 'model' => $classes['comment']
+ 'model' => $classes['comments']
));
$result->set(compact('comments'));
}
@@ -127,7 +127,7 @@ public function user($record) {
if (!empty($record->_user)) {
return $record->_user;
}
- $user = static::$_classes['user'];
+ $user = static::$_classes['users'];
return $record->_user = $user::find($record->user_id);
}
@@ -136,7 +136,7 @@ public function comment($record, $params = array()) {
$params += $default;
extract($params);
- $comment = static::$_classes['comment'];
+ $comment = static::$_classes['comments'];
$comment = $comment::create($data);
if (empty($record->_id) || !$comment->save()) {
@@ -231,7 +231,7 @@ public function comments($record) {
if (!empty($record->comments)) {
$comments = new $set(array(
'data' => $record->comments->data(),
- 'model' => 'app\models\Comment',
+ 'model' => 'app\models\Comments',
));
}
return $comments;
@@ -3,7 +3,7 @@
namespace app\tests\cases\extensions\helper;
use \app\extensions\helper\Thread;
-use \lithium\data\collection\Document;
+use \lithium\data\collection\DocumentSet as Document;
use \lithium\net\http\Router;
class ThreadTest extends \lithium\test\Unit {
@@ -38,7 +38,7 @@ public function testComments() {
)
);
- $document = new Document(array('items' => $data, 'model' => '\app\models\Post'));
+ $document = new Document(array('items' => $data, 'model' => '\app\models\Posts'));
$result = $thread->comments($document);
$this->assertNull($result);
@@ -59,7 +59,7 @@ public function testComments() {
)
);
- $document = new Document(array('items' => $data, 'model' => '\app\models\Post'));
+ $document = new Document(array('items' => $data, 'model' => '\app\models\Posts'));
$result = $thread->comments($document);
$this->assertTrue(!empty($result));
}
Oops, something went wrong.

0 comments on commit 4e1b7db

Please sign in to comment.