Skip to content
Snippets Groups Projects
Commit e92d19c9 authored by Tim Steiner's avatar Tim Steiner
Browse files

Update some of the model factory methods to gracefully handle being passed arrays with 0 members.

parent b36c5497
No related branches found
No related tags found
No related merge requests found
......@@ -34,19 +34,37 @@ class Requests_ApprovalRoleModel extends Unl_Model
}
}
static public function findAll()
{
$db = Zend_Registry::get('db');
$select = new Zend_Db_Select($db);
$select->from(array('r' => 'creqApprovalBodyRoles'));
$records = $select->query()->fetchAll();
$roleIds = array();
foreach ($records as $record) {
$roleIds[] = $record['approvalBodyRoleId'];
}
return self::find($roleIds);
}
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)
$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();
$objects[$user->getId()] = new Unl_Model_Collection(__CLASS__);
} else {
throw new Exception('$user is not a Unl_Model_Collection or a Auth_UserModel');
}
......@@ -63,13 +81,9 @@ class Requests_ApprovalRoleModel extends Unl_Model
}
$records = $select->query()->fetchAll();
$objects = array();
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();
......
......@@ -75,6 +75,9 @@ class Requests_RequestModel extends Unl_Model
$select = new Zend_Db_Select($db);
if (Unl_Util::isArray($role)) {
if (count($role) == 0) {
return new Unl_Model_Collection(__CLASS__);
}
$roleId = array();
foreach ($role as $aRole) {
$roleId[] = $aRole->getId();
......@@ -161,6 +164,9 @@ class Requests_RequestModel extends Unl_Model
$select = new Zend_Db_Select($db);
$select->from(array('w' => 'creqRequestWatchers'));
if (Unl_Util::isArray($roleId)) {
if (count($roleId) == 0) {
return new Unl_Model_Collection(__CLASS__);
}
$select->where('w.watchingApprovalRole IN (?)', $roleId);
} else {
$select->where('w.watchingApprovalRole = ?', $roleId);
......
......@@ -9,6 +9,9 @@ class Requests_ViewTimeModel extends Unl_Model
$select = new Zend_Db_Select($db);
$select->from(array('t' => 'creqRequestViewTimes'));
if (Unl_Util::isArray($id)) {
if (count($id) == 0) {
return new Unl_Model_Collection(__CLASS__);
}
$select->where('t.requestViewTimeId IN (?)', $id);
} else {
$select->where('t.requestViewTimeId = ?', $id);
......@@ -42,12 +45,18 @@ class Requests_ViewTimeModel extends Unl_Model
$select->from(array('t' => 'creqRequestViewTimes'), array('requestViewTimeId', 'user', 'request'));
if (Unl_Util::isArray($requestId)) {
if (count($requestId) == 0) {
return new Unl_Model_Collection(__CLASS__);
}
$select->where('request IN (?)', $requestId);
} else {
$select->where('request = ?', $requestId);
}
if (Unl_Util::isArray($userId)) {
if (count($userId) == 0) {
return new Unl_Model_Collection(__CLASS__);
}
$select->where('user IN (?)', $userId);
} else {
$select->where('user = ?', $userId);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment