public function __construct($objParentObject, $strControlId = null) { // Call the Parent try { parent::__construct($objParentObject, $strControlId); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } $this->strTemplate = __NARRO_INCLUDES__ . '/narro/panel/NarroRoleListPanel.tpl.php'; $this->pnlRolePermissions = new NarroRolePermissionPanel($this); if (QApplication::QueryString('r')) { $this->pnlRolePermissions->Role = NarroRole::Load(QApplication::QueryString('r')); } $this->pnlRoleUsers = new NarroRoleUserListPanel($this); if ($this->pnlRolePermissions->Role instanceof NarroRole) { $this->pnlRoleUsers->Role = $this->pnlRolePermissions->Role; } switch (QApplication::QueryString('view')) { case 'permission': $this->pnlRolePermissions->Display = QDisplayStyle::Inline; $this->pnlRoleUsers->Display = QDisplayStyle::None; break; case 'user': $this->pnlRolePermissions->Display = QDisplayStyle::None; $this->pnlRoleUsers->Display = QDisplayStyle::Inline; break; default: $this->pnlRolePermissions->Display = QDisplayStyle::None; $this->pnlRoleUsers->Display = QDisplayStyle::None; } // Setup DataGrid Columns $this->colRoleName = new QDataGridColumn(t('Role'), '<?= $_CONTROL->ParentControl->dtgRole_RoleNameColumn_Render($_ITEM) ?>', array('OrderByClause' => QQ::OrderBy(QQN::NarroRole()->RoleName), 'ReverseOrderByClause' => QQ::OrderBy(QQN::NarroRole()->RoleName, false))); $this->colRoleName->HtmlEntities = false; $this->colActions = new QDataGridColumn(t('Actions'), '<?= $_CONTROL->ParentControl->dtgRole_Actions_Render($_ITEM) ?>'); $this->colActions->HtmlEntities = false; // Setup DataGrid $this->dtgRole = new NarroDataGrid($this); $this->dtgRole->Title = t('Roles'); // Specify Whether or Not to Refresh using Ajax $this->dtgRole->UseAjax = false; // Specify the local databind method this datagrid will use $this->dtgRole->SetDataBinder('dtgRole_Bind', $this); $this->dtgRole->AddColumn($this->colRoleName); $this->dtgRole->AddColumn($this->colActions); $this->dtgRole->SortColumnIndex = 0; }
/** * Used internally by the Meta-based Add Column tools. * * Given a QQNode or a Text String, this will return a NarroRole-based QQNode. * It will also verify that it is a proper NarroRole-based QQNode, and will throw an exception otherwise. * * @param mixed $mixContent * @return QQNode */ protected function ResolveContentItem($mixContent) { if ($mixContent instanceof QQNode) { if (!$mixContent->_ParentNode) { throw new QCallerException('Content QQNode cannot be a Top Level Node'); } if ($mixContent->_RootTableName == 'narro_role') { if ($mixContent instanceof QQReverseReferenceNode && !$mixContent->_PropertyName) { throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.'); } $objCurrentNode = $mixContent; while ($objCurrentNode = $objCurrentNode->_ParentNode) { if (!$objCurrentNode instanceof QQNode) { throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.'); } if ($objCurrentNode instanceof QQReverseReferenceNode && !$objCurrentNode->_PropertyName) { throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.'); } } return $mixContent; } else { throw new QCallerException('Content QQNode has a root table of "' . $mixContent->_RootTableName . '". Must be a root of "narro_role".'); } } else { if (is_string($mixContent)) { switch ($mixContent) { case 'RoleId': return QQN::NarroRole()->RoleId; case 'RoleName': return QQN::NarroRole()->RoleName; default: throw new QCallerException('Simple Property not found in NarroRoleDataGrid content: ' . $mixContent); } } else { if ($mixContent instanceof QQAssociationNode) { throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.'); } else { throw new QCallerException('Invalid Content type'); } } } }
private function CreateNarroTemplate($intProjectId) { $strPoFile = __DOCROOT__ . __SUBDIRECTORY__ . '/locale/' . $this->objSourceLanguage->LanguageCode . '/narro.po'; NarroLogger::LogInfo(sprintf('Building a narro gettext template in %s.', $strPoFile)); $arrPermissions = NarroPermission::QueryArray(QQ::All(), QQ::Clause(QQ::OrderBy(QQN::NarroPermission()->PermissionName))); NarroLogger::LogInfo(sprintf('Found %d permission names to localize.', count($arrPermissions))); $arrRoles = NarroRole::QueryArray(QQ::All(), QQ::Clause(QQ::OrderBy(QQN::NarroRole()->RoleName))); NarroLogger::LogInfo(sprintf('Found %d role names to localize.', count($arrRoles))); $allFiles = NarroUtils::ListDirectory(realpath(dirname(__FILE__) . '/../../..'), null, '/.*\\/drafts\\/.*|.*\\/data\\/.*|.*\\/examples\\/.*|.*\\/qcubed_generated\\/.*/'); NarroLogger::LogInfo(sprintf('Found %d php files to search for localizable messages.', count($allFiles))); foreach ($allFiles as $strFileName) { if (pathinfo($strFileName, PATHINFO_EXTENSION) != 'php') { continue; } $strFile = file_get_contents($strFileName); $strShortPath = str_ireplace(realpath(__DOCROOT__ . __SUBDIRECTORY__) . '/', '', $strFileName); if (strpos($strShortPath, 'data') === 0) { continue; } if (strpos($strShortPath, 'includes/qcubed_generated') === 0) { continue; } $strFile = str_replace("\\'", "&&&escapedsimplequote&&&", $strFile); $strFile = str_replace('\\"', "&&&escapeddoublequote&&&", $strFile); if ($strFile) { preg_match_all('/([^a-zA-Z]t|NarroApp::Translate|QApplication::Translate|__t)\\s*\\(\\s*[\']([^\']{2,})[\']\\s*\\)/', $strFile, $arrMatches); if (isset($arrMatches[2])) { foreach ($arrMatches[2] as $intMatchNo => $strText) { if (trim($strText) != '') { $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText); $arrMessages[md5($strText)]['text'] = $strText; $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath; $strSearchText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $arrMatches[0][$intMatchNo]); preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches); $arrMessages[md5($strText)]['context'] = '#. '; foreach ($arrFullMatches[0] as $strFullMatch) { if (trim($strFullMatch)) { $arrMessages[md5($strText)]['context'] .= trim($strFullMatch) . "\n"; } } } } } preg_match_all('/([^a-zA-Z]t|NarroApp::Translate|QApplication::Translate|__t)\\s*\\(\\s*[\\"]([^\\"]{2,})[\\"]\\s*\\)/', $strFile, $arrMatches); if (isset($arrMatches[2])) { foreach ($arrMatches[2] as $intMatchNo => $strText) { if (trim($strText) != '') { $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText); $arrMessages[md5($strText)]['text'] = $strText; $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath; $strSearchText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $arrMatches[0][$intMatchNo]); preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches); $arrMessages[md5($strText)]['context'] = '#. '; foreach ($arrFullMatches[0] as $strFullMatch) { if (trim($strFullMatch)) { $arrMessages[md5($strText)]['context'] .= trim($strFullMatch) . "\n"; } } } } } preg_match_all('/([^a-zA-Z]t|NarroApp::Translate|QApplication::Translate|__t)\\s*\\(\\s*[\']([^\']{2,})[\']\\s*,\\s*[\']([^\']{2,})[\']\\s*,\\s*([^\\)]+)\\s*\\)/', $strFile, $arrMatches); if (isset($arrMatches[2])) { foreach ($arrMatches[2] as $intMatchNo => $strText) { if (trim($strText) != '') { $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText); $arrMessages[md5($strText)]['text'] = $strText; $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath; $arrMessages[md5($strText)]['plural'] = $arrMatches[3][$intMatchNo]; $strSearchText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $arrMatches[0][$intMatchNo]); preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches); $arrMessages[md5($strText)]['context'] = '#. '; foreach ($arrFullMatches[0] as $strFullMatch) { if (trim($strFullMatch)) { $arrMessages[md5($strText)]['context'] .= trim($strFullMatch) . "\n"; } } } } } preg_match_all('/([^a-zA-Z]t|NarroApp::Translate|QApplication::Translate|__t)\\s*\\(\\s*[\\"]([^\\"]{2,})[\\"]\\s*,\\s*[\\"]([^\\"]{2,})[\\"]\\s*,\\s*([^\\)]+)\\s*\\)/', $strFile, $arrMatches); if (isset($arrMatches[2])) { foreach ($arrMatches[2] as $intMatchNo => $strText) { if (trim($strText) != '') { $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText); $arrMessages[md5($strText)]['text'] = $strText; $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath; $arrMessages[md5($strText)]['plural'] = $arrMatches[3][$intMatchNo]; $strSearchText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $arrMatches[0][$intMatchNo]); preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches); $arrMessages[md5($strText)]['context'] = '#. '; foreach ($arrFullMatches[0] as $strFullMatch) { if (trim($strFullMatch)) { $arrMessages[md5($strText)]['context'] .= trim($strFullMatch) . "\n"; } } } } } preg_match_all('/NarroApp::RegisterPreference\\(\\s*\'([^\']+)\'\\s*,\\s*\'[^\']+\'\\s*,\\s*\'([^\']+)\'\\s*,\\s*/', $strFile, $arrMatches); if (isset($arrMatches[1])) { foreach ($arrMatches[1] as $intMatchNo => $strText) { if (trim($strText) != '') { $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText); $arrMessages[md5($strText)]['text'] = $strText; $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath; $strSearchText = $arrMatches[0][$intMatchNo]; preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches); $arrMessages[md5($strText)]['context'] = "#. Preference name\n"; foreach ($arrFullMatches[0] as $strLine) { if (isset($strLine) && trim($strLine)) { $arrMessages[md5($strText)]['context'] .= trim($strLine) . "\n"; } } } } foreach ($arrMatches[2] as $intMatchNo => $strText) { if (trim($strText) != '') { $strText = str_replace(array("&&&escapedsimplequote&&&", "&&&escapeddoublequote&&&"), array("'", '\\"'), $strText); $arrMessages[md5($strText)]['text'] = $strText; $arrMessages[md5($strText)]['files'][$strShortPath] = $strShortPath; $strSearchText = $arrMatches[0][$intMatchNo]; preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches); $arrMessages[md5($strText)]['context'] = "#. Preference description\n"; foreach ($arrFullMatches[0] as $strLine) { if (isset($strLine) && trim($strLine)) { $arrMessages[md5($strText)]['context'] .= trim($strLine) . "\n"; } } } } } if (preg_match_all('/t\\(\\$[a-zA-Z]+\\-\\>LanguageName/', $strFile, $arrMatches)) { if (!isset($arrLanguages)) { $arrLanguages = NarroLanguage::QueryArray(QQ::All(), QQ::Clause(QQ::OrderBy(QQN::NarroLanguage()->LanguageName))); } $strLangContext = '#. '; foreach ($arrMatches as $intMatchNo => $arrVal) { $strSearchText = $arrMatches[0][$intMatchNo]; preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches); foreach ($arrFullMatches[0] as $strLine) { if (isset($strLine) && trim($strLine)) { $strLangContext .= trim($strLine) . "\n"; } } } if (is_array($arrLanguages)) { foreach ($arrLanguages as $objLanguage) { $arrMessages[md5($objLanguage->LanguageName)]['text'] = $objLanguage->LanguageName; $arrMessages[md5($objLanguage->LanguageName)]['files'][$strShortPath] = $strShortPath; $arrMessages[md5($objLanguage->LanguageName)]['context'] = $strLangContext; } } } if (preg_match_all('/t\\(\\$[a-zA-Z]+\\-\\>RoleName/', $strFile, $arrMatches)) { $strLangContext = '#. '; foreach ($arrMatches as $intMatchNo => $arrVal) { $strSearchText = $arrMatches[0][$intMatchNo]; preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches); foreach ($arrFullMatches[0] as $strLine) { if (isset($strLine) && trim($strLine)) { $strLangContext .= trim($strLine) . "\n"; } } } if (is_array($arrRoles)) { foreach ($arrRoles as $objRole) { $arrMessages[md5($objRole->RoleName)]['text'] = $objRole->RoleName; $arrMessages[md5($objRole->RoleName)]['files'][$strShortPath] = $strShortPath; $arrMessages[md5($objRole->RoleName)]['context'] = $strLangContext; } } } if (preg_match_all('/t\\(\\$[a-zA-Z]+\\-\\>PermissionName/', $strFile, $arrMatches)) { $strLangContext = '#. '; foreach ($arrMatches as $intMatchNo => $arrVal) { $strSearchText = $arrMatches[0][$intMatchNo]; preg_match_all('/^.*' . preg_quote($strSearchText, '/') . '.*$/m', $strFile, $arrFullMatches); foreach ($arrFullMatches[0] as $strLine) { if (isset($strLine) && trim($strLine)) { $strLangContext .= trim($strLine) . "\n"; } } } if (is_array($arrPermissions)) { foreach ($arrPermissions as $objPermission) { $arrMessages[md5($objPermission->PermissionName)]['text'] = $objPermission->PermissionName; $arrMessages[md5($objPermission->PermissionName)]['files'][$strShortPath] = $strShortPath; $arrMessages[md5($objPermission->PermissionName)]['context'] = $strLangContext; } } } } } $strPoHeader = '#, fuzzy' . "\n" . 'msgid ""' . "\n" . 'msgstr ""' . "\n" . '"Project-Id-Version: Narro ' . NARRO_VERSION . "\n" . '"Report-Msgid-Bugs-To: alexxed@gmail.com\\n"' . "\n" . '"POT-Creation-Date: ' . date('Y-d-m H:iO') . '\\n"' . "\n" . '"PO-Revision-Date: ' . date('Y-d-m H:iO') . '\\n"' . "\n" . '"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"' . "\n" . '"Language-Team: LANGUAGE <*****@*****.**>\\n"' . "\n" . '"MIME-Version: 1.0\\n"' . "\n" . '"Content-Type: text/plain; charset=UTF-8\\n"' . "\n" . '"Content-Transfer-Encoding: 8bit\\n"' . "\n" . '"Plural-Forms: nplurals=2; plural=n != 1;\\n"' . "\n" . '"X-Generator: Narro\\n"' . "\n"; $hndFile = fopen($strPoFile, 'w'); if (!$hndFile) { NarroLogger::LogError(sprintf('Error while opening the po file "%s" for writing.', $strPoFile)); } fputs($hndFile, $strPoHeader); // Obtain a list of columns foreach ($arrMessages as $key => $row) { $texts[$key] = $row['text']; } //array_multisort($texts, SORT_ASC, SORT_STRING, $arrMessages); foreach ($arrMessages as $intKey => $arrMsgData) { if (isset($arrMsgData['plural'])) { fputs($hndFile, sprintf("#: %s\nmsgid \"%s\"\nmsgid_plural \"%s\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n\n", join(' ', array_values($arrMsgData['files'])), str_replace(array('"', "\n"), array('\\"', '\\n'), $arrMsgData['text']), str_replace(array('"', "\n"), array('\\"', '\\n'), $arrMsgData['plural']))); } else { if (!isset($arrMsgData['files'])) { print_r($arrMsgData); } else { fputs($hndFile, sprintf("%s\n#: %s\nmsgid \"%s\"\nmsgstr \"\"\n\n", isset($arrMsgData['context']) ? str_replace("\n", "\n#. ", trim($arrMsgData['context'])) . '' : '', join(' ', array_values($arrMsgData['files'])), str_replace(array('"', "\n"), array('\\"', '\\n'), $arrMsgData['text']))); } } } fclose($hndFile); NarroUtils::Chmod($strPoFile, 0666); NarroLogger::LogInfo('Wrote a new Narro template file in ' . $strPoFile); }
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')); }
/** * Load a single NarroRole object, * by RoleName Index(es) * @param string $strRoleName * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query * @return NarroRole */ public static function LoadByRoleName($strRoleName, $objOptionalClauses = null) { return NarroRole::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroRole()->RoleName, $strRoleName)), $objOptionalClauses); }