Changeset 55 for trunk/lib

Show
Ignore:
Timestamp:
12/20/05 11:44:03 (3 years ago)
Author:
fabien
Message:

day 20 modifications

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/model/Answer.php

    r23 r55  
    3939    $this->setHtmlBody(markdown($v)); 
    4040  } 
     41 
     42  public function deleteReports() 
     43  { 
     44    $reports = $this->getReportQuestions(); 
     45    foreach ($reports as $report) 
     46    { 
     47      $report->delete(); 
     48    } 
     49 
     50    $this->setReports(0); 
     51  } 
     52 
     53  public function deleteSpam($moderator) 
     54  { 
     55    $con = Propel::getConnection(); 
     56    try 
     57    { 
     58      $con->begin(); 
     59 
     60      $user = $this->getUser(); 
     61      if ($user->getNickname() != 'anonymous') 
     62      { 
     63        $user->setDeletions($user->getDeletions() + 1); 
     64        $user->save(); 
     65      } 
     66 
     67      $this->delete(); 
     68 
     69      $con->commit(); 
     70 
     71      $log = 'moderator "%s" deleted answer "%s" for question "%s" (%s)'; 
     72      $log = sprintf($log, $moderator->getNickname(), $this->getId(), $this->getQuestion()->getTitle(), substr($this->getBody(), 0, 50)); 
     73      sfContext::getInstance()->getLogger()->warning($log); 
     74    } 
     75    catch (PropelException $e) 
     76    { 
     77      $con->rollback(); 
     78      throw $e; 
     79    } 
     80  } 
    4181} 
    4282 
  • trunk/lib/model/AnswerPeer.php

    r40 r55  
    5050  } 
    5151 
    52   public function getRecent($max = 10) 
     52  public static function getRecent($max = 10) 
    5353  { 
    5454    $c = new Criteria(); 
     
    5858 
    5959    return self::doSelectJoinUser($c); 
     60  } 
     61 
     62  public static function getReportedSpamPager($page) 
     63  { 
     64    $pager = new sfPager('Answer', APP_PAGER_HOMEPAGE_MAX); 
     65    $c = new Criteria(); 
     66    $c->add(self::REPORTS, 0, Criteria::GREATER_THAN); 
     67    $c->setLimit(20); 
     68    $c->addDescendingOrderByColumn(self::REPORTS); 
     69    $c->addAscendingOrderByColumn(self::CREATED_AT); 
     70    $c = self::addPermanentTagToCriteria($c); 
     71    $pager->setCriteria($c); 
     72    $pager->setPage($page); 
     73    $pager->setPeerMethod('doSelectJoinUser'); 
     74    $pager->init(); 
     75 
     76    return $pager; 
     77  } 
     78 
     79  public static function getReportCount() 
     80  { 
     81    $c = new Criteria(); 
     82    $c->add(self::REPORTS, 0, Criteria::GREATER_THAN); 
     83    $c = self::addPermanentTagToCriteria($c); 
     84 
     85    return self::doCount($c); 
    6086  } 
    6187 
  • trunk/lib/model/Question.php

    r42 r55  
    145145    $c->addAsColumn('relevancy', AnswerPeer::RELEVANCY_UP.' / ('.AnswerPeer::RELEVANCY_UP.' + '.AnswerPeer::RELEVANCY_DOWN.')'); 
    146146    $c->addDescendingOrderByColumn('relevancy'); 
     147    $c->addDescendingOrderByColumn(AnswerPeer::RELEVANCY_UP); 
    147148 
    148149    return AnswerPeer::doSelect($c); 
     150  } 
     151 
     152  public function deleteReports() 
     153  { 
     154    $reports = $this->getReportQuestions(); 
     155    foreach ($reports as $report) 
     156    { 
     157      $report->delete(); 
     158    } 
     159 
     160    $this->setReports(0); 
     161  } 
     162 
     163  public function deleteSpam($moderator) 
     164  { 
     165    $con = Propel::getConnection(); 
     166    try 
     167    { 
     168      $con->begin(); 
     169 
     170      $user = $this->getUser(); 
     171      $user->setDeletions($user->getDeletions() + 1); 
     172      $user->save(); 
     173 
     174      $this->delete(); 
     175 
     176      $con->commit(); 
     177 
     178      $log = 'moderator "%s" deleted question "%s"'; 
     179      $log = sprintf($log, $moderator->getNickname(), $this->getTitle()); 
     180      sfContext::getInstance()->getLogger()->warning($log); 
     181    } 
     182    catch (PropelException $e) 
     183    { 
     184      $con->rollback(); 
     185      throw $e; 
     186    } 
    149187  } 
    150188} 
  • trunk/lib/model/QuestionPeer.php

    r42 r55  
    103103  } 
    104104 
     105  public static function getReportedSpamPager($page) 
     106  { 
     107    $pager = new sfPager('Question', APP_PAGER_HOMEPAGE_MAX); 
     108    $c = new Criteria(); 
     109    $c->add(self::REPORTS, 0, Criteria::GREATER_THAN); 
     110    $c->setLimit(20); 
     111    $c->addDescendingOrderByColumn(self::REPORTS); 
     112    $c->addAscendingOrderByColumn(self::CREATED_AT); 
     113    $c = self::addPermanentTagToCriteria($c); 
     114    $pager->setCriteria($c); 
     115    $pager->setPage($page); 
     116    $pager->setPeerMethod('doSelectJoinUser'); 
     117    $pager->init(); 
     118 
     119    return $pager; 
     120  } 
     121 
     122  public static function getReportCount() 
     123  { 
     124    $c = new Criteria(); 
     125    $c->add(self::REPORTS, 0, Criteria::GREATER_THAN); 
     126    $c = self::addPermanentTagToCriteria($c); 
     127 
     128    return self::doCount($c); 
     129  } 
     130 
    105131  private static function addPermanentTagToCriteria($criteria) 
    106132  { 
  • trunk/lib/model/QuestionTagPeer.php

    r40 r55  
    147147    return $tags; 
    148148  } 
     149 
     150  public static function getUnpopularTags() 
     151  { 
     152    $tags = array(); 
     153 
     154    $con = Propel::getConnection(); 
     155    $query = ' 
     156      SELECT t1.normalized_tag AS tag, 
     157      COUNT(t1.normalized_tag) AS count 
     158      FROM '.QuestionTagPeer::TABLE_NAME.' AS t1'; 
     159 
     160    if (defined('APP_PERMANENT_TAG')) 
     161    { 
     162      $query .= ' 
     163        INNER JOIN '.QuestionTagPeer::TABLE_NAME.' AS t2 ON t1.question_id = t2.question_id 
     164        WHERE t2.normalized_tag = ? AND t1.normalized_tag != ? 
     165        AND count < 5 
     166      '; 
     167    } 
     168 
     169    $query .= ' 
     170      GROUP BY t1.normalized_tag 
     171      ORDER BY count ASC 
     172    '; 
     173 
     174    $stmt = $con->prepareStatement($query); 
     175    if (defined('APP_PERMANENT_TAG')) 
     176    { 
     177      $stmt->setString(1, APP_PERMANENT_TAG); 
     178      $stmt->setString(2, APP_PERMANENT_TAG); 
     179    } 
     180    $rs = $stmt->executeQuery(); 
     181    while ($rs->next()) 
     182    { 
     183      $tags[$rs->getString('tag')] = $rs->getInt('count'); 
     184    } 
     185 
     186    return $tags; 
     187  } 
     188 
     189  public static function getByNormalizedTag($tag) 
     190  { 
     191    $c = new Criteria(); 
     192    $c->add(self::NORMALIZED_TAG, Tag::normalize($tag)); 
     193 
     194    return self::doSelect($c); 
     195  } 
     196 
     197  public static function deleteSpam($moderator, $tag, $question_id = null) 
     198  { 
     199    if ($question_id === null) 
     200    { 
     201      $tags = self::getByNormalizedTag($tag); 
     202    } 
     203    else 
     204    { 
     205      $c = new Criteria(); 
     206      $c->add(self::NORMALIZED_TAG, Tag::normalize($tag)); 
     207      $c->add(self::QUESTION_ID, $question_id); 
     208 
     209      $tags = self::doSelect($c); 
     210    } 
     211 
     212    $con = Propel::getConnection(); 
     213    try 
     214    { 
     215      $con->begin(); 
     216 
     217      foreach ($tags as $tag) 
     218      { 
     219        $user = $tag->getUser(); 
     220        $user->setDeletions($user->getDeletions() + 1); 
     221        $user->save(); 
     222 
     223        $tag->delete(); 
     224      } 
     225 
     226      $con->commit(); 
     227 
     228      $log = 'moderator "%s" deleted tag "%s"'; 
     229      $log = sprintf($log, $moderator->getNickname(), $tag->getNormalizedTag()); 
     230      sfContext::getInstance()->getLogger()->warning($log); 
     231    } 
     232    catch (PropelException $e) 
     233    { 
     234      $con->rollback(); 
     235      throw $e; 
     236    } 
     237  } 
    149238} 
    150239 
  • trunk/lib/model/UserPeer.php

    r48 r55  
    4545    return null; 
    4646  } 
     47 
     48  public static function getModeratorCandidatesCount() 
     49  { 
     50    $c = new Criteria(); 
     51    $c->add(self::WANT_TO_BE_MODERATOR, true); 
     52 
     53    return self::doCount($c); 
     54  } 
     55 
     56  public static function getModeratorCandidates() 
     57  { 
     58    $c = new Criteria(); 
     59    $c->add(self::WANT_TO_BE_MODERATOR, true); 
     60    $c->addAscendingOrderByColumn(self::CREATED_AT); 
     61 
     62    return self::doSelect($c); 
     63  } 
     64 
     65  public static function getModerators() 
     66  { 
     67    $c = new Criteria(); 
     68    $c->add(self::IS_MODERATOR, true); 
     69    $c->addAscendingOrderByColumn(self::CREATED_AT); 
     70 
     71    return self::doSelect($c); 
     72  } 
     73 
     74  public static function getAdministrators() 
     75  { 
     76    $c = new Criteria(); 
     77    $c->add(self::IS_ADMINISTRATOR, true); 
     78    $c->addAscendingOrderByColumn(self::CREATED_AT); 
     79 
     80    return self::doSelect($c); 
     81  } 
     82 
     83  public static function getProblematicUsersCount() 
     84  { 
     85    $c = new Criteria(); 
     86    $c->add(self::DELETIONS, 0, Criteria::GREATER_THAN); 
     87 
     88    return self::doCount($c); 
     89  } 
     90 
     91  public static function getProblematicUsers() 
     92  { 
     93    $c = new Criteria(); 
     94    $c->add(self::DELETIONS, 0, Criteria::GREATER_THAN); 
     95    $c->addDescendingOrderByColumn(self::DELETIONS); 
     96 
     97    return self::doSelect($c); 
     98  } 
    4799} 
    48100 
  • trunk/lib/model/map/AnswerMapBuilder.php

    r23 r55  
    7979        $tMap->addColumn('RELEVANCY_DOWN', 'RelevancyDown', 'int', CreoleTypes::INTEGER, false); 
    8080 
     81        $tMap->addColumn('REPORTS', 'Reports', 'int', CreoleTypes::INTEGER, false); 
     82 
    8183        $tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false); 
    8284                 
  • trunk/lib/model/map/QuestionMapBuilder.php

    r23 r55  
    7979        $tMap->addColumn('INTERESTED_USERS', 'InterestedUsers', 'int', CreoleTypes::INTEGER, false); 
    8080 
     81        $tMap->addColumn('REPORTS', 'Reports', 'int', CreoleTypes::INTEGER, false); 
     82 
    8183        $tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false); 
    8284 
  • trunk/lib/model/map/QuestionTagMapBuilder.php

    r31 r55  
    6565        $tMap->setUseIdGenerator(false); 
    6666 
    67         $tMap->addForeignKey('QUESTION_ID', 'QuestionId', 'int', CreoleTypes::INTEGER, 'ask_question', 'ID', false, null); 
     67        $tMap->addForeignPrimaryKey('QUESTION_ID', 'QuestionId', 'int' , CreoleTypes::INTEGER, 'ask_question', 'ID', true, null); 
    6868 
    69         $tMap->addForeignKey('USER_ID', 'UserId', 'int', CreoleTypes::INTEGER, 'ask_user', 'ID', false, null); 
     69        $tMap->addForeignPrimaryKey('USER_ID', 'UserId', 'int' , CreoleTypes::INTEGER, 'ask_user', 'ID', true, null); 
    7070 
    7171        $tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false); 
     
    7373        $tMap->addColumn('TAG', 'Tag', 'string', CreoleTypes::VARCHAR, false); 
    7474 
    75         $tMap->addColumn('NORMALIZED_TAG', 'NormalizedTag', 'string', CreoleTypes::VARCHAR, false); 
     75        $tMap->addPrimaryKey('NORMALIZED_TAG', 'NormalizedTag', 'string', CreoleTypes::VARCHAR, true, 100); 
    7676                 
    7777    } // doBuild() 
  • trunk/lib/model/map/UserMapBuilder.php

    r44 r55  
    8181        $tMap->addColumn('HAS_PAYPAL', 'HasPaypal', 'boolean', CreoleTypes::BOOLEAN, false); 
    8282 
     83        $tMap->addColumn('WANT_TO_BE_MODERATOR', 'WantToBeModerator', 'boolean', CreoleTypes::BOOLEAN, false); 
     84 
     85        $tMap->addColumn('IS_MODERATOR', 'IsModerator', 'boolean', CreoleTypes::BOOLEAN, false); 
     86 
     87        $tMap->addColumn('IS_ADMINISTRATOR', 'IsAdministrator', 'boolean', CreoleTypes::BOOLEAN, false); 
     88 
     89        $tMap->addColumn('DELETIONS', 'Deletions', 'int', CreoleTypes::INTEGER, false); 
     90 
    8391        $tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false); 
    8492                 
  • trunk/lib/model/om/BaseAnswer.php

    r23 r55  
    7979 
    8080    /** 
     81     * The value for the reports field. 
     82     * @var int 
     83     */ 
     84    protected $reports = 0; 
     85 
     86 
     87    /** 
    8188     * The value for the created_at field. 
    8289     * @var int 
     
    105112     */ 
    106113    private $lastRelevancyCriteria = null; 
     114 
     115    /** 
     116     * Collection to store aggregation of collReportAnswers. 
     117     * @var array 
     118     */ 
     119    protected $collReportAnswers; 
     120     
     121    /** 
     122     * The criteria used to select the current contents of collReportAnswers. 
     123     * @var Criteria 
     124     */ 
     125    private $lastReportAnswerCriteria = null; 
    107126 
    108127    /** 
     
    195214 
    196215        return $this->relevancy_down; 
     216    } 
     217 
     218    /** 
     219     * Get the [reports] column value. 
     220     *  
     221     * @return int 
     222     */ 
     223    public function getReports() 
     224    { 
     225 
     226        return $this->reports; 
    197227    } 
    198228 
     
    349379 
    350380    /** 
     381     * Set the value of [reports] column. 
     382     *  
     383     * @param int $v new value 
     384     * @return void 
     385     */ 
     386    public function setReports($v) 
     387    { 
     388 
     389        if ($this->reports !== $v || $v === 0) { 
     390            $this->reports = $v; 
     391            $this->modifiedColumns[] = AnswerPeer::REPORTS; 
     392        } 
     393 
     394    } // setReports() 
     395 
     396    /** 
    351397     * Set the value of [created_at] column. 
    352398     *  
     
    403449            $this->relevancy_down = $rs->getInt($startcol + 6); 
    404450 
    405             $this->created_at = $rs->getTimestamp($startcol + 7, null); 
     451            $this->reports = $rs->getInt($startcol + 7); 
     452 
     453            $this->created_at = $rs->getTimestamp($startcol + 8, null); 
    406454 
    407455            $this->resetModified(); 
     
    410458 
    411459            // FIXME - using NUM_COLUMNS may be clearer. 
    412             return $startcol + 8; // 8 = AnswerPeer::NUM_COLUMNS - AnswerPeer::NUM_LAZY_LOAD_COLUMNS). 
     460            return $startcol + 9; // 9 = AnswerPeer::NUM_COLUMNS - AnswerPeer::NUM_LAZY_LOAD_COLUMNS). 
    413461 
    414462        } catch (Exception $e) { 
     
    546594            } 
    547595 
     596            if ($this->collReportAnswers !== null) { 
     597                foreach($this->collReportAnswers as $referrerFK) { 
     598                    if (!$referrerFK->isDeleted()) { 
     599                        $affectedRows += $referrerFK->save($con); 
     600                    } 
     601                } 
     602            } 
     603 
    548604            $this->alreadyInSave = false; 
    549605        } 
     
    620676                } 
    621677 
     678                if ($this->collReportAnswers !== null) { 
     679                    foreach($this->collReportAnswers as $referrerFK) { 
     680                        if (($retval = $referrerFK->validate()) !== true) { 
     681                            $failureMap = array_merge($failureMap, $retval); 
     682                        } 
     683                    } 
     684                } 
     685 
    622686 
    623687            $this->alreadyInValidation = false; 
     
    675739                break; 
    676740            case 7: 
     741                return $this->getReports(); 
     742                break; 
     743            case 8: 
    677744                return $this->getCreatedAt(); 
    678745                break; 
     
    704771            $keys[5] => $this->getRelevancyUp(), 
    705772            $keys[6] => $this->getRelevancyDown(), 
    706             $keys[7] => $this->getCreatedAt(), 
     773            $keys[7] => $this->getReports(), 
     774            $keys[8] => $this->getCreatedAt(), 
    707775        ); 
    708776        return $result; 
     
    759827                break; 
    760828            case 7: 
     829                $this->setReports($value); 
     830                break; 
     831            case 8: 
    761832                $this->setCreatedAt($value); 
    762833                break; 
     
    791862        if (array_key_exists($keys[5], $arr)) $this->setRelevancyUp($arr[$keys[5]]); 
    792863        if (array_key_exists($keys[6], $arr)) $this->setRelevancyDown($arr[$keys[6]]); 
    793         if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]); 
     864        if (array_key_exists($keys[7], $arr)) $this->setReports($arr[$keys[7]]); 
     865        if (array_key_exists($keys[8], $arr)) $this->setCreatedAt($arr[$keys[8]]); 
    794866    } 
    795867 
     
    810882        if ($this->isColumnModified(AnswerPeer::RELEVANCY_UP)) $criteria->add(AnswerPeer::RELEVANCY_UP, $this->relevancy_up); 
    811883        if ($this->isColumnModified(AnswerPeer::RELEVANCY_DOWN)) $criteria->add(AnswerPeer::RELEVANCY_DOWN, $this->relevancy_down); 
     884        if ($this->isColumnModified(AnswerPeer::REPORTS)) $criteria->add(AnswerPeer::REPORTS, $this->reports); 
    812885        if ($this->isColumnModified(AnswerPeer::CREATED_AT)) $criteria->add(AnswerPeer::CREATED_AT, $this->created_at); 
    813886 
     
    876949 
    877950        $copyObj->setRelevancyDown($this->relevancy_down); 
     951 
     952        $copyObj->setReports($this->reports); 
    878953 
    879954        $copyObj->setCreatedAt($this->created_at); 
     
    887962            foreach($this->getRelevancys() as $relObj) { 
    888963                $copyObj->addRelevancy($relObj->copy($deepCopy)); 
     964            } 
     965 
     966            foreach($this->getReportAnswers() as $relObj) { 
     967                $copyObj->addReportAnswer($relObj->copy($deepCopy)); 
    889968            } 
    890969 
     
    11931272    } 
    11941273 
     1274    /** 
     1275     * Temporary storage of collReportAnswers to save a possible db hit in 
     1276     * the event objects are add to the collection, but the 
     1277     * complete collection is never requested. 
     1278     * @return void 
     1279     */ 
     1280    public function initReportAnswers() 
     1281    { 
     1282        if ($this->collReportAnswers === null) { 
     1283            $this->collReportAnswers = array(); 
     1284        } 
     1285    } 
     1286 
     1287    /** 
     1288     * If this collection has already been initialized with 
     1289     * an identical criteria, it returns the collection. 
     1290     * Otherwise if this Answer has previously 
     1291     * been saved, it will retrieve related ReportAnswers from storage. 
     1292     * If this Answer is new, it will return 
     1293     * an empty collection or the current collection, the criteria 
     1294     * is ignored on a new object. 
     1295     * 
     1296     * @param Connection $con 
     1297     * @param Criteria $criteria 
     1298     * @throws PropelException 
     1299     */ 
     1300    public function getReportAnswers($criteria = null, $con = null) 
     1301    { 
     1302        // include the Peer class 
     1303        include_once 'model/om/BaseReportAnswerPeer.php'; 
     1304        if ($criteria === null) { 
     1305            $criteria = new Criteria(); 
     1306        } 
     1307        elseif ($criteria instanceof Criteria) 
     1308        { 
     1309            $criteria = clone $criteria; 
     1310        } 
     1311 
     1312        if ($this->collReportAnswers === null) { 
     1313            if ($this->isNew()) { 
     1314               $this->collReportAnswers = array(); 
     1315            } else { 
     1316 
     1317                $criteria->add(ReportAnswerPeer::ANSWER_ID, $this->getId()); 
     1318 
     1319                ReportAnswerPeer::addSelectColumns($criteria); 
     1320                $this->collReportAnswers = ReportAnswerPeer::doSelect($criteria, $con); 
     1321            } 
     1322        } else { 
     1323            // criteria has no effect for a new object 
     1324            if (!$this->isNew()) { 
     1325                // the following code is to determine if a new query is 
     1326                // called for.  If the criteria is the same as the last 
     1327                // one, just return the collection. 
     1328 
     1329 
     1330                $criteria->add(ReportAnswerPeer::ANSWER_ID, $this->getId()); 
     1331 
     1332                ReportAnswerPeer::addSelectColumns($criteria); 
     1333                if (!isset($this->lastReportAnswerCriteria) || !$this->lastReportAnswerCriteria->equals($criteria)) { 
     1334                    $this->collReportAnswers = ReportAnswerPeer::doSelect($criteria, $con); 
     1335                } 
     1336            } 
     1337        } 
     1338        $this->lastReportAnswerCriteria = $criteria; 
     1339        return $this->collReportAnswers; 
     1340    } 
     1341 
     1342    /** 
     1343     * Returns the number of related ReportAnswers. 
     1344     * 
     1345     * @param Criteria $criteria 
     1346     * @param Connection $con 
     1347     * @throws PropelException 
     1348     */ 
     1349    public function countReportAnswers($criteria = null, $con = null) 
     1350    { 
     1351        // include the Peer class 
     1352        include_once 'model/om/BaseReportAnswerPeer.php'; 
     1353        if ($criteria === null) { 
     1354            $criteria = new Criteria(); 
     1355        } 
     1356        elseif ($criteria instanceof Criteria) 
     1357        { 
     1358            $criteria = clone $criteria; 
     1359        } 
     1360 
     1361        $criteria->add(ReportAnswerPeer::ANSWER_ID, $this->getId()); 
     1362 
     1363        return ReportAnswerPeer::doCount($criteria, $con); 
     1364    } 
     1365 
     1366    /** 
     1367     * Method called to associate a ReportAnswer object to this object 
     1368     * through the ReportAnswer foreign key attribute 
     1369     * 
     1370     * @param ReportAnswer $l ReportAnswer 
     1371     * @return void 
     1372     * @throws PropelException 
     1373     */ 
     1374    public function addReportAnswer(ReportAnswer $l) 
     1375    { 
     1376        $this->collReportAnswers[] = $l; 
     1377        $l->setAnswer($this); 
     1378    } 
     1379 
     1380 
     1381    /** 
     1382     * If this collection has already been initialized with 
     1383     * an identical criteria, it returns the collection. 
     1384     * Otherwise if this Answer is new, it will return 
     1385     * an empty collection; or if this Answer has previously 
     1386     * been saved, it will retrieve related ReportAnswers from storage. 
     1387     * 
     1388     * This method is protected by default in order to keep the public 
     1389     * api reasonable.  You can provide public methods for those you 
     1390     * actually need in Answer. 
     1391     */ 
     1392    public function getReportAnswersJoinUser($criteria = null, $con = null) 
     1393    { 
     1394        // include the Peer class 
     1395        include_once 'model/om/BaseReportAnswerPeer.php'; 
     1396        if ($criteria === null) { 
     1397            $criteria = new Criteria(); 
     1398        } 
     1399        elseif ($criteria instanceof Criteria) 
     1400        { 
     1401            $criteria = clone $criteria; 
     1402        } 
     1403 
     1404        if ($this->collReportAnswers === null) { 
     1405            if ($this->isNew()) { 
     1406                $this->collReportAnswers = array(); 
     1407            } else { 
     1408 
     1409                $criteria->add(ReportAnswerPeer::ANSWER_ID, $this->getId()); 
     1410 
     1411                $this->collReportAnswers = ReportAnswerPeer::doSelectJoinUser($criteria, $con); 
     1412            } 
     1413        } else { 
     1414            // the following code is to determine if a new query is 
     1415            // called for.  If the criteria is the same as the last 
     1416            // one, just return the collection. 
     1417 
     1418            $criteria->add(ReportAnswerPeer::ANSWER_ID, $this->getId()); 
     1419 
     1420            if (!isset($this->lastReportAnswerCriteria) || !$this->lastReportAnswerCriteria->equals($criteria)) { 
     1421                $this->collReportAnswers = ReportAnswerPeer::doSelectJoinUser($criteria, $con); 
     1422            } 
     1423        } 
     1424        $this->lastReportAnswerCriteria = $criteria; 
     1425 
     1426        return $this->collReportAnswers; 
     1427    } 
     1428 
    11951429} // BaseAnswer 
  • trunk/lib/model/om/BaseAnswerPeer.php

    r23 r55  
    2525 
    2626    /** The total number of columns. */ 
    27     const NUM_COLUMNS = 8
     27    const NUM_COLUMNS = 9
    2828 
    2929    /** The number of lazy-loaded columns. */ 
     
    5252    const RELEVANCY_DOWN = 'ask_answer.RELEVANCY_DOWN'; 
    5353 
     54    /** the column name for the REPORTS field */ 
     55    const REPORTS = 'ask_answer.REPORTS'; 
     56 
    5457    /** the column name for the CREATED_AT field */ 
    5558    const CREATED_AT = 'ask_answer.CREATED_AT'; 
     
    6669     */ 
    6770    private static $fieldNames = array ( 
    68         BasePeer::TYPE_PHPNAME => array ('Id', 'QuestionId', 'UserId', 'Body', 'HtmlBody', 'RelevancyUp', 'RelevancyDown', 'CreatedAt', ), 
    69         BasePeer::TYPE_COLNAME => array (AnswerPeer::ID, AnswerPeer::QUESTION_ID, AnswerPeer::USER_ID, AnswerPeer::BODY, AnswerPeer::HTML_BODY, AnswerPeer::RELEVANCY_UP, AnswerPeer::RELEVANCY_DOWN, AnswerPeer::CREATED_AT, ), 
    70         BasePeer::TYPE_FIELDNAME => array ('id', 'question_id', 'user_id', 'body', 'html_body', 'relevancy_up', 'relevancy_down', 'created_at', ), 
    71         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7,
     71        BasePeer::TYPE_PHPNAME => array ('Id', 'QuestionId', 'UserId', 'Body', 'HtmlBody', 'RelevancyUp', 'RelevancyDown', 'Reports', 'CreatedAt', ), 
     72        BasePeer::TYPE_COLNAME => array (AnswerPeer::ID, AnswerPeer::QUESTION_ID, AnswerPeer::USER_ID, AnswerPeer::BODY, AnswerPeer::HTML_BODY, AnswerPeer::RELEVANCY_UP, AnswerPeer::RELEVANCY_DOWN, AnswerPeer::REPORTS, AnswerPeer::CREATED_AT, ), 
     73        BasePeer::TYPE_FIELDNAME => array ('id', 'question_id', 'user_id', 'body', 'html_body', 'relevancy_up', 'relevancy_down', 'reports', 'created_at', ), 
     74        BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8,
    7275    ); 
    7376 
     
    7982     */ 
    8083    private static $fieldKeys = array ( 
    81         BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'QuestionId' => 1, 'UserId' => 2, 'Body' => 3, 'HtmlBody' => 4, 'RelevancyUp' => 5, 'RelevancyDown' => 6, 'CreatedAt' => 7, ), 
    82         BasePeer::TYPE_COLNAME => array (AnswerPeer::ID => 0, AnswerPeer::QUESTION_ID => 1, AnswerPeer::USER_ID => 2, AnswerPeer::BODY => 3, AnswerPeer::HTML_BODY => 4, AnswerPeer::RELEVANCY_UP => 5, AnswerPeer::RELEVANCY_DOWN => 6, AnswerPeer::CREATED_AT => 7, ), 
    83         BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'question_id' => 1, 'user_id' => 2, 'body' => 3, 'html_body' => 4, 'relevancy_up' => 5, 'relevancy_down' => 6, 'created_at' => 7, ), 
    84         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7,
     84        BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'QuestionId' => 1, 'UserId' => 2, 'Body' => 3, 'HtmlBody' => 4, 'RelevancyUp' => 5, 'RelevancyDown' => 6, 'Reports' => 7, 'CreatedAt' => 8, ), 
     85        BasePeer::TYPE_COLNAME => array (AnswerPeer::ID => 0, AnswerPeer::QUESTION_ID => 1, AnswerPeer::USER_ID => 2, AnswerPeer::BODY => 3, AnswerPeer::HTML_BODY => 4, AnswerPeer::RELEVANCY_UP => 5, AnswerPeer::RELEVANCY_DOWN => 6, AnswerPeer::REPORTS => 7, AnswerPeer::CREATED_AT => 8, ), 
     86        BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'question_id' => 1, 'user_id' => 2, 'body' => 3, 'html_body' => 4, 'relevancy_up' => 5, 'relevancy_down' => 6, 'reports' => 7, 'created_at' => 8, ), 
     87        BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8,
    8588    ); 
    8689 
     
    196199 
    197200        $criteria->addSelectColumn(AnswerPeer::RELEVANCY_DOWN); 
     201 
     202        $criteria->addSelectColumn(AnswerPeer::REPORTS); 
    198203 
    199204        $criteria->addSelectColumn(AnswerPeer::CREATED_AT); 
  • trunk/lib/model/om/BaseQuestion.php

    r31 r55  
    7979 
    8080    /** 
     81     * The value for the reports field. 
     82     * @var int 
     83     */ 
     84    protected $reports = 0; 
     85 
     86 
     87    /** 
    8188     * The value for the created_at field. 
    8289     * @var int 
     
    131138     */ 
    132139    private $lastQuestionTagCriteria = null; 
     140 
     141    /** 
     142     * Collection to store aggregation of collReportQuestions. 
     143     * @var array 
     144     */ 
     145    protected $collReportQuestions; 
     146     
     147    /** 
     148     * The criteria used to select the current contents of collReportQuestions. 
     149     * @var Criteria 
     150     */ 
     151    private $lastReportQuestionCriteria = null; 
    133152 
    134153    /** 
     
    221240 
    222241        return $this->interested_users; 
     242    } 
     243 
     244    /** 
     245     * Get the [reports] column value. 
     246     *  
     247     * @return int 
     248     */ 
     249    public function getReports() 
     250    { 
     251 
     252        return $this->reports; 
    223253    } 
    224254 
     
    402432 
    403433    /** 
     434     * Set the value of [reports] column. 
     435     *  
     436     * @param int $v new value 
     437     * @return void 
     438     */ 
     439    public function setReports($v) 
     440    { 
     441 
     442        if ($this->reports !== $v || $v === 0) { 
     443            $this->reports = $v; 
     444            $this->modifiedColumns[] = QuestionPeer::REPORTS; 
     445        } 
     446 
     447    } // setReports() 
     448 
     449    /** 
    404450     * Set the value of [created_at] column. 
    405451     *  
     
    480526            $this->interested_users = $rs->getInt($startcol + 6); 
    481527 
    482             $this->created_at = $rs->getTimestamp($startcol + 7, null); 
    483  
    484             $this->updated_at = $rs->getTimestamp($startcol + 8, null); 
     528            $this->reports = $rs->getInt($startcol + 7); 
     529 
     530            $this->created_at = $rs->getTimestamp($startcol + 8, null); 
     531 
     532            $this->updated_at = $rs->getTimestamp($startcol + 9, null); 
    485533 
    486534            $this->resetModified(); 
     
    489537 
    490538            // FIXME - using NUM_COLUMNS may be clearer. 
    491             return $startcol + 9; // 9 = QuestionPeer::NUM_COLUMNS - QuestionPeer::NUM_LAZY_LOAD_COLUMNS). 
     539            return $startcol + 10; // 10 = QuestionPeer::NUM_COLUMNS - QuestionPeer::NUM_LAZY_LOAD_COLUMNS). 
    492540 
    493541        } catch (Exception $e) { 
     
    635683            } 
    636684 
     685            if ($this->collReportQuestions !== null) { 
     686                foreach($this->collReportQuestions as $referrerFK) { 
     687                    if (!$referrerFK->isDeleted()) { 
     688                        $affectedRows += $referrerFK->save($con); 
     689                    } 
     690                } 
     691            } 
     692 
    637693            $this->alreadyInSave = false; 
    638694        } 
     
    719775                } 
    720776 
     777                if ($this->collReportQuestions !== null) { 
     778                    foreach($this->collReportQuestions as $referrerFK) { 
     779                        if (($retval = $referrerFK->validate()) !== true) { 
     780                            $failureMap = array_merge($failureMap, $retval); 
     781                        } 
     782                    } 
     783                } 
     784 
    721785 
    722786            $this->alreadyInValidation = false; 
     
    774838                break; 
    775839            case 7: 
     840                return $this->getReports(); 
     841                break; 
     842            case 8: 
    776843                return $this->getCreatedAt(); 
    777844                break; 
    778             case 8
     845            case 9
    779846                return $this->getUpdatedAt(); 
    780847                break; 
     
    806873            $keys[5] => $this->getHtmlBody(), 
    807874            $keys[6] => $this->getInterestedUsers(), 
    808             $keys[7] => $this->getCreatedAt(), 
    809             $keys[8] => $this->getUpdatedAt(), 
     875            $keys[7] => $this->getReports(), 
     876            $keys[8] => $this->getCreatedAt(), 
     877            $keys[9] => $this->getUpdatedAt(), 
    810878        ); 
    811879        return $result; 
     
    862930                break; 
    863931            case 7: 
     932                $this->setReports($value); 
     933                break; 
     934            case 8: 
    864935                $this->setCreatedAt($value); 
    865936                break; 
    866             case 8
     937            case 9
    867938                $this->setUpdatedAt($value); 
    868939                break; 
     
    897968        if (array_key_exists($keys[5], $arr)) $this->setHtmlBody($arr[$keys[5]]); 
    898969        if (array_key_exists($keys[6], $arr)) $this->setInterestedUsers($arr[$keys[6]]); 
    899         if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]); 
    900         if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]); 
     970        if (array_key_exists($keys[7], $arr)) $this->setReports($arr[$keys[7]]); 
     971        if (array_key_exists($keys[8], $arr)) $this->setCreatedAt($arr[$keys[8]]); 
     972        if (array_key_exists($keys[9], $arr)) $this->setUpdatedAt($arr[$keys[9]]); 
    901973    } 
    902974 
     
    917989        if ($this->isColumnModified(QuestionPeer::HTML_BODY)) $criteria->add(QuestionPeer::HTML_BODY, $this->html_body); 
    918990        if ($this->isColumnModified(QuestionPeer::INTERESTED_USERS)) $criteria->add(QuestionPeer::INTERESTED_USERS, $this->interested_users); 
     991        if ($this->isColumnModified(QuestionPeer::REPORTS)) $criteria->add(QuestionPeer::REPORTS, $this->reports); 
    919992        if ($this->isColumnModified(QuestionPeer::CREATED_AT)) $criteria->add(QuestionPeer::CREATED_AT, $this->created_at); 
    920993        if ($this->isColumnModified(QuestionPeer::UPDATED_AT)) $criteria->add(QuestionPeer::UPDATED_AT, $this->updated_at); 
     
    9841057 
    9851058        $copyObj->setInterestedUsers($this->interested_users); 
     1059 
     1060        $copyObj->setReports($this->reports); 
    9861061&