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
bfefdfa5
Commit
bfefdfa5
authored
16 years ago
by
Tim Steiner
Browse files
Options
Downloads
Patches
Plain Diff
Handle ::find(NULL) on ApprovalBody and ApprovalRole models.
parent
03aebc75
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
+35
-32
35 additions, 32 deletions
application/modules/requests/models/ApprovalBodyModel.php
application/modules/requests/models/ApprovalRoleModel.php
+130
-124
130 additions, 124 deletions
application/modules/requests/models/ApprovalRoleModel.php
with
165 additions
and
156 deletions
application/modules/requests/models/ApprovalBodyModel.php
+
35
−
32
View file @
bfefdfa5
...
...
@@ -2,10 +2,13 @@
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__
);
}
else
if
(
$id
===
NULL
)
{
return
null
;
}
$db
=
Zend_Registry
::
get
(
'db'
);
...
...
@@ -43,7 +46,7 @@ class Requests_ApprovalBodyModel extends Unl_Model
$records
=
$db
->
query
(
$select
)
->
fetchAll
();
$approvalBodyIds
=
array
();
foreach
(
$records
as
$record
)
{
$approvalBodyIds
[]
=
$record
[
'approvalBodyId'
];
$approvalBodyIds
[]
=
$record
[
'approvalBodyId'
];
}
return
self
::
find
(
$approvalBodyIds
);
...
...
@@ -115,7 +118,7 @@ class Requests_ApprovalBodyModel extends Unl_Model
/**
* Gets a freshly created model object
*
* @return Requests_
Comments
Model
* @return Requests_
ApprovalBody
Model
*/
static
function
fetchNew
()
{
...
...
@@ -126,31 +129,31 @@ class Requests_ApprovalBodyModel extends Unl_Model
'adminGroup'
=>
null
);
$new
=
new
self
(
$data
);
$new
=
new
self
(
$data
);
$new
->
_setClean
();
return
$new
;
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
;
}
}
$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
);
...
...
@@ -168,7 +171,7 @@ class Requests_ApprovalBodyModel extends Unl_Model
static
protected
function
_update
(
Unl_Model_Collection
$models
)
{
$db
=
Zend_Registry
::
get
(
'db'
);
$db
=
Zend_Registry
::
get
(
'db'
);
$sql
=
'CREATE TEMPORARY TABLE creqApprovalBodiesUpdate '
.
'SELECT * FROM creqApprovalBodies LIMIT 0'
;
...
...
@@ -176,18 +179,18 @@ class Requests_ApprovalBodyModel extends Unl_Model
$sql
=
'INSERT INTO creqApprovalBodiesUpdate VALUES '
;
$sqlParts
=
array
();
foreach
(
$models
as
$model
)
{
$sqlParts
[]
=
$db
->
quoteInto
(
'(?, '
,
$model
->
_data
[
'approvalBodyId'
])
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
.
=
implode
(
', '
,
$sqlParts
);
$db
->
query
(
$sql
);
$sql
=
'UPDATE creqApprovalBodies AS a, '
.
' creqApprovalBodiesUpdate AS b '
.
'SET a.name = b.name, '
$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 '
;
...
...
@@ -198,7 +201,7 @@ class Requests_ApprovalBodyModel extends Unl_Model
{
$db
=
Zend_Registry
::
get
(
'db'
);
$sql
=
'INSERT INTO creqApprovalBodies (name, description, adminGroup) VALUES '
;
$sql
=
'INSERT INTO creqApprovalBodies (name, description, adminGroup) VALUES '
;
$sqlParts
=
array
();
foreach
(
$models
as
$model
)
{
$sqlParts
[]
=
$db
->
quoteInto
(
'(?, '
,
$model
->
_data
[
'name'
])
...
...
@@ -217,7 +220,7 @@ class Requests_ApprovalBodyModel extends Unl_Model
public
function
getId
()
{
return
$this
->
_data
[
'approvalBodyId'
];
return
$this
->
_data
[
'approvalBodyId'
];
}
public
function
getName
()
...
...
This diff is collapsed.
Click to expand it.
application/modules/requests/models/ApprovalRoleModel.php
+
130
−
124
View file @
bfefdfa5
...
...
@@ -2,9 +2,15 @@
class
Requests_ApprovalRoleModel
extends
Unl_Model
{
static
public
function
find
(
$id
)
{
if
(
Unl_Util
::
isArray
(
$id
)
&&
count
(
$id
)
==
0
)
{
return
new
Unl_Model_Collection
(
__CLASS__
);
}
else
if
(
$id
===
NULL
)
{
return
null
;
}
$db
=
Zend_Registry
::
get
(
'db'
);
$select
=
new
Zend_Db_Select
(
$db
);
...
...
@@ -43,88 +49,88 @@ class Requests_ApprovalRoleModel extends Unl_Model
$records
=
$select
->
query
()
->
fetchAll
();
$roleIds
=
array
();
foreach
(
$records
as
$record
)
{
$roleIds
[]
=
$record
[
'approvalBodyRoleId'
];
$roleIds
[]
=
$record
[
'approvalBodyRoleId'
];
}
return
self
::
find
(
$roleIds
);
}
static
public
function
findByUser
(
$user
)
{
$db
=
Zend_Registry
::
get
(
'db'
);
$select
=
new
Zend_Db_Select
(
$db
);
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)
// get userId as a string or array from the user object(s)
$objects
=
array
();
if
(
Unl_Util
::
isArray
(
$user
))
{
$userId
=
array
();
foreach
(
$user
as
$aUser
)
{
$userId
[]
=
$aUser
->
getId
();
$objects
[
$aUser
->
getId
()]
=
new
Unl_Model_Collection
(
__CLASS__
);
}
}
else
if
(
$user
instanceof
Auth_UserModel
)
{
$userId
=
$user
->
getId
();
if
(
Unl_Util
::
isArray
(
$user
))
{
$userId
=
array
();
foreach
(
$user
as
$aUser
)
{
$userId
[]
=
$aUser
->
getId
();
$objects
[
$aUser
->
getId
()]
=
new
Unl_Model_Collection
(
__CLASS__
);
}
}
else
if
(
$user
instanceof
Auth_UserModel
)
{
$userId
=
$user
->
getId
();
$objects
[
$user
->
getId
()]
=
new
Unl_Model_Collection
(
__CLASS__
);
}
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'
));
$select
->
join
(
array
(
'r'
=>
'creqApprovalBodyRoles'
),
'u.primaryGroup = r.group'
);
if
(
Unl_Util
::
isArray
(
$userId
))
{
$select
->
where
(
'u.userId IN (?)'
,
$userId
);
}
else
{
$select
->
where
(
'u.userId = ?'
,
$userId
);
}
$records
=
$select
->
query
()
->
fetchAll
();
foreach
(
$records
as
$record
)
{
$recordUserId
=
$record
[
'userId'
];
unset
(
$record
[
'userId'
]);
$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'
));
$select
->
join
(
array
(
'm'
=>
'creqGroupImpliedMemberships'
),
'u.primaryGroup = m.childGroup'
,
array
());
$select
->
join
(
array
(
'r'
=>
'creqApprovalBodyRoles'
),
'm.parentGroup = r.group'
);
if
(
Unl_Util
::
isArray
(
$userId
))
{
$select
->
where
(
'u.userId IN (?)'
,
$userId
);
}
else
{
$select
->
where
(
'u.userId = ?'
,
$userId
);
}
$records
=
$select
->
query
()
->
fetchAll
();
foreach
(
$records
as
$record
)
{
$recordUserId
=
$record
[
'userId'
];
unset
(
$record
[
'userId'
]);
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
;
// otherwise, return an array of groups for the single user we were passed
}
else
{
return
$objects
[
$userId
];
}
}
public
function
findByParentBody
(
$parentBody
)
{
}
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'
));
$select
->
join
(
array
(
'r'
=>
'creqApprovalBodyRoles'
),
'u.primaryGroup = r.group'
);
if
(
Unl_Util
::
isArray
(
$userId
))
{
$select
->
where
(
'u.userId IN (?)'
,
$userId
);
}
else
{
$select
->
where
(
'u.userId = ?'
,
$userId
);
}
$records
=
$select
->
query
()
->
fetchAll
();
foreach
(
$records
as
$record
)
{
$recordUserId
=
$record
[
'userId'
];
unset
(
$record
[
'userId'
]);
$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'
));
$select
->
join
(
array
(
'm'
=>
'creqGroupImpliedMemberships'
),
'u.primaryGroup = m.childGroup'
,
array
());
$select
->
join
(
array
(
'r'
=>
'creqApprovalBodyRoles'
),
'm.parentGroup = r.group'
);
if
(
Unl_Util
::
isArray
(
$userId
))
{
$select
->
where
(
'u.userId IN (?)'
,
$userId
);
}
else
{
$select
->
where
(
'u.userId = ?'
,
$userId
);
}
$records
=
$select
->
query
()
->
fetchAll
();
foreach
(
$records
as
$record
)
{
$recordUserId
=
$record
[
'userId'
];
unset
(
$record
[
'userId'
]);
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
;
// otherwise, return an array of groups for the single user we were passed
}
else
{
return
$objects
[
$userId
];
}
}
public
function
findByParentBody
(
$parentBody
)
{
$db
=
Zend_Registry
::
get
(
'db'
);
if
(
Unl_Util
::
isArray
(
$parentBody
))
{
...
...
@@ -155,13 +161,13 @@ class Requests_ApprovalRoleModel extends Unl_Model
$objects
=
array
();
foreach
((
array
)
$parentBody
->
getId
()
as
$parentBodyId
)
{
$objects
[
$parentBodyId
]
=
new
Unl_Model_Collection
(
__CLASS__
);
$objects
[
$parentBodyId
]
=
new
Unl_Model_Collection
(
__CLASS__
);
}
foreach
(
$approvalBodyRoles
as
$approvalBodyId
=>
$approvalRoleIds
)
{
foreach
(
$approvalRoleIds
as
$approvalRoleId
)
{
foreach
(
$approvalRoleIds
as
$approvalRoleId
)
{
$objects
[
$approvalBodyId
][
$approvalRoleId
]
=
Unl_Model_Registry
::
getInstance
()
->
get
(
__CLASS__
,
$approvalRoleId
);
}
}
}
if
(
Unl_Util
::
isArray
(
$parentBody
))
{
...
...
@@ -169,12 +175,12 @@ class Requests_ApprovalRoleModel extends Unl_Model
}
else
{
return
array_pop
(
$objects
);
}
}
}
/**
* Gets a freshly created model object
*
* @return Requests_
Comments
Model
* @return Requests_
ApprovalRole
Model
*/
static
function
fetchNew
()
{
...
...
@@ -278,49 +284,49 @@ class Requests_ApprovalRoleModel extends Unl_Model
}
}
public
function
getId
()
{
return
$this
->
_data
[
'approvalBodyRoleId'
];
}
public
function
getName
()
{
return
$this
->
_data
[
'name'
];
}
public
function
setName
(
$name
)
{
$this
->
_data
[
'name'
]
=
$name
;
}
public
function
getNotice
()
{
return
$this
->
_data
[
'notice'
];
}
public
function
setNotice
(
$notice
)
{
$this
->
_data
[
'notice'
]
=
$notice
;
}
public
function
getApprovalBody
()
{
return
$this
->
_data
[
'approvalBody'
];
}
public
function
setApprovalBody
(
Requests_ApprovalBodyModel
$approvalBody
)
{
$this
->
_data
[
'approvalBody'
]
=
$approvalBody
->
getId
();
}
public
function
getGroup
()
{
return
$this
->
_data
[
'group'
];
}
public
function
setGroup
(
Auth_GroupModel
$group
)
{
$this
->
_data
[
'group'
]
=
$group
->
getId
();
}
public
function
getId
()
{
return
$this
->
_data
[
'approvalBodyRoleId'
];
}
public
function
getName
()
{
return
$this
->
_data
[
'name'
];
}
public
function
setName
(
$name
)
{
$this
->
_data
[
'name'
]
=
$name
;
}
public
function
getNotice
()
{
return
$this
->
_data
[
'notice'
];
}
public
function
setNotice
(
$notice
)
{
$this
->
_data
[
'notice'
]
=
$notice
;
}
public
function
getApprovalBody
()
{
return
$this
->
_data
[
'approvalBody'
];
}
public
function
setApprovalBody
(
Requests_ApprovalBodyModel
$approvalBody
)
{
$this
->
_data
[
'approvalBody'
]
=
$approvalBody
->
getId
();
}
public
function
getGroup
()
{
return
$this
->
_data
[
'group'
];
}
public
function
setGroup
(
Auth_GroupModel
$group
)
{
$this
->
_data
[
'group'
]
=
$group
->
getId
();
}
}
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