/**
  * function __construct
  * <pre>
  * Initialize the Class ...
  * </pre>
  * @param $sortBy [STRING] the field name to sort list by
  * @return [void]
  */
 function __construct($sortBy = '')
 {
     $searchManager = new RowManager_AccountAdminAccessManager();
     // NOTE: if you need to narrow the field of the search then uncommnet
     // the following and set the proper search criteria.
     //$searchManager->setValueByFieldName('module_isCommonLook', '1' );
     $searchManager->setSortOrder($sortBy);
     $this->resultSet = $searchManager->find();
 }
 /**
  * function getListAccountPriviledgeAccess
  * <pre>
  * Returns a ListIterator for the list of accounts this viewer has access
  * to modify.
  * </pre>
  * @param $sortBy [STRING] the name of the field to sort by (can be a
  * comma seperated list).
  * @return [OBJECT]
  */
 function getListAccountPriviledgeAccess($sortBy)
 {
     $multiTable = new MultiTableManager();
     $genViewer = new RowManager_ViewerManager();
     $joinFieldA = $genViewer->getJoinOnViewerID();
     // if the current viewer is limited to the Group Access scope then
     // filter list based on current group.
     if ($this->hasGroupPriv()) {
         $viewerMgr = $this->getViewerManager();
         $genViewer->setAccountGroupID($viewerMgr->getAccountGroupID());
     }
     $multiTable->addRowManager($genViewer);
     $accessManager = new RowManager_AccountAdminAccessManager();
     $joinFieldB = $accessManager->getJoinOnViewerID();
     $joinPair = new JoinPair($joinFieldA, $joinFieldB);
     $multiTable->addRowManager($accessManager, $joinPair);
     $multiTable->constructSearchCondition('accountadminaccess_privilege', '<=', $this->getAccessPrivilege(), true);
     return $multiTable->getListIterator($sortBy);
 }
 /**
  * function processData
  * <pre>
  * Processes the data for this form.
  * </pre>
  * @return [void]
  */
 function processData()
 {
     // now get list of NEW Groups added to this Account
     $addedList = array();
     for ($indx = 0; $indx < count($this->submittedGroups); $indx++) {
         $id = $this->submittedGroups[$indx];
         // if id not in currentGroupList then add to addList
         if (!isset($this->currentGroupList[$id])) {
             $addedList[] = $id;
         }
     }
     // foreach added group
     $viewerAccessGroup = new RowManager_ViewerAccessGroupManager();
     $accessGroupManager = new RowManager_AccessGroupManager();
     $adminAccessGroupID = $accessGroupManager->getAdminAccessGroupID();
     //print($adminAccessGroupID . "<br>");
     for ($indx = 0; $indx < count($addedList); $indx++) {
         // create new entry
         $viewerAccessGroup->createNewEntry();
         // load values
         $values = array();
         $values['viewer_id'] = $this->viewer_id;
         $values['accessgroup_id'] = $addedList[$indx];
         $viewerAccessGroup->loadFromArray($values);
         // update DB Table
         $viewerAccessGroup->updateDBTable();
         //add to table accountadmin_accountadminaccess if acces group is adminAccesGroup
         if ($values['accessgroup_id'] == $adminAccessGroupID) {
             $aam = new RowManager_AccountAdminAccessManager();
             $aam->setViewerID($this->viewer_id);
             $aam->setGroupPrivilege();
             $aam->createNewEntry();
         }
     }
     // next group
     $languageManager = new RowManager_LanguageManager();
     $languageList = $languageManager->getListIterator();
     $languageList->setFirst();
     while ($language = $languageList->getNext()) {
         $navbar = new RowManager_NavBarCacheManager();
         $navbar->loadByViewerID($this->viewer_id, $language->getID());
         if ($navbar->getID() != -1) {
             $navbar->setCacheInvalid();
             $navbar->updateDBTable();
         }
     }
     // get list of DELETED Groups from this account
     $deletedList = array();
     foreach ($this->currentGroupList as $key => $value) {
         if (!in_array($key, $this->submittedGroups)) {
             $deletedList[] = $key;
         }
     }
     // foreach deleted group
     for ($indx = 0; $indx < count($deletedList); $indx++) {
         // if we can load a manager for this account with this group then
         if ($viewerAccessGroup->loadByViewerAccessGroup($this->viewer_id, $deletedList[$indx])) {
             // delete
             $viewerAccessGroup->deleteEntry();
             if ($deletedList[$indx] == $adminAccessGroupID) {
                 $aam = new RowManager_AccountAdminAccessManager();
                 $aam->setViewerID($this->viewer_id);
                 //$aam->setGroupPrivilege();
                 //print("before delete");
                 $aam->deleteEntry();
             }
         }
     }
     // next group
     // update currentGroupList with submittedGroupList
     $groupList = new ViewerAccessGroupList($this->viewer_id, $this->sortBy);
     $this->currentGroupList = $groupList->getAccessGroupArray();
 }