/**
  * Gets the classes whose objects the user can execute certain action
  *
  * @param $action object - The action that the user should be allowed to do
  * @param $user User - The user that holds de permissions
  * @return Array - an array of class objects
  */
 function &findByPermission($action, $user)
 {
     $classQuery = new Query("Class");
     // Navigate relationships
     $folderClassQuery =& $classQuery->queryRelationedClass("FolderClass");
     $permissionQuery =& $folderClassQuery->queryRelationedClass("Permission");
     $actionQuery =& $permissionQuery->queryRelationedClass("Action", Relationship::ManyToOneType());
     $roleQuery =& $permissionQuery->queryRelationedClass("Role", Relationship::ManyToOneType());
     $roleUserQuery =& $roleQuery->queryRelationedClass("RoleUser");
     $userQuery =& $roleUserQuery->queryRelationedClass("User", Relationship::ManyToOneType());
     // Criterias
     $criteriaGroup = new CriteriaGroup();
     $actionCriteria = new Criteria($actionQuery, "action", $action->getAction());
     $userCriteria = new Criteria($userQuery, "ID", $user->getId());
     $criteriaGroup->addCriterion($actionCriteria);
     $criteriaGroup->addCriterion($userCriteria);
     $classQuery->setCriterion($criteriaGroup);
     // sorting
     $order = new Order($classQuery, "title", "ASC");
     $classQuery->addOrder($order);
     // Execute the query
     $recordset =& $classQuery->execute();
     $array = $this->mapAll($recordset);
     return $array;
 }
 /**
  * Gets the folders for a user to do certain action.
  *
  * @param $action Action - that the user intends to do
  * @param $user User - the user that tries to get his folders.
  * @return Array - vector of folder objects
  */
 function &findByPermission($action, $user)
 {
     $folderQuery = $this->newQueryObject();
     $folderClassQuery =& $folderQuery->queryRelationedClass("FolderClass");
     $permissionQuery =& $folderClassQuery->queryRelationedClass("Permission");
     $actionQuery =& $permissionQuery->queryRelationedClass("Action", Relationship::ManyToOneType());
     $roleQuery =& $permissionQuery->queryRelationedClass("Role", Relationship::ManyToOneType());
     $roleUserQuery =& $roleQuery->queryRelationedClass("RoleUser");
     $criteriaGroup = new CriteriaGroup();
     $actionCriteria = new Criteria($actionQuery, "action", $action->getAction());
     $criteriaGroup->addCriterion($actionCriteria);
     $userCriteria = new Criteria($roleUserQuery, "userID", $user->getId());
     $criteriaGroup->addCriterion($userCriteria);
     // Set the criterion
     $folderQuery->setCriterion($criteriaGroup);
     // Execute
     return $this->mapAll($folderQuery->execute());
 }
 /**
  * Gets the objects in a given folder
  * 
  * @param $folderId id of a certain folder
  * @return List of Object class objects
  */
 function &findByFolder($folderId)
 {
     $objectQuery = $this->newQueryObject();
     $objectFolderQuery =& $objectQuery->queryRelationedClass("ObjectFolder");
     $folderQuery =& $objectFolderQuery->queryRelationedClass("Folder", Relationship::ManyToOneType());
     $criteria =& new Criteria($folderQuery, "ID", $folderId);
     $objectQuery->setCriterion($criteria);
     $order = new Order($objectFolderQuery, "position", Order::OrderTypeAsc());
     $objectQuery->addOrder($order);
     return $this->mapAll($objectQuery->execute());
 }