/** * This Form_Validate event handler allows you to specify any custom Form Validation rules. * It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control. */ protected function Form_Validate() { // By default, we report the result of validation from the parent $blnToReturn = parent::Form_Validate(); // Custom Validation Rules // TODO: Be sure to set $blnToReturn to false if any custom validation fails! // Check for records that may violate Unique Clauses if (($objNarroPermission = NarroPermission::LoadByPermissionName($this->txtPermissionName->Text)) && $objNarroPermission->PermissionId != $this->mctNarroPermission->NarroPermission->PermissionId) { $blnToReturn = false; $this->txtPermissionName->Warning = QApplication::Translate("Already in Use"); } $blnFocused = false; foreach ($this->GetErrorControls() as $objControl) { // Set Focus to the top-most invalid control if (!$blnFocused) { $objControl->Focus(); $blnFocused = true; } // Blink on ALL invalid controls $objControl->Blink(); } return $blnToReturn; }
/** * Default / simple DataBinder for this Meta DataGrid. This can easily be overridden * by calling SetDataBinder() on this DataGrid with another DataBinder of your choice. * * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used. * It will also perform any sorting (if applicable). */ public function MetaDataBinder() { $objConditions = $this->Conditions; if (null !== $this->conAdditionalConditions) { $objConditions = QQ::AndCondition($this->conAdditionalConditions, $objConditions); } // Setup the $objClauses Array $objClauses = array(); if (null !== $this->clsAdditionalClauses) { $objClauses = $this->clsAdditionalClauses; } // Remember! We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below if ($this->Paginator) { $this->TotalItemCount = NarroPermission::QueryCount($objConditions); } // 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->OrderByClause) { array_push($objClauses, $objClause); } // Add the LimitClause information, as well if ($objClause = $this->LimitClause) { array_push($objClauses, $objClause); } // Set the DataSource to be a Query result from NarroPermission, given the clauses above $this->DataSource = NarroPermission::QueryArray($objConditions, $objClauses); }
public static function GetSoapArrayFromArray($objArray) { if (!$objArray) { return null; } $objArrayToReturn = array(); foreach ($objArray as $objObject) { array_push($objArrayToReturn, NarroPermission::GetSoapObjectFromObject($objObject, true)); } return unserialize(serialize($objArrayToReturn)); }
/** * 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; } }
public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects) { if ($objObject->objRole) { $objObject->objRole = NarroRole::GetSoapObjectFromObject($objObject->objRole, false); } else { if (!$blnBindRelatedObjects) { $objObject->intRoleId = null; } } if ($objObject->objPermission) { $objObject->objPermission = NarroPermission::GetSoapObjectFromObject($objObject->objPermission, false); } else { if (!$blnBindRelatedObjects) { $objObject->intPermissionId = null; } } return $objObject; }
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); }
/** * Static Helper Method to Create using PK arguments * You must pass in the PK arguments on an object to load, or leave it blank to create a new one. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to * edit, or if we are also allowed to create a new one, etc. * * @param mixed $objParentObject QForm or QPanel which will be using this NarroPermissionMetaControl * @param integer $intPermissionId primary key value * @param QMetaControlCreateType $intCreateType rules governing NarroPermission object creation - defaults to CreateOrEdit * @return NarroPermissionMetaControl */ public static function Create($objParentObject, $intPermissionId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intPermissionId)) { $objNarroPermission = NarroPermission::Load($intPermissionId); // NarroPermission was found -- return it! if ($objNarroPermission) { return new NarroPermissionMetaControl($objParentObject, $objNarroPermission); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a NarroPermission object with PK arguments: ' . $intPermissionId); } } // If EditOnly is specified, throw an exception } else { if ($intCreateType == QMetaControlCreateType::EditOnly) { throw new QCallerException('No PK arguments specified'); } } // If we are here, then we need to create a new record return new NarroPermissionMetaControl($objParentObject, new NarroPermission()); }