Esempio n. 1
0
 function __construct($getCurrentValues = true)
 {
     parent::__construct();
     $userPreferences = UserPreferences::instance();
     $this->setModuleName('contacts');
     $roleCollection = new RoleCollection();
     $sh = new SearchHandler($roleCollection, false);
     $sh->AddConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
     $sh->setOrderby('name');
     $roleCollection->load($sh);
     $roles = array();
     foreach ($roleCollection->getContents() as $role) {
         $roles[$role->id] = array('value' => $role->id, 'label' => $role->name);
         if ($getCurrentValues) {
             if (in_array($role->id, $userPreferences->getPreferenceValue('default-read-roles', 'contacts'))) {
                 $roles[$role->id]['selected'] = true;
             }
         }
     }
     $this->registerPreference(array('name' => 'default-read-roles', 'display_name' => 'Default Read Access', 'type' => 'select_multiple', 'data' => $roles, 'default' => array()));
     foreach ($roleCollection->getContents() as $role) {
         $roles[$role->id] = array('value' => $role->id, 'label' => $role->name);
         if ($getCurrentValues) {
             if (in_array($role->id, $userPreferences->getPreferenceValue('default-write-roles', 'contacts'))) {
                 $roles[$role->id]['selected'] = true;
             }
         }
     }
     $this->registerPreference(array('name' => 'default-write-roles', 'display_name' => 'Default Write Access', 'type' => 'select_multiple', 'data' => $roles, 'default' => array()));
 }
Esempio n. 2
0
 function getRoles()
 {
     $roles = new RoleCollection(new Role());
     $sh = new SearchHandler($roles, false, false);
     $sh->addConstraint(new Constraint('usercompanyid', '=', $this->usercompanyid));
     $roles->load($sh);
     return $roles;
 }
Esempio n. 3
0
 public function sharing($model = '')
 {
     $flash = Flash::Instance();
     if (!$this->checkParams(array('id', 'model'), $flash)) {
         sendTo();
     }
     if (empty($model)) {
         $modelname = $this->_data['model'];
     } else {
         $modelname = $model;
     }
     $object = $this->_uses[$modelname];
     $object->load($this->_data['id']);
     // What if 'owner' is not a field on the model?
     if ($object->owner != EGS_USERNAME && !isModuleAdmin()) {
         // We're not the owner, are we /really/ allowed to read this object?
         $objectPermissions = new ObjectRoleCollection();
         if ($objectPermissions->getRows($object->id, $object->getTableName(), 'write')->count() == 0) {
             if (empty($model)) {
                 $flash = Flash::Instance();
                 $flash->addError('You do not have permission to edit this ' . $modelname);
                 sendTo($this->name, 'view', $this->_data['module'], array('id' => $this->_data['id']));
             }
             return false;
         }
     }
     $roles = array();
     $roleCollection = new RoleCollection();
     $sh = new SearchHandler($roleCollection, false);
     $sh->AddConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
     $roleCollection->load($sh);
     // $ObjectRole = new ObjectRole;
     $ObjectRole = DataObjectFactory::Factory('ObjectRole');
     $writeRoles = $ObjectRole->getRoleID($this->_data['id'], $object->getTableName(), 'write');
     if ($writeRoles === false) {
         $writeRoles = array();
     }
     foreach ($roleCollection->getContents() as $role) {
         $roles[$role->id]['name'] = $role->name;
         if (array_key_exists($role->id, $writeRoles)) {
             $roles[$role->id]['selected'] = true;
         }
     }
     $this->view->set('writeRoles', $roles);
     // $ObjectRole = new ObjectRole;
     $ObjectRole = DataObjectFactory::Factory('ObjectRole');
     $readRoles = $ObjectRole->getRoleID($this->_data['id'], $object->getTableName(), 'read');
     if ($readRoles === false) {
         $readRoles = array();
     }
     foreach ($roleCollection->getContents() as $role) {
         $roles[$role->id]['name'] = $role->name;
         if (array_key_exists($role->id, $readRoles)) {
             $roles[$role->id]['selected'] = true;
         }
     }
     $this->view->set('readRoles', $roles);
     // FIXME: I'm sure this isn't the way this is done
     $this->view->set('id', $this->_data['id']);
     $this->view->set('model_name', $this->_data['model']);
     $this->view->set('model', $object);
     return true;
 }