Subversion Repositories bacoAlunos

Rev

Rev 1814 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
146 jmachado 1
package pt.estgp.estgweb.domain;
2
 
1814 jmachado 3
import pt.estgp.estgweb.utils.Globals;
214 jmachado 4
 
146 jmachado 5
/**
6
 * @author Jorge Machado
7
 * @date 21/Abr/2008
8
 * @time 14:37:50
9
 * @see pt.estgp.estgweb.domain
10
 */
11
public class CourseUnitBlogImpl extends CourseUnitBlog
12
{
214 jmachado 13
 
14
 
15
    public CourseUnitBlogImpl()
16
    {
17
        super.setType(Globals.BLOG_TYPE_COURSE_UNIT);
18
    }
19
 
202 jmachado 20
    public boolean canAddPost(GenericUserImpl user)
21
    {
22
        return canAddPost(user,false);
23
    }
146 jmachado 24
    /**
25
     * Check if user has any target role and if is associated in some way with blog course unit
26
     *
27
     * @param user to check
28
     * @return true if can add post
29
     */
202 jmachado 30
    public boolean canAddPost(GenericUserImpl user, boolean transaction)
146 jmachado 31
    {
208 jmachado 32
        if(!super.canAddPost(user,transaction))
146 jmachado 33
            return false;
202 jmachado 34
        if(user == null)
35
            return false;
146 jmachado 36
        if(user instanceof Teacher)
37
        {
204 jmachado 38
            return ((TeacherImpl)user).hasCourseUnit(getCourseUnit().getId(),transaction);
146 jmachado 39
        }
40
        else if(user instanceof Student)
41
        {
204 jmachado 42
            return ((StudentImpl)user).hasCourseUnit(getCourseUnit().getId(),transaction);
146 jmachado 43
        }
44
        return false;
45
    }
202 jmachado 46
 
47
    public boolean canLoad(GenericUserImpl user)
48
    {
49
        return !isCourseUnitInternal() || canAddPost(user);
50
    }
51
 
52
    public boolean canLoadInOpenTransaction(GenericUserImpl user)
53
    {
54
        return !isCourseUnitInternal() || canAddPost(user,true);
55
    }
208 jmachado 56
 
1782 jmachado 57
    public boolean checkIsOwnedBy(GenericUser u, boolean transaction)
208 jmachado 58
    {
59
        if(u instanceof UserImpl)
1782 jmachado 60
            if(((UserImpl) u).checkIsTeacherOfCourseUnit(getCourseUnit().getId(), transaction))
208 jmachado 61
                return true;
62
        return false;
63
    }
64
 
1782 jmachado 65
    public boolean checkIsOwnedBy(GenericUser u)
208 jmachado 66
    {
1782 jmachado 67
        return checkIsOwnedBy(u, false);
208 jmachado 68
    }
146 jmachado 69
}