summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorMichael Francis <edude03@gmail.com>2011-07-16 00:50:36 -0400
committerMichael Francis <edude03@gmail.com>2011-07-16 00:54:38 -0400
commitfda3b17b032b67e0ccfbaa3aa6ec6e4ee5a17f70 (patch)
tree5d4fbd461bc1fb2716f0fa9fa6c1458cf6f816f8 /models
parenta277c978e66c970231b3cf987d220f3476fe456e (diff)
downloadotakuhub-fda3b17b032b67e0ccfbaa3aa6ec6e4ee5a17f70.tar.xz
Implemented mySQL based friending
Diffstat (limited to 'models')
-rw-r--r--models/Friends.php32
-rw-r--r--models/User.php23
2 files changed, 36 insertions, 19 deletions
diff --git a/models/Friends.php b/models/Friends.php
new file mode 100644
index 0000000..67d747a
--- /dev/null
+++ b/models/Friends.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace app\models;
+
+class Friends extends \lithium\data\Model {
+
+ public $validates = array();
+ public $belongsTo = array('User' => array('keys' => array('FromUserId' => 'id')));
+
+ /**
+ * Returns the opposite value of whatever is passed in (like an enum)
+ * @param Mixed $input
+ * @return String or Int;
+ */
+ public static function status($input) {
+ if (is_int($input)) {
+ switch($input) {
+ case "rejected": return 0;
+ case "accepted": return 1;
+ case "open": return 2;
+ }
+ }
+ else {
+ switch($input) {
+ case 0: return "rejected";
+ case 1: return "accepted";
+ case 2: return "open";
+ }
+ }
+ }
+}
+?> \ No newline at end of file
diff --git a/models/User.php b/models/User.php
index cacda49..6bfa423 100644
--- a/models/User.php
+++ b/models/User.php
@@ -10,7 +10,7 @@ use \lithium\security\Password;
class User extends \lithium\data\Model {
- public $hasMany = array('Post');
+ public $hasMany = array('Post', 'Friends' => array('keys' => array('id' => 'ToUserId')));
public static function __init()
{
@@ -223,27 +223,12 @@ class User extends \lithium\data\Model {
return $posts;
}
- /**
- * Increments the amount profile views for the user.
- * This is the command we are going to give to Mongo, which breaks down to db.users.update({_id : $id}, {$inc: {profileViews : 1}} )
- * Which says, find the user by their mongo ID, then increment their profile views by one.
- * @param User $entity The instance of user to increment
- * @param string $type Not implemented but in the future will allow you to increment anime manga and kdrama list views :TODO:
- * @return null
- */
- public function incrementViews($entity, $type = null)
+ public function myFriends($entity)
{
- if ($type = null)
- {
- $views = 'profileViews';
- }
- $updateData = array('$inc' => array('profileViews' => 1));
- $conditions = array('_id' => $entity['_id']);
- $result = User::update($updateData, $conditions, array('atomic' => false));
- return $result;
+ return self::find(array('conditions' => array('id' => $entity->friends->map(function ($f) { return $f->FromUserId;}))));
+ //return static::FindAllById($entity->friends->map(function ($f) { return $f->FromUserId; }));
}
-
//Overrides save so we can do some stuff before the data is commited to the database.
public function save($entity, $data = null, array $options = array())
{