Commits

christiansalazar committed 51b20e4

can_read

  • Participants
  • Parent commits cbd580b

Comments (0)

Files changed (3)

File IYiiFileManager.php

 	public function remove_files($id, $file_id, $extra=array());
 	public function get_file_path($id, $file_id, $extra=array());
 	public function get_file_info($id, $file_id, $extra=array());
+	public function can_read($id, $file_id, $extra=array());
 
 	function on_file($id, $file_id, $file_path, $extra=array());
 	function get_file_list($id, $extra=array());
 
 	Register the fileman component into your config file.
 
+~~~
+[php]
+
 	'import'=>array(
 		...bla...
 		'application.extensions.yiifileman.*',  // <<--HERE
 			'storage_path' => "/var/tmp/fileman",
 	),
 
+~~~
 
 ### Basic yii File Manager operations
 
+~~~
+
+[php]
+
+
 	$identity = Yii::app()->user->id; // or any IDentificator.
 
 	// ADD FILES
 	$real_path = Yii::app()->fileman->get_file_path($id, "18aac1a12");
 	// ..do what ever you want with this file...
 	printf("the real local path is: %s\n",$real_path);
-	
+
+	// QUERY IF THE GIVEN USER ID CAN READ A FILE USING ITS FILE_ID
+	//
+	$bool = Yii::app()->fileman->can_read(Yii::app()->user->id, "188abc123");
+
 	// REMOVE FILES
 	//   using the file_id provided when calling list_files()
 	Yii::app()->fileman->remove_file($identity, "18ac11981");
 	Yii::app()->fileman->remove_file($identity, array("288abc12","2029acb12"));
 
+~~~
+
 ### Yii File Manager Class Diagram
 
 ![Class Diagram][1]
 	# cd protected
 	# ./yiic fileman
 
+
 ~~~	
 
+
+~~~
+[php]
+
 	<?php
 	// save as:
 	//		protected/commands/FilemanCommand.php	
-	//
 	class FilemanCommand extends CConsoleCommand {
-		public function actionIndex($cmd='list',$fileids=''){
+		public function actionIndex($cmd='list',$fileids='',$id=''){
 			$id = "MYID";
 			printf("\nFileman tester. ID=%s\n",$id);
 			printf("usage:\n");
 			printf("	--cmd=list\n");
 			printf("	--cmd=rem --fileids=129819,129982\n");
 			printf("	--cmd=path --fileids=129819\n");
+			printf("	--cmd=canread --id=123456 --fileids=129819,119891\n");
 			printf("\n");
 			if($cmd=='add'){
 				// ADD
 				//
-				$file_ids = Yii::app()->fileman->add_files($id,	
-					array("/var/tmp/file1","/var/tmp/file2"));		<---  PUT SOME FILES HERE
-
+				$file_ids = Yii::app()->fileman->add_files($id,
+					array("/var/tmp/h2","/var/tmp/x")// <<<--- PUT SOME REAL FILES HERE
+				);
 				foreach($file_ids as $file_id)
 					printf("add_files -> file_id: %s\n",$file_id);
 			}elseif($cmd=='list'){
 				}
 				else
 					printf("file not found\d");
+			}elseif($cmd=='canread'){
+				if(($fileids == '') || ($id == '')){
+					printf("usage: fileman --cmd=canread --id=123456 --fileids=129812,198928\n");
+				}else{
+					$ar = explode(",",$fileids);
+					foreach($ar as $file_id)
+						printf("can_read %s: %s\n",
+							$file_id,
+							Yii::app()->fileman->can_read($id,$file_id) ? "YES" : "NO");
+				}
 			}
 		}
+
 	}
 
+~~~
+
 [1]:https://bitbucket.org/christiansalazarh/yiifilemanager/downloads/fileman-class-diagram.png

File YiiDiskFileManager.php

 class YiiDiskFileManager extends YiiBaseFileManager {
 	public $storage_path;
 
+
+	/**
+    	query if the given ID (identitity) -can read- the given file -file_id-
+
+    	by default, this implementation returns TRUE only if the given ID
+    	is the same as the file_id repo owner.
+
+    	@return bool true|false
+     */
+    public function can_read($id, $file_id, $extra=array()){
+		return (parent::get_file_info($id, $file_id) != null);
+    }
+
 	private function get_storage_path($id){
 		$local_path = rtrim(trim($this->storage_path),"/");
 		@mkdir($local_path);