OSDN Git Service

Owner, PublicFlagチェックをCorePlusに移動
authorCake <cake_67@users.sourceforge.jp>
Sat, 22 May 2010 11:48:43 +0000 (20:48 +0900)
committerCake <cake_67@users.sourceforge.jp>
Sat, 22 May 2010 11:48:43 +0000 (20:48 +0900)
app/controllers/app_controller.php
app/libs/core_plus.php

index cb4504d..f163ad3 100644 (file)
@@ -178,19 +178,11 @@ class AppController extends Controller
        }
        function check_public_flag($data, $key = null)
        {
-               if ($this->isOwner($data, $this->user_id)) {
-                       return true;
-               }
-
-               return $this->check_public_flag2($data, $key);
+               return CorePlus::check_public_flag($data, $key);
        }
        function check_public_flag2($data, $key = null)
        {
-               if ($data['public_flag'] == 'public') {
-                       return true;
-               }
-
-               return false;
+               return CorePlus::check_public_flag2($data, $key);
        }
 
        /* status設定をview用にセット */
@@ -214,17 +206,7 @@ class AppController extends Controller
        /* isOwner */
        function isOwner($data, $user_id)
        {
-               if (!$user_id) {
-                       return false;
-               }
-               if (!isset($data['user_id']) || !$data['user_id']) {
-                       return false;
-               }
-               if ($data['user_id'] == $user_id) {
-                       return true;
-               }
-
-               return false;
+               return CorePlus::isOwner($data, $user_id);
        }
 
        /* ユーザ情報取得 */
index d405cf5..f77e0cc 100644 (file)
@@ -8,6 +8,47 @@ class CorePlus extends Object {
        var $models = array();
        var $behavoirs = array();
 
+       /* isOwner */
+       function isOwner($data, $user_id)
+       {
+               if (!$user_id) {
+                       return false;
+               }
+               if (!isset($data['user_id']) || !$data['user_id']) {
+                       return false;
+               }
+               if ($data['user_id'] == $user_id) {
+                       return true;
+               }
+
+               return false;
+       }
+
+       // public_flagチェック
+       function check_public_flag($data, $key = null)
+       {
+               $userid = null;
+               if (isset($this->user_id)) {
+                       $userid = $this->user_id;
+               } elseif (isset($user['User']['id'])) {
+                       $userid = $user['User']['id'];
+               }
+               if (self::isOwner($data, $userid)) {
+                       return true;
+               }
+
+               return self::check_public_flag2($data, $key);
+       }
+       function check_public_flag2($data, $key = null)
+       {
+               if ($data['public_flag'] == 'public') {
+                       return true;
+               }
+
+               return false;
+       }
+
+
        // $value[$key]が存在しかつ空ではない場合、値を返す
        function get_value($value, $key)
        {