Esempio n. 1
0
 public function dtgRole_Bind()
 {
     // Because we want to enable pagination AND sorting, we need to setup the $objClauses array to send to LoadAll()
     // Setup the $objClauses Array
     $objClauses = array();
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->dtgRole->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->dtgRole->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be the array of all NarroRole objects, given the clauses above
     $this->dtgRole->DataSource = NarroRole::LoadAll($objClauses);
     QApplication::ExecuteJavaScript('highlight_datagrid();');
 }
Esempio n. 2
0
 public function __construct($objUser, $objParentObject, $strControlId = null)
 {
     // Call the Parent
     try {
         parent::__construct($objParentObject, $strControlId);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
     $this->strTemplate = __NARRO_INCLUDES__ . '/narro/panel/NarroUserRolePanel.tpl.php';
     $this->objUser = $objUser;
     // Setup DataGrid Columns
     $this->colLanguage = new QDataGridColumn(t('Language'), '<?= $_CONTROL->ParentControl->dtgUserRole_LanguageColumn_Render($_ITEM) ?>', array('OrderByClause' => QQ::OrderBy(QQN::NarroUserRole()->Language->LanguageName), 'ReverseOrderByClause' => QQ::OrderBy(QQN::NarroUserRole()->Language->LanguageName, false)));
     $this->colLanguage->HtmlEntities = false;
     $this->colProject = new QDataGridColumn(t('Project'), '<?= $_CONTROL->ParentControl->dtgUserRole_ProjectColumn_Render($_ITEM) ?>', array('OrderByClause' => QQ::OrderBy(QQN::NarroUserRole()->Project->ProjectName), 'ReverseOrderByClause' => QQ::OrderBy(QQN::NarroUserRole()->Project->ProjectName, false)));
     $this->colProject->HtmlEntities = false;
     $this->colRole = new QDataGridColumn(t('Roles'), '<?= $_CONTROL->ParentControl->dtgUserRole_RoleColumn_Render($_ITEM) ?>', array('OrderByClause' => QQ::OrderBy(QQN::NarroUserRole()->Role->RoleName), 'ReverseOrderByClause' => QQ::OrderBy(QQN::NarroUserRole()->Role->RoleName, false)));
     $this->colRole->HtmlEntities = false;
     $this->colActions = new QDataGridColumn(t('Actions'), '<?= $_CONTROL->ParentControl->dtgUserRole_ActionsColumn_Render($_ITEM) ?>');
     $this->colActions->HtmlEntities = false;
     // Setup DataGrid
     $this->dtgUserRole = new NarroDataGrid($this);
     $this->dtgUserRole->Title = sprintf(t('<b>%s</b>\'s roles'), NarroLink::UserProfile($this->objUser->UserId, $this->objUser->RealName));
     $this->dtgUserRole->ShowHeader = true;
     $this->dtgUserRole->Paginator = new QPaginator($this->dtgUserRole);
     $this->dtgUserRole->PaginatorAlternate = new QPaginator($this->dtgUserRole);
     $this->dtgUserRole->ItemsPerPage = QApplication::$User->GetPreferenceValueByName('Items per page');
     // Specify Whether or Not to Refresh using Ajax
     $this->dtgUserRole->UseAjax = QApplication::$UseAjax;
     // Specify the local databind method this datagrid will use
     $this->dtgUserRole->SetDataBinder('dtgUserRole_Bind', $this);
     $this->dtgUserRole->AddColumn($this->colLanguage);
     $this->dtgUserRole->AddColumn($this->colProject);
     $this->dtgUserRole->AddColumn($this->colRole);
     $this->lstLanguage = new QListBox($this);
     $this->lstLanguage->AddItem('Any');
     foreach (NarroLanguage::LoadAllActive(array(QQ::OrderBy(QQN::NarroLanguage()->LanguageName))) as $objNarroLanguage) {
         if (QApplication::HasPermission('Can manage user roles', null, $objNarroLanguage->LanguageId)) {
             $this->blnCanManageSomeRoles = true;
         }
         $this->lstLanguage->AddItem($objNarroLanguage->LanguageName, $objNarroLanguage->LanguageId);
     }
     $this->lstLanguage->SelectedValue = QApplication::GetLanguageId();
     $this->lstProject = new QListBox($this);
     $this->lstProject->AddItem('Any');
     foreach (NarroProject::QueryArray(QQ::Equal(QQN::NarroProject()->Active, 1), array(QQ::OrderBy(QQN::NarroProject()->ProjectName))) as $objNarroProject) {
         if (QApplication::HasPermission('Can manage user roles', $objNarroProject->ProjectId)) {
             $this->blnCanManageSomeRoles = true;
         }
         $this->lstProject->AddItem($objNarroProject->ProjectName, $objNarroProject->ProjectId);
     }
     if (!$this->blnCanManageSomeRoles && QApplication::HasPermission('Can manage user roles')) {
         $this->blnCanManageSomeRoles = true;
     }
     if ($this->blnCanManageSomeRoles) {
         $this->dtgUserRole->AddColumn($this->colActions);
     }
     $this->lstRole = new QListBox($this);
     foreach (NarroRole::LoadAll(array(QQ::OrderBy(QQN::NarroRole()->RoleName))) as $objNarroRole) {
         if ($objNarroRole->RoleName == 'Administrator' && !QApplication::HasPermission('Administrator')) {
             continue;
         }
         $this->lstRole->AddItem($objNarroRole->RoleName, $objNarroRole->RoleId);
     }
     $this->btnAddRole = new QButton($this);
     $this->btnAddRole->Text = t('Add');
     $this->btnAddRole->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnAddRole_Click'));
 }
 /**
  * Refresh this MetaControl with Data from the local NarroRolePermission object.
  * @param boolean $blnReload reload NarroRolePermission from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objNarroRolePermission->Reload();
     }
     if ($this->lblRolePermissionId) {
         if ($this->blnEditMode) {
             $this->lblRolePermissionId->Text = $this->objNarroRolePermission->RolePermissionId;
         }
     }
     if ($this->lstRole) {
         $this->lstRole->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstRole->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objRoleArray = NarroRole::LoadAll();
         if ($objRoleArray) {
             foreach ($objRoleArray as $objRole) {
                 $objListItem = new QListItem($objRole->__toString(), $objRole->RoleId);
                 if ($this->objNarroRolePermission->Role && $this->objNarroRolePermission->Role->RoleId == $objRole->RoleId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstRole->AddItem($objListItem);
             }
         }
     }
     if ($this->lblRoleId) {
         $this->lblRoleId->Text = $this->objNarroRolePermission->Role ? $this->objNarroRolePermission->Role->__toString() : null;
     }
     if ($this->lstPermission) {
         $this->lstPermission->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstPermission->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objPermissionArray = NarroPermission::LoadAll();
         if ($objPermissionArray) {
             foreach ($objPermissionArray as $objPermission) {
                 $objListItem = new QListItem($objPermission->__toString(), $objPermission->PermissionId);
                 if ($this->objNarroRolePermission->Permission && $this->objNarroRolePermission->Permission->PermissionId == $objPermission->PermissionId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstPermission->AddItem($objListItem);
             }
         }
     }
     if ($this->lblPermissionId) {
         $this->lblPermissionId->Text = $this->objNarroRolePermission->Permission ? $this->objNarroRolePermission->Permission->__toString() : null;
     }
 }
 /**
  * Refresh this MetaControl with Data from the local NarroUserRole object.
  * @param boolean $blnReload reload NarroUserRole from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objNarroUserRole->Reload();
     }
     if ($this->lblUserRoleId) {
         if ($this->blnEditMode) {
             $this->lblUserRoleId->Text = $this->objNarroUserRole->UserRoleId;
         }
     }
     if ($this->lstUser) {
         $this->lstUser->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstUser->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objUserArray = NarroUser::LoadAll();
         if ($objUserArray) {
             foreach ($objUserArray as $objUser) {
                 $objListItem = new QListItem($objUser->__toString(), $objUser->UserId);
                 if ($this->objNarroUserRole->User && $this->objNarroUserRole->User->UserId == $objUser->UserId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstUser->AddItem($objListItem);
             }
         }
     }
     if ($this->lblUserId) {
         $this->lblUserId->Text = $this->objNarroUserRole->User ? $this->objNarroUserRole->User->__toString() : null;
     }
     if ($this->lstRole) {
         $this->lstRole->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstRole->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objRoleArray = NarroRole::LoadAll();
         if ($objRoleArray) {
             foreach ($objRoleArray as $objRole) {
                 $objListItem = new QListItem($objRole->__toString(), $objRole->RoleId);
                 if ($this->objNarroUserRole->Role && $this->objNarroUserRole->Role->RoleId == $objRole->RoleId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstRole->AddItem($objListItem);
             }
         }
     }
     if ($this->lblRoleId) {
         $this->lblRoleId->Text = $this->objNarroUserRole->Role ? $this->objNarroUserRole->Role->__toString() : null;
     }
     if ($this->lstProject) {
         $this->lstProject->RemoveAllItems();
         $this->lstProject->AddItem(QApplication::Translate('- Select One -'), null);
         $objProjectArray = NarroProject::LoadAll();
         if ($objProjectArray) {
             foreach ($objProjectArray as $objProject) {
                 $objListItem = new QListItem($objProject->__toString(), $objProject->ProjectId);
                 if ($this->objNarroUserRole->Project && $this->objNarroUserRole->Project->ProjectId == $objProject->ProjectId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstProject->AddItem($objListItem);
             }
         }
     }
     if ($this->lblProjectId) {
         $this->lblProjectId->Text = $this->objNarroUserRole->Project ? $this->objNarroUserRole->Project->__toString() : null;
     }
     if ($this->lstLanguage) {
         $this->lstLanguage->RemoveAllItems();
         $this->lstLanguage->AddItem(QApplication::Translate('- Select One -'), null);
         $objLanguageArray = NarroLanguage::LoadAll();
         if ($objLanguageArray) {
             foreach ($objLanguageArray as $objLanguage) {
                 $objListItem = new QListItem($objLanguage->__toString(), $objLanguage->LanguageId);
                 if ($this->objNarroUserRole->Language && $this->objNarroUserRole->Language->LanguageId == $objLanguage->LanguageId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstLanguage->AddItem($objListItem);
             }
         }
     }
     if ($this->lblLanguageId) {
         $this->lblLanguageId->Text = $this->objNarroUserRole->Language ? $this->objNarroUserRole->Language->__toString() : null;
     }
 }