Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Curriculum-Request
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tim Steiner
Curriculum-Request
Commits
83817ffd
Commit
83817ffd
authored
16 years ago
by
Tim Steiner
Browse files
Options
Downloads
Patches
Plain Diff
Added the Requests_ApprovalBodyModel, and added the getBody() method to Requests_ApprovalRoleModel
parent
12e1e536
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
application/modules/requests/models/ApprovalBodyModel.php
+194
-0
194 additions, 0 deletions
application/modules/requests/models/ApprovalBodyModel.php
application/modules/requests/models/ApprovalRoleModel.php
+19
-14
19 additions, 14 deletions
application/modules/requests/models/ApprovalRoleModel.php
with
213 additions
and
14 deletions
application/modules/requests/models/ApprovalBodyModel.php
0 → 100644
+
194
−
0
View file @
83817ffd
rklusman
<?php
class
Requests_ApprovalBodyModel
extends
Unl_Model
{
static
public
function
find
(
$id
)
{
if
(
Unl_Util
::
isArray
(
$id
)
&&
count
(
$id
)
==
0
)
{
return
new
Unl_Model_Collection
(
__CLASS__
);
}
$db
=
Zend_Registry
::
get
(
'db'
);
$select
=
new
Zend_Db_Select
(
$db
);
$select
->
from
(
array
(
'c'
=>
'creqApprovalBodies'
));
if
(
Unl_Util
::
isArray
(
$id
))
{
$select
->
where
(
'c.approvalBodyId IN(?)'
,
$id
);
}
else
{
$select
->
where
(
'c.approvalBodyId = ?'
,
$id
);
}
$records
=
$db
->
query
(
$select
)
->
fetchAll
();
$objects
=
new
Unl_Model_Collection
(
__CLASS__
);
foreach
(
$records
as
$record
)
{
$object
=
Unl_Model_Registry
::
getInstance
()
->
getOrAdd
(
new
self
(
$record
));
$objectId
=
$object
->
getId
();
$objects
[
$objectId
]
=
$object
;
}
if
(
Unl_Util
::
isArray
(
$id
))
{
return
$objects
;
}
else
{
return
$objects
->
pop
();
}
}
static
public
function
findForApprovalRoles
(
$approvalRoles
)
{
if
(
Unl_Util
::
isArray
(
$approvalRoles
))
{
$inputIsArray
=
true
;
foreach
(
$approvalRoles
as
$approvalRole
)
{
$id
[
$approvalRole
->
getId
()]
=
$approvalRole
->
getApprovalBody
();
}
}
else
{
$inputIsArray
=
false
;
$id
[
$approvalRoles
]
=
$approvalRoles
->
getApprovalBody
();
}
self
::
find
(
$id
);
$objects
=
new
Unl_Model_Collection
(
__CLASS__
);
foreach
(
$id
as
$roleId
=>
$bodyId
)
{
$objects
[
$roleId
]
=
Unl_Model_Registry
::
getInstance
()
->
get
(
__CLASS__
,
$bodyId
);
}
if
(
$inputIsArray
)
{
return
$objects
;
}
else
{
return
$objects
->
pop
();
}
}
/**
* Gets a freshly created model object
*
* @return Requests_CommentsModel
*/
static
function
fetchNew
()
{
$data
=
array
(
'approvalBodyId'
=>
null
,
'name'
=>
null
,
'description'
=>
null
,
'adminGroup'
=>
null
);
$new
=
new
self
(
$data
);
$new
->
_setClean
();
return
$new
;
}
static
public
function
save
(
$models
)
{
$modelsToInsert
=
new
Unl_Model_Collection
(
__CLASS__
);
$modelsToUpdate
=
new
Unl_Model_Collection
(
__CLASS__
);
if
(
!
Unl_Util
::
isArray
(
$models
))
{
$model
=
$models
;
$models
=
new
Unl_Model_Collection
(
__CLASS__
);
$models
[
$model
->
getId
()]
=
$model
;
}
foreach
(
$models
as
$model
)
{
if
(
$model
->
getId
())
{
if
(
$model
->
_cleanData
!=
$model
->
_data
)
{
$modelsToUpdate
[]
=
$model
;
}
}
else
{
$modelsToInsert
[]
=
$model
;
}
}
if
(
count
(
$modelsToInsert
)
>
0
)
{
self
::
_insert
(
$modelsToInsert
);
}
if
(
count
(
$modelsToUpdate
)
>
0
)
{
self
::
_update
(
$modelsToUpdate
);
}
foreach
(
$models
as
$model
)
{
$model
->
_setClean
();
}
}
static
protected
function
_update
(
Unl_Model_Collection
$models
)
{
$db
=
Zend_Registry
::
get
(
'db'
);
$sql
=
'CREATE TEMPORARY TABLE creqApprovalBodiesUpdate '
.
'SELECT * FROM creqApprovalBodies LIMIT 0'
;
$db
->
query
(
$sql
);
$sql
=
'INSERT INTO creqApprovalBodiesUpdate VALUES '
;
$sqlParts
=
array
();
foreach
(
$models
as
$model
)
{
$sqlParts
[]
=
$db
->
quoteInto
(
'(?, '
,
$model
->
_data
[
'approvalBodyId'
])
.
$db
->
quoteInto
(
'?, '
,
$model
->
_data
[
'name'
])
.
$db
->
quoteInto
(
'?, '
,
$model
->
_data
[
'description'
])
.
$db
->
quoteInto
(
'?)'
,
$model
->
_data
[
'adminGroup'
]);
}
$sql
.
=
implode
(
', '
,
$sqlParts
);
$db
->
query
(
$sql
);
$sql
=
'UPDATE creqApprovalBodies AS a, '
.
' creqApprovalBodiesUpdate AS b '
.
'SET a.name = b.name, '
.
' a.description = b.description, '
.
' a.adminGroup = b.adminGroup '
.
'WHERE a.approvalBodyId = b.approvalBodyId '
;
$db
->
query
(
$sql
);
}
static
protected
function
_insert
(
Unl_Model_Collection
$models
)
{
$db
=
Zend_Registry
::
get
(
'db'
);
$sql
=
'INSERT INTO creqApprovalBodies (name, description, adminGroup) VALUES '
;
$sqlParts
=
array
();
foreach
(
$models
as
$model
)
{
$sqlParts
[]
=
$db
->
quoteInto
(
'(?, '
,
$model
->
_data
[
'name'
])
.
$db
->
quoteInto
(
'?, '
,
$model
->
_data
[
'description'
])
.
$db
->
quoteInto
(
'?)'
,
$model
->
_data
[
'adminGroup'
]);
}
$sql
.
=
implode
(
', '
,
$sqlParts
);
$db
->
query
(
$sql
);
}
public
function
getId
()
{
return
$this
->
_data
[
'approvalBodyId'
];
}
public
function
getName
()
{
return
$this
->
_data
[
'name'
];
}
public
function
setName
(
$name
)
{
$this
->
_data
[
'name'
]
=
$name
;
}
public
function
getDescription
()
{
return
$this
->
_data
[
'description'
];
}
public
function
setDescription
(
$description
)
{
$this
->
_data
[
'description'
]
=
$description
;
}
public
function
getAdminGroup
()
{
return
$this
->
_data
[
'adminGroup'
];
}
public
function
setAdminGroup
(
Auth_GroupModel
$group
)
{
$this
->
_data
[
'adminGroup'
]
=
$group
->
getId
();
}
}
This diff is collapsed.
Click to expand it.
application/modules/requests/models/ApprovalRoleModel.php
+
19
−
14
View file @
83817ffd
...
...
@@ -2,12 +2,12 @@
class
Requests_ApprovalRoleModel
extends
Unl_Model
{
static
public
function
findByUser
(
$user
)
{
$db
=
Zend_Registry
::
get
(
'db'
);
$select
=
new
Zend_Db_Select
(
$db
);
// get userId as a string or array from the user object(s)
if
(
Unl_Util
::
isArray
(
$user
))
{
$userId
=
array
();
...
...
@@ -19,8 +19,8 @@ class Requests_ApprovalRoleModel extends Unl_Model
}
else
{
throw
new
Exception
(
'$user is not a Unl_Model_Collection or a Auth_UserModel'
);
}
// find the group(s) that the user(s) is a "primary" member of
$select
=
new
Zend_Db_Select
(
$db
);
$select
->
from
(
array
(
'u'
=>
'creqUsers'
),
array
(
'userId'
));
...
...
@@ -30,7 +30,7 @@ class Requests_ApprovalRoleModel extends Unl_Model
}
else
{
$select
->
where
(
'u.userId = ?'
,
$userId
);
}
$records
=
$select
->
query
()
->
fetchAll
();
$objects
=
array
();
foreach
(
$records
as
$record
)
{
...
...
@@ -39,12 +39,12 @@ class Requests_ApprovalRoleModel extends Unl_Model
if
(
!
$objects
[
$recordUserId
])
{
$objects
[
$recordUserId
]
=
new
Unl_Model_Collection
(
'Requests_ApprovalRoleModel'
);
}
$object
=
Unl_Model_Registry
::
getInstance
()
->
getOrAdd
(
new
self
(
$record
));
$objectId
=
$object
->
getId
();
$objects
[
$recordUserId
][
$objectId
]
=
$object
;
}
// find any groups that the user(s) is a "non-primary" member of
$select
=
new
Zend_Db_Select
(
$db
);
$select
->
from
(
array
(
'u'
=>
'creqUsers'
),
array
(
'userId'
));
...
...
@@ -55,7 +55,7 @@ class Requests_ApprovalRoleModel extends Unl_Model
}
else
{
$select
->
where
(
'u.userId = ?'
,
$userId
);
}
$records
=
$select
->
query
()
->
fetchAll
();
foreach
(
$records
as
$record
)
{
$recordUserId
=
$record
[
'userId'
];
...
...
@@ -63,12 +63,12 @@ class Requests_ApprovalRoleModel extends Unl_Model
if
(
!
$objects
[
$recordUserId
])
{
$objects
[
$recordUserId
]
=
new
Unl_Model_Collection
(
'Requests_ApprovalRoleModel'
);
}
$object
=
Unl_Model_Registry
::
getInstance
()
->
getOrAdd
(
new
self
(
$record
));
$objectId
=
$object
->
getId
();
$objects
[
$recordUserId
][
$objectId
]
=
$object
;
}
// if we were passed an array of users, return an array for each user
if
(
Unl_Util
::
isArray
(
$userId
))
{
return
$objects
;
...
...
@@ -77,20 +77,25 @@ class Requests_ApprovalRoleModel extends Unl_Model
return
$objects
[
$userId
];
}
}
public
function
getId
()
{
return
$this
->
_data
[
'approvalBodyRoleId'
];
}
public
function
getName
()
{
return
$this
->
_data
[
'name'
];
}
public
function
getNotice
()
{
return
$this
->
_data
[
'notice'
];
}
public
function
getApprovalBody
()
{
return
$this
->
_data
[
'approvalBody'
];
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment