} catch (Exception $objEx) { if (strstr($objEx->getMessage(), 'Duplicate')) { $arrDuplicateTexts = NarroText::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroText()->TextValue, $objText->TextValue), QQ::NotEqual(QQN::NarroText()->TextId, $objText->TextId))); error_log(sprintf('Found duplicates for "%s": %d', $objText->TextValue, count($arrDuplicateTexts))); foreach ($arrDuplicateTexts as $objDuplicateText) { if ($objText->TextValue !== $objDuplicateText->TextValue) { continue; } foreach (NarroTextComment::LoadArrayByTextId($objDuplicateText->TextId) as $objTextComment) { error_log('Moving text comment'); $objTextComment->TextId = $objText->TextId; $objTextComment->Save(); } 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();
/** * 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 = NarroSuggestion::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 NarroSuggestion, given the clauses above $this->DataSource = NarroSuggestion::QueryArray($objConditions, $objClauses); }
/** * Load an array of NarroSuggestion objects, * by TextId, LanguageId Index(es) * @param integer $intTextId * @param integer $intLanguageId * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query * @return NarroSuggestion[] */ public static function LoadArrayByTextIdLanguageId($intTextId, $intLanguageId, $objOptionalClauses = null) { // Call NarroSuggestion::QueryArray to perform the LoadArrayByTextIdLanguageId query try { return NarroSuggestion::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestion()->TextId, $intTextId), QQ::Equal(QQN::NarroSuggestion()->LanguageId, $intLanguageId)), $objOptionalClauses); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } }
/** * 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; } }