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

Commit

Permalink
ENH: Added move item, delete folder, create folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Marion committed Apr 11, 2011
1 parent 9b7eed6 commit bcf0461
Show file tree
Hide file tree
Showing 48 changed files with 2,066 additions and 220 deletions.
15 changes: 12 additions & 3 deletions core/AppController.php
Expand Up @@ -27,8 +27,8 @@ public function preDispatch()
//Init Session
if($fc->getRequest()->getActionName()!='login'||$fc->getRequest()->getControllerName()!='user')
{
Zend_Loader::loadClass( "UserDao", BASE_PATH . '/core/models/dao');
Zend_Loader::loadClass( "ItemDao", BASE_PATH . '/core/models/dao');
require_once BASE_PATH . '/core/models/dao/UserDao.php';
require_once BASE_PATH . '/core/models/dao/ItemDao.php';

if (isset($_POST['sid']))
{
Expand All @@ -44,7 +44,7 @@ public function preDispatch()
$this->logged=true;
$this->view->logged=true;
$this->view->userDao=$user->Dao;
$cookieData = $this->getRequest()->getCookie('recentItems'.$this->userSession->Dao->getKey());
$cookieData = $this->getRequest()->getCookie('recentItems'.$this->userSession->Dao->user_id);
$this->view->recentItems=array();
if(isset($cookieData))
{
Expand All @@ -70,6 +70,7 @@ public function preDispatch()
"webroot"=>$this->view->webroot,
"coreWebroot"=>$this->view->coreWebroot,
"logged"=>$this->logged,
"needToLog"=>false,
"currentUri"=>$this->getRequest()->REQUEST_URI,
"lang"=>Zend_Registry::get('configGlobal')->application->lang,
"Yes"=>$this->t('Yes'),
Expand All @@ -82,11 +83,13 @@ public function preDispatch()

$browse=array(
'view'=>$this->t('View'),
'createFolder'=>$this->t('Create a new Folder'),
'preview'=>$this->t('Preview'),
'download'=>$this->t('Download'),
'manage'=>$this->t('Manage'),
'edit'=>$this->t('Edit'),
'delete'=>$this->t('Delete'),
'deleteMessage'=>$this->t('Do you really want to delete the folder'),
'share'=>$this->t('Share'),
'rename'=>$this->t('Rename'),
'move'=>$this->t('Move'),
Expand Down Expand Up @@ -120,6 +123,12 @@ public function postDispatch()
}
}

public function haveToBeLogged()
{
$this->view->header=$this->t("You should be logged to access this page");
$this->view->json['global']['needToLog']=true;
$this->_helper->viewRenderer->setNoRender();
}
/** translation */
protected function t($text)
{
Expand Down
17 changes: 16 additions & 1 deletion core/controllers/BrowseController.php
Expand Up @@ -60,6 +60,7 @@ public function movecopyAction()
{
$elements=explode(';',$this->_getParam('elements'));
$destination=$this->_getParam('destination');
$ajax=$this->_getParam('ajax');
$folderIds=explode('-',$elements[0]);
$itemIds=explode('-',$elements[1]);
$folders= $this->Folder->load($folderIds);
Expand Down Expand Up @@ -94,9 +95,23 @@ public function movecopyAction()
}
else
{
//TODO move
$from=$this->_getParam('from');
$from=$this->Folder->load($from);
if($destination==false)
{
throw new Zend_Exception("Unable to load destination");
}
$this->Folder->addItem($destination,$item);
$this->Folder->removeItem($from, $item);
}
}
if(isset($ajax))
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
echo JsonComponent::encode(array(true,$this->t('Changes saved')));
return;
}
$this->_redirect ('/folder/'.$destination->getKey());
}

Expand Down
186 changes: 182 additions & 4 deletions core/controllers/CommunityController.php
Expand Up @@ -17,7 +17,188 @@ function init()
$this->_forward('view',null,null,array('communityId'=>$actionName));
}
} // end init()

/*manage community*/
function manageAction()
{
if(!$this->logged)
{
$this->haveToBeLogged();
return false;
}

$communityId=$this->_getParam("communityId");
if(!isset($communityId) || (!is_numeric($communityId) && strlen($communityId)!=32)) // This is tricky! and for Cassandra for now
{
throw new Zend_Exception("Community ID should be a number");
}
$communityDao=$this->Community->load($communityId);
if($communityDao===false||!$this->Community->policyCheck($communityDao, $this->userSession->Dao,MIDAS_POLICY_WRITE))
{
throw new Zend_Exception("This community doesn't exist or you don't have the permissions.");
}

$formInfo=$this->Form->Community->createCreateForm();
$formCreateGroup=$this->Form->Community->createCreateGroupForm();

//ajax posts
if($this->_request->isPost())
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$modifyInfo=$this->_getParam('modifyInfo');
$editGroup=$this->_getParam('editGroup');
$deleteGroup=$this->_getParam('deleteGroup');
$addUser=$this->_getParam('addUser');
$removeUser=$this->_getParam('removeUser');
if(isset($removeUser)) //remove users from group
{
$group=$this->Group->load($this->_getParam('groupId'));
if($group==false||$group->getCommunity()->getKey()!=$communityDao->getKey())
{
echo JsonComponent::encode(array(false,$this->t('Error')));
}
else
{
$users=explode('-', $this->_getParam('users'));
$usersDao=$this->User->load($users);
foreach ($usersDao as $userDao)
{
$this->Group->removeUser($group, $userDao);
}
echo JsonComponent::encode(array(true,$this->t('Changes saved')));
}
}
if(isset($addUser)) //add users to group
{
$group=$this->Group->load($this->_getParam('groupId'));
if($group==false||$group->getCommunity()->getKey()!=$communityDao->getKey())
{
echo JsonComponent::encode(array(false,$this->t('Error')));
}
else
{
$users=explode('-', $this->_getParam('users'));
$usersDao=$this->User->load($users);
foreach ($usersDao as $userDao)
{
$this->Group->addUser($group, $userDao);
}
echo JsonComponent::encode(array(true,$this->t('Changes saved')));
}
}
if(isset($modifyInfo))
{
if($formInfo->isValid($_POST))
{
$communityDao=$this->Community->load($communityDao->getKey());
$communityDao->setName($formInfo->getValue('name'));
$communityDao->setDescription($formInfo->getValue('description'));
$communityDao->setPrivacy($formInfo->getValue('privacy'));
$this->Community->save($communityDao);
echo JsonComponent::encode(array(true,$this->t('Changes saved'),$formInfo->getValue('name')));
}
else
{
echo JsonComponent::encode(array(false,$this->t('Error')));
}
}
if(isset($editGroup))
{
if($formCreateGroup->isValid($_POST))
{
if($this->_getParam('groupId')==0)
{
$new_group=$this->Group->createGroup($communityDao,$formCreateGroup->getValue('name'));
echo JsonComponent::encode(array(true,$this->t('Changes saved'),$new_group->_toArray()));
}
else
{
$group=$this->Group->load($this->_getParam('groupId'));
if($group==false||$group->getCommunity()->getKey()!=$communityDao->getKey())
{
echo JsonComponent::encode(array(false,$this->t('Error')));
}
$group->setName($formCreateGroup->getValue('name'));
$this->Group->save($group);
echo JsonComponent::encode(array(true,$this->t('Changes saved'),$group->_toArray()));
}
}
else
{
echo JsonComponent::encode(array(false,$this->t('Error')));
}
}

if(isset($deleteGroup))
{
$group=$this->Group->load($this->_getParam('groupId'));
if($group==false||$group->getCommunity()->getKey()!=$communityDao->getKey())
{
echo JsonComponent::encode(array(false,$this->t('Error')));
}
else
{
$this->Group->delete($group);
echo JsonComponent::encode(array(true,$this->t('Changes saved')));
}
}
return;
}//end ajax posts

//init forms
$formInfo->setAction($this->view->webroot.'/community/manage?communityId='.$communityId);
$formCreateGroup->setAction($this->view->webroot.'/community/manage?communityId='.$communityId);
$name=$formInfo->getElement('name');
$name->setValue($communityDao->getName());
$description=$formInfo->getElement('description');
$description->setValue($communityDao->getDescription());
$privacy=$formInfo->getElement('privacy');
$privacy->setValue($communityDao->getPrivacy());
$submit=$formInfo->getElement('submit');
$submit->setLabel($this->t('Save'));
$this->view->infoForm=$this->getFormAsArray($formInfo);
$this->view->createGroupForm=$this->getFormAsArray($formCreateGroup);

//init groups and members
$group_member=$communityDao->getMemberGroup();
$admin_group=$communityDao->getAdminGroup();
$moderator_group=$communityDao->getModeratorGroup();
$this->view->members=$group_member->getUsers();

$this->view->memberGroup=$group_member;
$this->view->adminGroup=$admin_group;
$this->view->moderatorGroup=$moderator_group;
$this->view->groups=$this->Group->findByCommunity($communityDao);

foreach($this->view->groups as $key => $group)
{
if($group->getKey()==$group_member->getKey()||$group->getKey()==$admin_group->getKey()||$group->getKey()==$moderator_group->getKey())
{
unset($this->view->groups[$key]);
}
}

//init file tree
$this->view->folders=array();
$this->view->folders[]=$communityDao->getPublicFolder();
$this->view->folders[]=$communityDao->getPrivateFolder();
$this->view->Date=$this->Component->Date;

$this->view->header=$this->t("Manage Community");
$this->view->communityDao=$communityDao;

$this->view->isAdmin=$this->Community->policyCheck($communityDao, $this->userSession->Dao,MIDAS_POLICY_ADMIN);
$this->view->json['community']=$communityDao->_toArray();
$this->view->json['community']['message']['delete']=$this->t('Delete');
$this->view->json['community']['message']['deleteMessage']=$this->t('Do you really want to delete this community? It cannot be undo.');
$this->view->json['community']['message']['deleteGroupMessage']=$this->t('Do you really want to delete this group? It cannot be undo.');
$this->view->json['community']['message']['infoErrorName']=$this->t('Please, set the name.');
$this->view->json['community']['message']['createGroup']=$this->t('Create a group');
$this->view->json['community']['message']['editGroup']=$this->t('Edit a group');
}//end manageAction


/** index*/
function indexAction()
{
Expand Down Expand Up @@ -82,10 +263,7 @@ function viewAction()
}
$this->view->isModerator=$this->Community->policyCheck($communityDao, $this->userSession->Dao,MIDAS_POLICY_WRITE);
$this->view->isAdmin=$this->Community->policyCheck($communityDao, $this->userSession->Dao,MIDAS_POLICY_ADMIN);
$this->view->json['community']=$communityDao->_toArray();
$this->view->json['community']['message']['delete']=$this->t('Delete');
$this->view->json['community']['message']['deleteMessage']=$this->t('Do you really want to delete this community? It cannot be undo.');

$this->view->json['community']=$communityDao->_toArray();
}//end view

/** Delete a community*/
Expand Down

0 comments on commit bcf0461

Please sign in to comment.