protected function Form_Create()
 {
     parent::Form_Create();
     // Instantiate the Meta DataGrid
     $this->dtgNarroSuggestionVotes = new NarroSuggestionVoteDataGrid($this);
     // Style the DataGrid (if desired)
     $this->dtgNarroSuggestionVotes->CssClass = 'datagrid';
     $this->dtgNarroSuggestionVotes->AlternateRowStyle->CssClass = 'alternate';
     // Add Pagination (if desired)
     $this->dtgNarroSuggestionVotes->Paginator = new QPaginator($this->dtgNarroSuggestionVotes);
     $this->dtgNarroSuggestionVotes->ItemsPerPage = __FORM_DRAFTS_FORM_LIST_ITEMS_PER_PAGE__;
     // Use the MetaDataGrid functionality to add Columns for this datagrid
     // Create an Edit Column
     $strEditPageUrl = __VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/narro_suggestion_vote_edit.php';
     $this->dtgNarroSuggestionVotes->MetaAddEditLinkColumn($strEditPageUrl, 'Edit', 'Edit');
     // Create the Other Columns (note that you can use strings for narro_suggestion_vote's properties, or you
     // can traverse down QQN::narro_suggestion_vote() to display fields that are down the hierarchy)
     $this->dtgNarroSuggestionVotes->MetaAddColumn(QQN::NarroSuggestionVote()->Suggestion);
     $this->dtgNarroSuggestionVotes->MetaAddColumn(QQN::NarroSuggestionVote()->Context);
     $this->dtgNarroSuggestionVotes->MetaAddColumn(QQN::NarroSuggestionVote()->User);
     $this->dtgNarroSuggestionVotes->MetaAddColumn('VoteValue');
     $this->dtgNarroSuggestionVotes->MetaAddColumn('Created');
     $this->dtgNarroSuggestionVotes->MetaAddColumn('Modified');
 }
 public function btnVote_Click($strFormId, $strControlId, $strParameter)
 {
     if (!QApplication::HasPermissionForThisLang('Can vote', $this->objContextInfo->Context->ProjectId)) {
         return false;
     }
     $objNarroSuggestionVote = NarroSuggestionVote::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestionVote()->ContextId, $this->objContextInfo->ContextId), QQ::Equal(QQN::NarroSuggestionVote()->SuggestionId, $strParameter), QQ::Equal(QQN::NarroSuggestionVote()->UserId, QApplication::GetUserId())));
     if (!$objNarroSuggestionVote) {
         $objNarroSuggestionVote = new NarroSuggestionVote();
         $objNarroSuggestionVote->SuggestionId = $strParameter;
         $objNarroSuggestionVote->ContextId = $this->objContextInfo->ContextId;
         $objNarroSuggestionVote->UserId = QApplication::GetUserId();
         $objNarroSuggestionVote->Created = QDateTime::Now();
     }
     if (strpos($strControlId, 'votdn') === 0) {
         $objNarroSuggestionVote->VoteValue = -1;
     } else {
         $objNarroSuggestionVote->VoteValue = 1;
     }
     $objNarroSuggestionVote->Modified = QDateTime::Now();
     $objNarroSuggestionVote->Save();
     $this->objContextInfo->Modified = QDateTime::Now();
     $this->objContextInfo->Save();
     if ($this->ParentControl->ParentControl->chkRefresh->Checked && $strControlId != $this->btnKeepUntranslated->ControlId) {
         $this->ParentControl->ParentControl->btnSearch_Click();
     }
     $this->lblText->Warning = t('Thank you for your vote. You can change it anytime by voting another suggestion.');
 }
 /**
  * Count NarroSuggestionVotes
  * by ContextId Index(es)
  * @param integer $intContextId
  * @return int
  */
 public static function CountByContextId($intContextId)
 {
     // Call NarroSuggestionVote::QueryCount to perform the CountByContextId query
     return NarroSuggestionVote::QueryCount(QQ::Equal(QQN::NarroSuggestionVote()->ContextId, $intContextId));
 }
示例#4
0
 public function __get($strName)
 {
     switch ($strName) {
         case 'Votes':
             $mixResult = NarroSuggestionVote::QuerySingle(QQ::Equal(QQN::NarroSuggestionVote()->SuggestionId, $this->SuggestionId), array(QQ::Sum(QQN::NarroSuggestionVote()->VoteValue, 'votes'), QQ::GroupBy(QQN::NarroSuggestionVote()->SuggestionId)));
             if ($mixResult instanceof NarroSuggestionVote) {
                 return $mixResult->GetVirtualAttribute('votes');
             } else {
                 return 0;
             }
         default:
             try {
                 return parent::__get($strName);
                 break;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
     }
 }
 /**
  * Used internally by the Meta-based Add Column tools.
  *
  * Given a QQNode or a Text String, this will return a NarroSuggestionVote-based QQNode.
  * It will also verify that it is a proper NarroSuggestionVote-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_suggestion_vote') {
             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_suggestion_vote".');
         }
     } else {
         if (is_string($mixContent)) {
             switch ($mixContent) {
                 case 'SuggestionId':
                     return QQN::NarroSuggestionVote()->SuggestionId;
                 case 'Suggestion':
                     return QQN::NarroSuggestionVote()->Suggestion;
                 case 'ContextId':
                     return QQN::NarroSuggestionVote()->ContextId;
                 case 'Context':
                     return QQN::NarroSuggestionVote()->Context;
                 case 'UserId':
                     return QQN::NarroSuggestionVote()->UserId;
                 case 'User':
                     return QQN::NarroSuggestionVote()->User;
                 case 'VoteValue':
                     return QQN::NarroSuggestionVote()->VoteValue;
                 case 'Created':
                     return QQN::NarroSuggestionVote()->Created;
                 case 'Modified':
                     return QQN::NarroSuggestionVote()->Modified;
                 default:
                     throw new QCallerException('Simple Property not found in NarroSuggestionVoteDataGrid 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');
             }
         }
     }
 }
 protected function dtgVotes_Create()
 {
     $dtgVotes = new NarroSuggestionVoteDataGrid($this->tabActivity);
     $dtgVotes->SetCustomStyle('padding', '5px');
     $dtgVotes->Title = sprintf(t('Votes added by <b>%s</b>'), $this->objUser->RealName);
     $colSuggestion = $dtgVotes->MetaAddColumn(QQN::NarroSuggestionVote()->Suggestion->SuggestionValue);
     $colSuggestion->Name = t('Translation');
     $colSuggestion->Html = '<?= $_CONTROL->colSuggestion_Render($_ITEM); ?>';
     $colSuggestion->HtmlEntities = false;
     $colVote = $dtgVotes->MetaAddColumn(QQN::NarroSuggestionVote()->VoteValue);
     $colVote->Name = t('Vote');
     $colVote->Html = '<?= $_ITEM->VoteValue; ?>';
     $colCreated = $dtgVotes->MetaAddColumn(QQN::NarroSuggestionVote()->Created);
     $colCreated->Name = t('Added');
     $colCreated->FilterType = QFilterType::None;
     $colCreated->Html = '<?= $_CONTROL->colCreated_Render($_ITEM); ?>';
     $colCreated->HtmlEntities = false;
     $colCreated->Wrap = false;
     // Datagrid Paginator
     $dtgVotes->Paginator = new QPaginator($dtgVotes);
     $dtgVotes->ItemsPerPage = QApplication::$User->GetPreferenceValueByName('Items per page');
     // Specify Whether or Not to Refresh using Ajax
     $dtgVotes->UseAjax = true;
     $dtgVotes->SortColumnIndex = 2;
     $dtgVotes->SortDirection = true;
     $dtgVotes->AdditionalClauses = array(QQ::Expand(QQN::NarroSuggestionVote()->Suggestion));
     $dtgVotes->AdditionalConditions = QQ::Equal(QQN::NarroSuggestionVote()->UserId, $this->objUser->UserId);
     $dtgVotes->btnFilter_Click($this->Form->FormId, $dtgVotes->FilterButton->ControlId, '');
 }
示例#7
0
 /**
  * Get the suggestion made by a specified user
  *
  * @param integer $intContextId
  * @param integer $intTextId
  * @param integer $intUserId
  * @return NarroSuggestion
  */
 public function GetUserSuggestion($intContextId, $intTextId, $intUserId)
 {
     $arrSuggestion = NarroSuggestion::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestion()->UserId, $intUserId), QQ::Equal(QQN::NarroSuggestion()->TextId, $intTextId), QQ::Equal(QQN::NarroSuggestion()->LanguageId, $this->objTargetLanguage->LanguageId)));
     if (count($arrSuggestion) == 1) {
         return $arrSuggestion[0];
     } elseif (count($arrSuggestion) > 1) {
         /**
          * if there are more suggestions for a user, get the one that he has voted for
          */
         $objSuggestionVote = NarroSuggestionVote::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestionVote()->UserId, $intUserId), QQ::Equal(QQN::NarroSuggestionVote()->ContextId, $intContextId), QQ::Equal(QQN::NarroSuggestionVote()->Context->NarroContextInfoAsContext->LanguageId, $this->objTargetLanguage->LanguageId)));
         if ($objSuggestionVote) {
             return NarroSuggestion::Load($objSuggestionVote->SuggestionId);
         } else {
             /**
              * the user has more suggestions but has voted none
              */
             return false;
         }
     } else {
         /**
          * The user has no suggestions for this text
          */
         return false;
     }
 }