Bladeren bron

Added Recently watched (history)

Michael Francis 14 jaren geleden
bovenliggende
commit
b8d663bbe7
2 gewijzigde bestanden met toevoegingen van 24 en 1 verwijderingen
  1. 5 1
      controllers/ProfileController.php
  2. 19 0
      models/Profile.php

+ 5 - 1
controllers/ProfileController.php

@@ -2,6 +2,7 @@
 
 namespace app\controllers;
 use app\models\User;
+use app\models\Profile;
 use \lithium\security\Auth;
 
 class ProfileController extends \lithium\action\Controller {
@@ -20,7 +21,9 @@ class ProfileController extends \lithium\action\Controller {
 		
 			$photo = null;
 			$profile = $user->profile; 
-			return compact('user', 'photo', 'profile');
+
+			$history = Profile::history($user->animelist);
+			return compact('user', 'photo', 'profile', 'history');
 		}
 		else
 		{
@@ -33,6 +36,7 @@ class ProfileController extends \lithium\action\Controller {
 		
 	}
 
+
 	public function edit($username)
 	{
 		$user = Auth::check('default');

+ 19 - 0
models/Profile.php

@@ -12,6 +12,25 @@ class Profile extends \lithium\data\Model {
 	public $validates = array(
 		'birthday' => array(array('date'))
 		);
+
+	public static function history($animelist)
+	{
+		
+		$al = $animelist->data();
+		return profile::historySort($al, 'my_finish_date');
+	}
+
+
+	public static function historySort($a,$subkey) {
+		foreach($a as $k=>$v) {
+			$b[$k] = strtolower($v[$subkey]);
+		}
+		arsort($b);
+		foreach($b as $key=>$val) {
+			$c[] = $a[$key];
+		}
+		return $c;
+	}
 }
 
 ?>