function Validate() { if ($this->getUser() == $this->getParent()) { $this->Validator->isTrue('parent', FALSE, TTi18n::gettext('User is the same as parent')); } //Make sure both user and parent belong to the same company $ulf = new UserListFactory(); $ulf->getById($this->getUser()); $user = $ulf->getIterator()->current(); unset($ulf); $ulf = new UserListFactory(); $ulf->getById($this->getParent()); $parent = $ulf->getIterator()->current(); unset($ulf); if ($this->getUser() == 0 and $this->getParent() == 0) { $parent_company_id = 0; $user_company_id = 0; } elseif ($this->getUser() == 0) { $parent_company_id = $parent->getCompany(); $user_company_id = $parent->getCompany(); } elseif ($this->getParent() == 0) { $parent_company_id = $user->getCompany(); $user_company_id = $user->getCompany(); } else { $parent_company_id = $parent->getCompany(); $user_company_id = $user->getCompany(); } if ($user_company_id > 0 and $parent_company_id > 0) { Debug::Text(' User Company: ' . $user_company_id . ' Parent Company: ' . $parent_company_id, __FILE__, __LINE__, __METHOD__, 10); if ($user_company_id != $parent_company_id) { $this->Validator->isTrue('parent', FALSE, TTi18n::gettext('User or parent has incorrect company')); } $this->getFastTreeObject()->setTree($this->getHierarchyControl()); $children_arr = $this->getFastTreeObject()->getAllChildren($this->getUser(), 'RECURSE'); if (is_array($children_arr)) { $children_ids = array_keys($children_arr); if (isset($children_ids) and is_array($children_ids) and in_array($this->getParent(), $children_ids) == TRUE) { Debug::Text(' Objects cant be re-parented to their own children...', __FILE__, __LINE__, __METHOD__, 10); $this->Validator->isTrue('parent', FALSE, TTi18n::gettext('Unable to change parent to a child of itself')); } } /* //Make sure we're not re-parenting to a child. $uhlf = new UserHierarchyListFactory(); $hierarchy = $uhlf->getByCompanyIdArray( $parent_company_id ); Debug::Text(' User ID: '. $this->getUser() .' Parent ID: '. $this->getParent(), __FILE__, __LINE__, __METHOD__,10); if ( is_array( $hierarchy ) ) { if ( in_array( $this->getParent(), array_keys( $hierarchy[$this->getUser()] ) ) ) { Debug::Text(' Trying to re-parent to a child! ', __FILE__, __LINE__, __METHOD__,10); $this->Validator->isTrue( 'parent', FALSE, TTi18n::gettext('Unable to change parent to a child of itself') ); } else { Debug::Text(' NOT Trying to re-parent to a child! ', __FILE__, __LINE__, __METHOD__,10); } } else { Debug::Text(' NOT Trying to re-parent to a child! 22', __FILE__, __LINE__, __METHOD__,10); } */ } return TRUE; }