public static function getFor(Doctrine_Record $object) { $tableName = $object->getTable()->getTableName(); $componentName = $object->getTable()->getComponentName(); $q = Doctrine_Query::create()->select('c.message, c.parent, c.created_at, c.updated_at, c.created_by, c.updated_by, p.*, v.*,u.*')->from('Comment' . $componentName . ' c')->leftJoin('c.CreatedBy p')->leftJoin('p.User u')->leftJoin('c.VoteComment v')->where('c.' . $tableName . '_id = ?', $object->getId()); $treeObject = Doctrine::getTable('Comment' . $componentName)->getTree(); $treeObject->setBaseQuery($q); $comments = array(); $rootComment = $treeObject->fetchRoots()->getFirst(); if ($rootComment) { foreach ($treeObject->fetchTree(array('root_id' => $rootComment->root_id)) as $comment) { $comments[] = $comment; } } array_shift($comments); return $comments; }
public function setCommented(Doctrine_Record $toComment) { $this->setDefaults(array($this->getToward() . '_id' => $toComment->getId())); }
public static function deleteFromLuceneIndex(Doctrine_Record $object, $culture = null) { $index = $object->getTable()->getLuceneIndex(); // remove an existing entry $id = $object->getId(); // 20090506: we can't use a regular query string here because // numbers (such as IDs) will get stripped from it. So we have // to build a query using the Zend Search API. Note that this means // the Jobeet sample code is incorrect. // http://framework.zend.com/manual/en/zend.search.lucene.searching.html#zend.search.lucene.searching.query_building $aTerm = new Zend_Search_Lucene_Index_Term($id, 'primarykey'); $aQuery = new Zend_Search_Lucene_Search_Query_Term($aTerm); $query = new Zend_Search_Lucene_Search_Query_Boolean(); $query->addSubquery($aQuery, true); if (!is_null($culture)) { $culture = self::normalizeCulture($culture); $cultureTerm = new Zend_Search_Lucene_Index_Term($culture, 'culture'); // Oops, this said $aTerm before. Thanks to Quentin Dugauthier $cultureQuery = new Zend_Search_Lucene_Search_Query_Term($cultureTerm); $query->addSubquery($cultureQuery, true); } if ($hits = $index->find($query)) { // id is correct. This is the internal Zend search index id which is // not the same thing as the id of our object. // There should actually be only one hit for a specific id and culture foreach ($hits as $hit) { $index->delete($hit->id); } } }