summaryrefslogtreecommitdiff
path: root/demos/time-tracker/protected/App_Data/MySQL4/projects.xml
blob: 099e7fef469f653709311a4f7066934866f9d124 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?xml version="1.0" encoding="utf-8" ?>
<sqlMap>

<resultMap id="project-result" class="ProjectRecord">
	<result property="ID" column="ProjectID" type="integer"/>
	<result property="Name" column="Name" />
	<result property="Description" column="Description" />
	<result property="DateCreated" column="CreationDate" typeHandler="DateTime" />
	<result property="EstimateDuration" column="EstimateDuration" type="float" />
	<result property="CompletionDate" column="CompletionDate" typeHandler="DateTime" />
	<result property="CreatorUserName" column="CreatorID" />
	<result property="ManagerUserName" column="ManagerID" />
	<result property="ActualDuration" column="ActualDuration" type="float" />
</resultMap>

<select id="ProjectNameExists" resultClass="boolean">
	SELECT COUNT(Name) FROM project WHERE Name = #value#
</select>

<insert id="CreateNewProject" parameterClass="ProjectRecord">
	INSERT INTO project
	(Name, Description, CreationDate, EstimateDuration, CompletionDate, CreatorID, ManagerID)
	VALUES
	(#Name#, #Description#, NOW(), #EstimateDuration#,
		#CompletionDate, typeHandler=DateTime#, 
		#CreatorUserName#, #ManagerUserName#)
	<selectKey property="ID" type="post" resultClass="int">
		select LAST_INSERT_ID() as value
    </selectKey>
</insert>

<select id="GetProjectByID" parameterClass="integer" resultMap="project-result">
	SELECT 
		project.ProjectID as ProjectID,
		project.Name as Name,
		project.Description as Description,
		project.CreationDate as CreationDate,
		project.EstimateDuration as EstimateDuration,
		project.CompletionDate as CompletionDate,
		project.CreatorID as CreatorID,
		project.ManagerID as ManagerID,
		SUM(time_entry.Duration) as ActualDuration
	FROM project
		LEFT JOIN categories ON project.ProjectID = categories.ProjectID
		LEFT JOIN time_entry ON categories.CategoryID = time_entry.CategoryID
	WHERE 
			project.ProjectID = #value# 
		AND Disabled = 0
	GROUP BY
		project.ProjectID
	ORDER BY
		project.Name
</select>

<select id="GetAllProjects" resultMap="project-result">
	SELECT 
		project.ProjectID as ProjectID,
		project.Name as Name,
		project.Description as Description,
		project.CreationDate as CreationDate,
		project.EstimateDuration as EstimateDuration,
		project.CompletionDate as CompletionDate,
		project.CreatorID as CreatorID,
		project.ManagerID as ManagerID,
		SUM(time_entry.Duration) as ActualDuration
	FROM project
		LEFT JOIN categories ON project.ProjectID = categories.ProjectID
		LEFT JOIN time_entry ON categories.CategoryID = time_entry.CategoryID
	WHERE 
		Disabled = 0
	GROUP BY
		project.ProjectID
</select>

<select id="GetAllProjectsOrdered" resultMap="project-result" extends="GetAllProjects">
	ORDER BY $sort$ $order$
</select>

<select id="GetProjectsByManagerName" resultMap="project-result">
	SELECT 
		project.ProjectID as ProjectID,
		project.Name as Name,
		project.Description as Description,
		project.CreationDate as CreationDate,
		project.EstimateDuration as EstimateDuration,
		project.CompletionDate as CompletionDate,
		project.CreatorID as CreatorID,
		project.ManagerID as ManagerID,
		SUM(time_entry.Duration) as ActualDuration
	FROM project
		LEFT JOIN categories ON project.ProjectID = categories.ProjectID
		LEFT JOIN time_entry ON categories.CategoryID = time_entry.CategoryID
	WHERE 
			Disabled = 0 
		AND project.ManagerID = #value#
	GROUP BY
		project.ProjectID
	ORDER BY
		project.Name
</select>

<select id="GetProjectsByUserName" resultMap="project-result">
	SELECT 
		project.ProjectID as ProjectID,
		project.Name as Name,
		project.Description as Description,
		project.CreationDate as CreationDate,
		project.EstimateDuration as EstimateDuration,
		project.CompletionDate as CompletionDate,
		project.CreatorID as CreatorID,
		project.ManagerID as ManagerID,
		SUM(time_entry.Duration) as ActualDuration
	FROM project
		LEFT JOIN categories ON project.ProjectID = categories.ProjectID
		LEFT JOIN time_entry ON categories.CategoryID = time_entry.CategoryID,
		project_members
	WHERE 
			project_members.ProjectID = project.ProjectID
		AND project_members.UserID = #value#
		AND project.Disabled = 0
	GROUP BY
		project.ProjectID
	ORDER BY
		project.Name
</select>

<update id="DeleteProject" parameterClass="integer">
	UPDATE project SET Disabled = 1 WHERE ProjectID = #value#
</update>

<select id="GetProjectMembers" parameterClass="integer">
	SELECT UserID FROM project_members WHERE ProjectID = #value#
</select>

<insert id="AddUserToProject" parameterClass="array">
	INSERT INTO project_members (UserID, ProjectID)
	VALUES(#username#, #project#)
</insert>

<delete id="RemoveUserFromProject" parameterClass="array">
	DELETE FROM project_members WHERE ProjectID = #project# AND UserID = #username#
</delete>

<update id="UpdateProject" parameterClass="ProjectRecord">
	UPDATE project
	SET 
		CompletionDate = #CompletionDate, typeHandler=DateTime#,
		Description = #Description#,
		EstimateDuration = #EstimateDuration#,
		ManagerId =#ManagerUserName#,
		Name = #Name#
	WHERE 
		ProjectID = #ID#
</update>

</sqlMap>