public function btnSave_Click()
 {
     if (trim($this->txtComment->Text)) {
         $objComment = new NarroTextComment();
         $objComment->UserId = QApplication::GetUserId();
         $objComment->LanguageId = QApplication::GetLanguageId();
         $objComment->TextId = $this->intTextId;
         $objComment->Created = QDateTime::Now();
         $objComment->CommentText = $this->txtComment->Text;
         $objComment->CommentTextMd5 = md5($objComment->CommentText);
         $objComment->Save();
         $this->dtgComments->Refresh();
     }
 }
$intDuplicateTextsDeleted = 0;
foreach (NarroText::LoadAll() as $intVal => $objText) {
    if ($objText->TextValueMd5 == md5($objText->TextValue)) {
        continue;
    }
    try {
        $objText->Save();
    } 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');
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, NarroTextComment::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
示例#4
0
 /**
  * Counts all associated NarroTextCommentsAsText
  * @return int
  */
 public function CountNarroTextCommentsAsText()
 {
     if (is_null($this->intTextId)) {
         return 0;
     }
     return NarroTextComment::CountByTextId($this->intTextId);
 }
示例#5
0
 /**
  * Counts all associated NarroTextCommentsAsUser
  * @return int
  */
 public function CountNarroTextCommentsAsUser()
 {
     if (is_null($this->intUserId)) {
         return 0;
     }
     return NarroTextComment::CountByUserId($this->intUserId);
 }
 /**
  * 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 = NarroTextComment::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 NarroTextComment, given the clauses above
     $this->DataSource = NarroTextComment::QueryArray($objConditions, $objClauses);
 }
 /**
  * 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 NarroTextCommentMetaControl
  * @param integer $intTextCommentId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing NarroTextComment object creation - defaults to CreateOrEdit
  * @return NarroTextCommentMetaControl
  */
 public static function Create($objParentObject, $intTextCommentId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intTextCommentId)) {
         $objNarroTextComment = NarroTextComment::Load($intTextCommentId);
         // NarroTextComment was found -- return it!
         if ($objNarroTextComment) {
             return new NarroTextCommentMetaControl($objParentObject, $objNarroTextComment);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a NarroTextComment object with PK arguments: ' . $intTextCommentId);
             }
         }
         // 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 NarroTextCommentMetaControl($objParentObject, new NarroTextComment());
 }
示例#8
0
 /**
  * Counts all associated NarroTextCommentsAsLanguage
  * @return int
  */
 public function CountNarroTextCommentsAsLanguage()
 {
     if (is_null($this->intLanguageId)) {
         return 0;
     }
     return NarroTextComment::CountByLanguageId($this->intLanguageId);
 }
示例#9
0
文件: rss.php 项目: Jobava/narro
 }
 if (!($objRssFeed = QApplication::$Cache->load($strCacheId))) {
     if (isset($objProject) && $objProject instanceof NarroProject) {
         $objRssFeed = new QRssFeed(sprintf(t('Comments on texts from %s'), $objProject->ProjectName), __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__, sprintf(t('Get the latest debates on texts from the project %s'), $objProject->ProjectName));
     } else {
         $objRssFeed = new QRssFeed(t('Comments on texts'), __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__, t('Get the latest debates on texts'));
     }
     if (isset($objProject) && $objProject instanceof NarroProject) {
         $strSqlQuery = sprintf('SELECT DISTINCT narro_text_comment.* FROM narro_text_comment, narro_context WHERE narro_text_comment.text_id=narro_context.text_id AND narro_context.active=1 AND narro_context.project_id=%d AND narro_text_comment.language_id=%d ORDER BY created DESC LIMIT 0, 20', $objProject->ProjectId, QApplication::GetLanguageId());
     } else {
         $strSqlQuery = sprintf('SELECT DISTINCT narro_text_comment.* FROM narro_text_comment WHERE narro_text_comment.language_id=%d ORDER BY created DESC LIMIT 0, 20', QApplication::GetLanguageId());
     }
     $objDatabase = QApplication::$Database[1];
     $objDbResult = $objDatabase->Query($strSqlQuery);
     if ($objDbResult) {
         $arrTextComment = NarroTextComment::InstantiateDbResult($objDbResult);
         foreach ($arrTextComment as $objTextComment) {
             if (isset($objProject) && $objProject instanceof NarroProject) {
                 $arrContext = NarroContext::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContext()->ProjectId, $objProject->ProjectId), QQ::Equal(QQN::NarroContext()->TextId, $objTextComment->TextId), QQ::Equal(QQN::NarroContext()->Active, 1)));
             } else {
                 $arrContext = NarroContext::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContext()->TextId, $objTextComment->TextId), QQ::Equal(QQN::NarroContext()->Active, 1)));
             }
             if (count($arrContext)) {
                 $arrProjectLinks = array();
                 $arrProjects = array();
                 $strDescription = sprintf('
                         <span style="font-size:80%%;color:gray;">' . t('%s wrote on %s:') . '</span>
                         <br />
                         <span style="margin-left:5px;padding:3px;">%s</span>', NarroLink::UserProfile($objTextComment->UserId, '<b>' . $objTextComment->User->RealName . '</b>'), $objTextComment->Created, nl2br($objTextComment->CommentText));
                 foreach ($arrContext as $objContext) {
                     $arrProjects[$objContext->ProjectId] = $objContext->Project->ProjectName;