コード例 #1
0
 function setUser($ids)
 {
     Debug::text('Setting User IDs : ', __FILE__, __LINE__, __METHOD__, 10);
     if (is_array($ids)) {
         if (!$this->isNew()) {
             //If needed, delete mappings first.
             $hulf = new HierarchyUserListFactory();
             $hulf->getByHierarchyControlID($this->getId());
             $tmp_ids = array();
             foreach ($hulf as $obj) {
                 $id = $obj->getUser();
                 Debug::text('HierarchyControl ID: ' . $obj->getHierarchyControl() . ' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                 //Delete users that are not selected.
                 if (!in_array($id, $ids)) {
                     Debug::text('Deleting: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                     $obj->Delete();
                 } else {
                     //Save ID's that need to be updated.
                     Debug::text('NOT Deleting : ' . $id, __FILE__, __LINE__, __METHOD__, 10);
                     $tmp_ids[] = $id;
                 }
             }
             unset($id, $obj);
         }
         //Insert new mappings.
         $ulf = new UserListFactory();
         foreach ($ids as $id) {
             if (isset($ids) and !in_array($id, $tmp_ids)) {
                 $huf = new HierarchyUserFactory();
                 $huf->setHierarchyControl($this->getId());
                 $huf->setUser($id);
                 $ulf->getById($id);
                 if ($ulf->getRecordCount() > 0) {
                     $obj = $ulf->getCurrent();
                     if ($this->Validator->isTrue('user', $huf->Validator->isValid(), TTi18n::gettext('Selected subordinate is invalid or already assigned to another hierarchy with the same objects ') . ' (' . $obj->getFullName() . ')')) {
                         $huf->save();
                     }
                 }
             }
         }
         return TRUE;
     }
     Debug::text('No User IDs to set.', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }