Пример #1
0
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, NarroSuggestionVote::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
Пример #2
0
 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.');
 }
Пример #3
0
 /**
  * Counts all associated NarroSuggestionVotesAsContext
  * @return int
  */
 public function CountNarroSuggestionVotesAsContext()
 {
     if (is_null($this->intContextId)) {
         return 0;
     }
     return NarroSuggestionVote::CountByContextId($this->intContextId);
 }
 }
 foreach (NarroSuggestion::LoadArrayByTextId($objDuplicateText->TextId) as $objSuggestion) {
     error_log('Moving text from suggestion');
     $arrDuplicateSuggestions = NarroSuggestion::QueryArray(QQ::AndCondition(QQ::NotEqual(QQN::NarroSuggestion()->SuggestionId, $objSuggestion->SuggestionId), QQ::Equal(QQN::NarroSuggestion()->SuggestionValue, $objSuggestion->SuggestionValue), QQ::Equal(QQN::NarroSuggestion()->TextId, $objText->TextId), QQ::Equal(QQN::NarroSuggestion()->LanguageId, $objSuggestion->LanguageId)));
     if (count($arrDuplicateSuggestions)) {
         error_log(sprintf('Found duplicates for "%s": %d', $objSuggestion->SuggestionValue, count($arrDuplicateSuggestions)));
         foreach ($arrDuplicateSuggestions as $objDuplicateSuggestion) {
             if ($objSuggestion->SuggestionValue !== $objDuplicateSuggestion->SuggestionValue) {
                 continue;
             }
             foreach (NarroSuggestionComment::LoadArrayBySuggestionId($objDuplicateSuggestion->SuggestionId) as $objSuggestionComment) {
                 error_log('Moving suggestion comment');
                 $objSuggestionComment->SuggestionId = $objSuggestion->SuggestionId;
                 $objSuggestionComment->Save();
             }
             foreach (NarroSuggestionVote::LoadArrayBySuggestionId($objDuplicateSuggestion->SuggestionId) as $objSuggestionVote) {
                 error_log('Moving suggestion vote');
                 $objSuggestionVote->SuggestionId = $objSuggestion->SuggestionId;
                 $objSuggestionVote->Save();
             }
             foreach (NarroContextInfo::LoadArrayByValidSuggestionId($objDuplicateSuggestion->SuggestionId) as $objApprovedSuggestion) {
                 error_log('Moving approved suggestion');
                 $objApprovedSuggestion->ValidSuggestionId = $objSuggestion->SuggestionId;
                 $objApprovedSuggestion->Save();
             }
             error_log(sprintf('Deleting suggestion %d %d "%s"', $objDuplicateSuggestion->SuggestionId, $objDuplicateSuggestion->LanguageId, $objDuplicateSuggestion->SuggestionValue));
             $objDuplicateSuggestion->Delete();
             $intDuplicateSuggestionsDeleted++;
         }
     }
     $objSuggestion->TextId = $objText->TextId;
Пример #5
0
 /**
  * Counts all associated NarroSuggestionVotesAsSuggestion
  * @return int
  */
 public function CountNarroSuggestionVotesAsSuggestion()
 {
     if (is_null($this->intSuggestionId)) {
         return 0;
     }
     return NarroSuggestionVote::CountBySuggestionId($this->intSuggestionId);
 }
 /**
  * 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 NarroSuggestionVoteMetaControl
  * @param integer $intSuggestionId primary key value
  * @param integer $intContextId primary key value
  * @param integer $intUserId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing NarroSuggestionVote object creation - defaults to CreateOrEdit
  * @return NarroSuggestionVoteMetaControl
  */
 public static function Create($objParentObject, $intSuggestionId = null, $intContextId = null, $intUserId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intSuggestionId) && strlen($intContextId) && strlen($intUserId)) {
         $objNarroSuggestionVote = NarroSuggestionVote::Load($intSuggestionId, $intContextId, $intUserId);
         // NarroSuggestionVote was found -- return it!
         if ($objNarroSuggestionVote) {
             return new NarroSuggestionVoteMetaControl($objParentObject, $objNarroSuggestionVote);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a NarroSuggestionVote object with PK arguments: ' . $intSuggestionId . ', ' . $intContextId . ', ' . $intUserId);
             }
         }
         // 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 NarroSuggestionVoteMetaControl($objParentObject, new NarroSuggestionVote());
 }
Пример #7
0
 /**
  * Counts all associated NarroSuggestionVotesAsUser
  * @return int
  */
 public function CountNarroSuggestionVotesAsUser()
 {
     if (is_null($this->intUserId)) {
         return 0;
     }
     return NarroSuggestionVote::CountByUserId($this->intUserId);
 }
Пример #8
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;
             }
     }
 }
 /**
  * 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 = NarroSuggestionVote::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 NarroSuggestionVote, given the clauses above
     $this->DataSource = NarroSuggestionVote::QueryArray($objConditions, $objClauses);
 }
Пример #10
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;
     }
 }
 /**
  * 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 (($objNarroSuggestionVote = NarroSuggestionVote::LoadBySuggestionIdUserIdContextId($this->lstSuggestion->SelectedValue, $this->lstUser->SelectedValue, $this->lstContext->SelectedValue)) && $objNarroSuggestionVote->SuggestionId != $this->mctNarroSuggestionVote->NarroSuggestionVote->SuggestionId && $objNarroSuggestionVote->ContextId != $this->mctNarroSuggestionVote->NarroSuggestionVote->ContextId && $objNarroSuggestionVote->UserId != $this->mctNarroSuggestionVote->NarroSuggestionVote->UserId) {
         $blnToReturn = false;
         $this->lstSuggestion->Warning = QApplication::Translate("Already in Use");
         $this->lstUser->Warning = QApplication::Translate("Already in Use");
         $this->lstContext->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;
 }