Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 25b71ad

Browse files
author
Julien Jomier
committed
ENH: 0009683: Folder download should include community or user
1 parent ee0ab61 commit 25b71ad

File tree

7 files changed

+80
-4
lines changed

7 files changed

+80
-4
lines changed

core/controllers/DownloadController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class DownloadController extends AppController
1717
{
18-
public $_models = array("Folder", 'Item');
18+
public $_models = array('Folder', 'Item', 'Community', 'User');
1919
public $_daos = array();
2020
public $_components = array();
2121

@@ -149,6 +149,22 @@ public function indexAction()
149149
{
150150
$name = $folders[0]->getName();
151151
$name = substr($name, 0, 50);
152+
153+
$rootFolder = $this->Folder->getRoot($folders[0]);
154+
if($rootFolder)
155+
{
156+
// Find the Community or the User which have the folder
157+
$rootCom = $this->Community->getByFolder($rootFolder);
158+
if(!$rootCom)
159+
{
160+
$user = $this->User->getByFolder($rootFolder);
161+
$name = $user->getFirstname().$user->getLastname().'-'.$name;
162+
}
163+
else
164+
{
165+
$name = $rootCom->getName().'-'.$name;
166+
}
167+
}
152168
}
153169
else
154170
{

core/models/base/CommunityModelBase.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ public function __construct()
4646
$this->initialize(); // required
4747
} // end __construct()
4848

49-
/** getPublicCommunities*/
49+
/** Returns all the public communities. Limited to 20 by default. */
5050
abstract function getPublicCommunities($limit = 20);
51-
/** get By Name*/
51+
/** Returns the community given its name */
5252
abstract function getByName($name);
53-
/** get All*/
53+
/** Returns all the communities */
5454
abstract function getAll();
55+
/** Returns a community by its uuid */
5556
abstract function getByUuid($uuid);
57+
/** Returns a community given its folder (either public,private or base folder) */
58+
abstract function getByFolder($folder);
5659

5760
/** save */
5861
public function save($dao)

core/models/base/FolderModelBase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ abstract function removeItem($folder, $item);
5555
abstract function policyCheck($folderDao, $userDao = null, $policy = 0);
5656
abstract function getFolderExists($name, $description);
5757
abstract function getByUuid($uuid);
58+
abstract function getRoot($folder);
5859

5960
/** Increment the view count */
6061
function incrementViewCount($folder)

core/models/base/UserModelBase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ abstract function getByEmail($email);
5151
abstract function getByUser_id($userid);
5252
abstract function getUserCommunities($userDao);
5353
abstract function getByUuid($uuid);
54+
/** Returns a user given its folder (either public,private or base folder) */
55+
abstract function getByFolder($folder);
5456

5557
/** save */
5658
public function save($dao)

core/models/pdo/CommunityModel.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,25 @@ function getByName($name)
3434
return $dao;
3535
} // end getByName()
3636

37+
/** Returns a community given its folder (either public,private or base folder) */
38+
function getByFolder($folder)
39+
{
40+
if(!$folder instanceof FolderDao)
41+
{
42+
throw new Zend_Exception("Should be a folder" );
43+
}
3744

45+
$row = $this->database->fetchRow($this->database->select()->setIntegrityCheck(false)
46+
->from('community')
47+
->where('folder_id=?', $folder->getFolderId())
48+
->orwhere('publicfolder_id=?', $folder->getFolderId())
49+
->orwhere('privatefolder_id=?', $folder->getFolderId())
50+
);
51+
52+
$community = $this->initDao('Community',$row);
53+
return $community;
54+
}
55+
3856
/** Get all */
3957
function getAll()
4058
{

core/models/pdo/FolderModel.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,24 @@ public function getSizeFiltered($folders, $userDao = null, $policy = 0)
189189
return $folders;
190190
}
191191

192+
/** Get the root folder */
193+
function getRoot($folder)
194+
{
195+
if(!$folder instanceof FolderDao)
196+
{
197+
throw new Zend_Exception("Should be a folder" );
198+
}
192199

200+
$row = $this->database->fetchRow($this->database->select()->setIntegrityCheck(false)
201+
->from('folder')
202+
->where('left_indice<?', $folder->getLeftIndice())
203+
->where('right_indice>?', $folder->getRightIndice())
204+
->order('left_indice ASC')
205+
->limit(1));
206+
207+
$root = $this->initDao('Folder',$row);
208+
return $root;
209+
} // end getRoot()
193210

194211
/** Get the folder tree */
195212
function getAllChildren($folder, $userDao)

core/models/pdo/UserModel.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ public function getUserCommunities($userDao)
7474
return $return;
7575
} // end getUserCommunities
7676

77+
/** Returns a user given its folder (either public,private or base folder) */
78+
function getByFolder($folder)
79+
{
80+
if(!$folder instanceof FolderDao)
81+
{
82+
throw new Zend_Exception("Should be a folder" );
83+
}
84+
85+
$row = $this->database->fetchRow($this->database->select()->setIntegrityCheck(false)
86+
->from('user')
87+
->where('folder_id=?', $folder->getFolderId())
88+
->orwhere('publicfolder_id=?', $folder->getFolderId())
89+
->orwhere('privatefolder_id=?', $folder->getFolderId())
90+
);
91+
92+
$user = $this->initDao('User',$row);
93+
return $user;
94+
}
95+
7796
/** Return a list of users corresponding to the search */
7897
function getUsersFromSearch($search, $userDao, $limit = 14, $group = true, $order = 'view')
7998
{

0 commit comments

Comments
 (0)