function setDepartmentBranch($id) { $id = trim($id); $dblf = new DepartmentBranchListFactory(); if ($id != 0 or $this->Validator->isResultSetWithRows('department_branch', $dblf->getByID($id), TTi18n::gettext('Department Branch is invalid'))) { $this->data['department_branch_id'] = $id; return TRUE; } return FALSE; }
} } } } if ($dbuf->isValid()) { Redirect::Page(URLBuilder::getURL(NULL, 'DepartmentList.php')); break; } default: BreadCrumb::setCrumb($title); $dlf = new DepartmentListFactory(); $dlf->GetByIdAndCompanyId($id, $current_company->getId()); foreach ($dlf as $department) { //Debug::Arr($department,'Department', __FILE__, __LINE__, __METHOD__,10); $branch_data = array(); $dblf = new DepartmentBranchListFactory(); $dblf->getByDepartmentId($department->getId()); foreach ($dblf as $department_branch) { $branch_id = $department_branch->getBranch(); Debug::Text('DepartmentBranchId: ' . $branch_id, __FILE__, __LINE__, __METHOD__, 10); if (isset($id)) { //Get User ID's from database. $dbulf = new DepartmentBranchUserListFactory(); $dbulf->getByDepartmentBranchId($department_branch->getId()); $department_branch_user_ids = array(); foreach ($dbulf as $department_branch_user) { $department_branch_user_ids[] = $department_branch_user->getUser(); Debug::Text('DepartmentBranchUser: '******'s.
function setBranch($ids) { if (is_array($ids) and count($ids) > 0) { //If needed, delete mappings first. $dblf = new DepartmentBranchListFactory(); $dblf->getByDepartmentId($this->getId()); $branch_ids = array(); foreach ($dblf as $department_branch) { $branch_id = $department_branch->getBranch(); Debug::text('Department ID: ' . $department_branch->getDepartment() . ' Branch: ' . $branch_id, __FILE__, __LINE__, __METHOD__, 10); //Delete branches that are not selected. if (!in_array($branch_id, $ids)) { Debug::text('Deleting DepartmentBranch: ' . $branch_id, __FILE__, __LINE__, __METHOD__, 10); $department_branch->Delete(); } else { //Save branch ID's that need to be updated. Debug::text('NOT Deleting DepartmentBranch: ' . $branch_id, __FILE__, __LINE__, __METHOD__, 10); $branch_ids[] = $branch_id; } } //Insert new mappings. $dbf = new DepartmentBranchFactory(); foreach ($ids as $id) { if (!in_array($id, $branch_ids)) { $dbf->setDepartment($this->getId()); $dbf->setBranch($id); if ($this->Validator->isTrue('branch', $dbf->Validator->isValid(), TTi18n::gettext('Branch selection is invalid'))) { $dbf->save(); } } } return TRUE; } return FALSE; }