Exemple #1
1
 public function indexDirectory($dir)
 {
     if (!file_exists($dir)) {
         throw new Doctrine_Search_Indexer_Exception('Unknown directory ' . $dir);
     }
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY);
     $files = array();
     foreach ($it as $file) {
         $name = $file->getPathName();
         if (strpos($name, '.svn') === false) {
             $files[] = $name;
         }
     }
     $q = new Doctrine_Query();
     $q->delete()->from('Doctrine_File f')->where('f.url LIKE ?', array($dir . '%'))->execute();
     // clear the index
     $q = new Doctrine_Query();
     $q->delete()->from('Doctrine_File_Index i')->where('i.file_id = ?')->execute();
     $conn = Doctrine_Manager::connection();
     $coll = new Doctrine_Collection('Doctrine_File');
     foreach ($files as $file) {
         $coll[]->url = $file;
     }
     $coll->save();
 }
 public function reload($projets, $project_id, $project_ref, Doctrine_Connection $conn = null)
 {
     if ($conn == null) {
         $conn = Doctrine_Manager::connection();
     }
     //Création de la collection d'objet EiProjectLang à ajouter
     $collection = new Doctrine_Collection("EiProjectLang");
     $items = $projets->getElementsByTagName("ei_project_langs");
     if ($items->length > 0) {
         //ya t-il des éléments à traiter?
         $ei_project_langs = $items->item(0)->getElementsByTagName("ei_project_lang");
         if ($ei_project_langs->length > 0) {
             foreach ($ei_project_langs as $ei_project_lang) {
                 $lang_id = $ei_project_lang->getAttribute("lang");
                 //recherche du profil en base
                 if ($lang_id != null && $project_ref != null && $project_id != null) {
                     $new_ei_project_lang = new EiProjectLang();
                     $new_ei_project_lang->setLang($lang_id);
                     $new_ei_project_lang->setProjectId($project_id);
                     $new_ei_project_lang->setProjectRef($project_ref);
                     $collection->add($new_ei_project_lang);
                 }
             }
             if ($collection->getFirst()) {
                 $collection->save($conn);
             }
             //Sauvegarde de la collection
             return 1;
         }
         return null;
     }
 }
 /**
  * Returns the SLA Summary (@see IcingaSLASummary) for this filter
  *
  * @param Doctrine_Connection $dbConnection
  * @param type $filter
  * @return Doctrine_Collection
  */
 public static function getSummary(Doctrine_Connection $dbConnection = null, $filter = null)
 {
     if ($dbConnection == null) {
         $dbConnection = AgaviContext::getInstance()->getDatabaseConnection("icinga");
     }
     $driver = $dbConnection->getDriverName();
     $stmt = null;
     switch (strtolower($driver)) {
         case 'pgsql':
             $stmt = self::getPgsqlSummaryQuery($dbConnection, $filter);
             break;
         case 'oracle':
         case 'icingaoracle':
             $stmt = self::getOracleSummaryQuery($dbConnection, $filter);
             break;
         case 'mysql':
             $stmt = self::getMySQLSummaryQuery($dbConnection, $filter);
             break;
         default:
             throw new AppKitDoctrineException("Invalid driver " . $driver);
     }
     $stmt->execute();
     $result = new Doctrine_Collection("IcingaSLASummary");
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $record = new IcingaSLASummary();
         foreach ($row as $key => $value) {
             $record->{strtolower($key)} = $value;
         }
         $result->add($record);
     }
     return $result;
 }
Exemple #4
0
 public function executeImportSentences(dmWebRequest $request)
 {
     $catalogue = $this->getObjectOrForward404($request);
     $form = new DmCatalogueImportForm();
     sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url'));
     if ($request->isMethod('post') && $form->bindAndValid($request)) {
         $file = $form->getValue('file');
         $override = $form->getValue('override');
         $dataFile = $file->getTempName();
         $table = dmDb::table('DmTransUnit');
         $existQuery = $table->createQuery('t')->select('t.id, t.source, t.target, t.created_at, t.updated_at')->where('t.dm_catalogue_id = ? AND t.source = ?');
         $catalogueId = $catalogue->get('id');
         $nbAdded = 0;
         $nbUpdated = 0;
         try {
             if (!is_array($data = sfYaml::load(file_get_contents($dataFile)))) {
                 $this->getUser()->logError($this->getI18n()->__('Could not load file: %file%', array('%file%' => $file->getOriginalName())));
                 return $this->renderPartial('dmInterface/flash');
             }
         } catch (Exception $e) {
             $this->getUser()->logError($this->getI18n()->__('Unable to parse file: %file%', array('%file%' => $file->getOriginalName())));
             return $this->renderPartial('dmInterface/flash');
         }
         $addedTranslations = new Doctrine_Collection($table);
         $line = 0;
         foreach ($data as $source => $target) {
             ++$line;
             if (!is_string($source) || !is_string($target)) {
                 $this->getUser()->logError($this->getI18n()->__('Error line %line%: %file%', array('%line%' => $line, '%file%' => $file->getOriginalName())));
                 return $this->renderPartial('dmInterface/flash');
             } else {
                 $existing = $existQuery->fetchOneArray(array($catalogueId, $source));
                 if (!empty($existing) && $existing['source'] === $source) {
                     if ($existing['target'] !== $target) {
                         if ($override || $existing['created_at'] === $existing['updated_at']) {
                             $table->createQuery()->update('DmTransUnit')->set('target', '?', array($target))->where('id = ?', $existing['id'])->execute();
                             ++$nbUpdated;
                         }
                     }
                 } elseif (empty($existing)) {
                     $addedTranslations->add(dmDb::create('DmTransUnit', array('dm_catalogue_id' => $catalogue->get('id'), 'source' => $source, 'target' => $target)));
                     ++$nbAdded;
                 }
             }
         }
         $addedTranslations->save();
         if ($nbAdded) {
             $this->getUser()->logInfo($this->getI18n()->__('%catalogue%: added %count% translation(s)', array('%catalogue%' => $catalogue->get('name'), '%count%' => $nbAdded)));
         }
         if ($nbUpdated) {
             $this->getUser()->logInfo($this->getI18n()->__('%catalogue%: updated %count% translation(s)', array('%catalogue%' => $catalogue->get('name'), '%count%' => $nbUpdated)));
         }
         if (!$nbAdded && !$nbUpdated) {
             $this->getUser()->logInfo($this->getI18n()->__('%catalogue%: nothing to add and update', array('%catalogue%' => $catalogue->get('name'))));
         }
         return $this->renderText(url_for1($this->getRouteArrayForAction('index')));
     }
     $action = url_for1($this->getRouteArrayForAction('importSentences', $catalogue));
     return $this->renderText($form->render('.dm_form.list.little action="' . $action . '"'));
 }
 /**
  *
  * @param <type> $request
  */
 public function execute($request)
 {
     $this->setForm(new CopyActivityForm());
     $projectId = $request->getParameter('projectId');
     $this->form->bind($request->getParameter($this->form->getName()));
     $projectActivityList = $this->getProjectService()->getActivityListByProjectId($projectId);
     if ($this->form->isValid()) {
         $activityNameList = $request->getParameter('activityNames', array());
         $activities = new Doctrine_Collection('ProjectActivity');
         $isUnique = true;
         foreach ($activityNameList as $activityName) {
             foreach ($projectActivityList as $projectActivity) {
                 if (strtolower($activityName) == strtolower($projectActivity->getName())) {
                     $isUnique = false;
                     break;
                 }
             }
         }
         if ($isUnique) {
             foreach ($activityNameList as $activityName) {
                 $activity = new ProjectActivity();
                 $activity->setProjectId($projectId);
                 $activity->setName($activityName);
                 $activity->setIsDeleted(ProjectActivity::ACTIVE_PROJECT);
                 $activities->add($activity);
             }
             $activities->save();
             $this->getUser()->setFlash('templateMessageAct', array('success', __('Successfully Copied')));
         } else {
             $this->getUser()->setFlash('templateMessageAct', array('failure', __('Name Already Exists')));
         }
         $this->redirect('admin/saveProject?projectId=' . $projectId);
     }
 }
 public function testInsertMultiple()
 {
     $count = count($this->dbh);
     $listener = new Transaction_TestLogger();
     $users = new Doctrine_Collection('User');
     $users->getTable()->getConnection()->setListener($listener);
     $this->connection->beginTransaction();
     $users[0]->name = 'Arnold';
     $users[1]->name = 'Vincent';
     $users[0]->save();
     $users[1]->save();
     $this->assertEqual($listener->pop(), 'onSave');
     $this->assertEqual($listener->pop(), 'onInsert');
     $this->assertEqual($listener->pop(), 'onPreInsert');
     $this->assertEqual($listener->pop(), 'onPreSave');
     $this->assertEqual($listener->pop(), 'onSave');
     $this->assertEqual($listener->pop(), 'onInsert');
     $this->assertEqual($listener->pop(), 'onPreInsert');
     $this->assertEqual($listener->pop(), 'onPreSave');
     $this->assertEqual($users[0]->id, 2);
     $this->assertEqual($users[1]->id, 3);
     $this->assertTrue($count < count($this->dbh));
     $this->connection->commit();
     $this->assertEqual($listener->pop(), 'onTransactionCommit');
     $this->assertEqual($listener->pop(), 'onPreTransactionCommit');
 }
Exemple #7
0
 protected function getNodes($recreate = false)
 {
     if ($recreate || !self::$nodes) {
         $coll = new Doctrine_Collection('Structure', 'id');
         self::$nodes = $coll->merge($this->getMenuItemFetchingQuery()->execute());
     }
     return self::$nodes;
 }
 public function getObjects()
 {
     $objects = parent::getObjects();
     if ($objects instanceof Doctrine_Record) {
         $objects = new Doctrine_Collection($objects->getTable());
     }
     return $objects;
 }
 /**
  *
  * @param PetitionApiToken $api_token
  * @return \Doctrine_Collection
  */
 public function fetchOffsetsByToken(PetitionApiToken $api_token)
 {
     $coll = new Doctrine_Collection('ApiTokenOffset', 'country');
     foreach ($this->createQuery('o')->where('o.petition_api_token_id = ?', $api_token->getId())->execute() as $offset) {
         $coll->add($offset);
     }
     return $coll;
 }
 /**
  * Remaps a doctrine collection so that the keys of the colleciton "array"
  * are the ids of the underlying objects. This makes the collection
  * easier to deal with then replacing objects
  * 
  * @return Doctrine_Collection
  */
 protected static function _buildObjects(Doctrine_Collection $collection)
 {
     $objects = new Doctrine_Collection($collection->getTable());
     foreach ($collection as $key => $value) {
         $objects[$value->slug] = $value;
     }
     return $objects;
 }
 /**
  *
  * @param string $model_name
  * @param array  $data   
  * @return Doctrine_Collection 
  */
 public static function createCollection($model_name, $data)
 {
     $collection = new Doctrine_Collection($model_name);
     if (!$collection instanceof Doctrine_Collection) {
         throw new sfException('Trying to hydrate a non-Doctrine_collection object!');
     }
     $collection->fromArray($data);
     return $collection;
 }
 public function reload($projets, $project_id, $project_ref, Doctrine_Connection $conn = null)
 {
     if ($conn == null) {
         $conn = Doctrine_Manager::connection();
     }
     //Création de la collection d'objet EiVersionNotice à ajouter
     $collection = new Doctrine_Collection("EiVersionNotice");
     //Supression des versions de notice qui n'existent plus sur script
     $this->deleteNotFoundVersionNotice($conn);
     $items = $projets->getElementsByTagName("ei_version_notices");
     if ($items->length > 0) {
         //ya t-il des éléments à traiter?
         $ei_version_notices = $items->item(0)->getElementsByTagName("ei_version_notice");
         if ($ei_version_notices->length > 0) {
             foreach ($ei_version_notices as $ei_version_notice) {
                 $notice_id = $ei_version_notice->getAttribute("notice_id");
                 $notice_ref = $ei_version_notice->getAttribute("notice_ref");
                 $version_notice_id = $ei_version_notice->getAttribute("version_notice_id");
                 $lang = $ei_version_notice->getAttribute("lang");
                 //recherche du profil en base
                 if ($notice_id != null && $notice_ref != null && $version_notice_id != null && $lang != null) {
                     $q = Doctrine_Core::getTable('EiVersionNotice')->findOneByNoticeIdAndNoticeRefAndVersionNoticeIdAndLang($notice_id, $notice_ref, $version_notice_id, $lang);
                     if ($q && $q != null) {
                         //si l'element existe , on fait une mise à jour
                         $q->setName($ei_version_notice->getElementsByTagName("name")->item(0)->nodeValue);
                         $q->setDescription($ei_version_notice->getElementsByTagName("description")->item(0)->nodeValue);
                         $q->setExpected($ei_version_notice->getElementsByTagName("expected")->item(0)->nodeValue);
                         $q->setResult($ei_version_notice->getElementsByTagName("result")->item(0)->nodeValue);
                         $q->setIsActive($ei_version_notice->getElementsByTagName("is_active")->item(0)->nodeValue);
                         $q->save($conn);
                     } else {
                         //l'élément n'existe pas encore, et dans ce cas on le crée
                         $new_ei_version_notice = new EiVersionNotice();
                         $new_ei_version_notice->setNoticeId($notice_id);
                         $new_ei_version_notice->setNoticeRef($notice_ref);
                         $new_ei_version_notice->setVersionNoticeId($version_notice_id);
                         $new_ei_version_notice->setLang($lang);
                         $new_ei_version_notice->setDescription($ei_version_notice->getElementsByTagName("description")->item(0)->nodeValue);
                         $new_ei_version_notice->setExpected($ei_version_notice->getElementsByTagName("expected")->item(0)->nodeValue);
                         $new_ei_version_notice->setResult($ei_version_notice->getElementsByTagName("result")->item(0)->nodeValue);
                         $new_ei_version_notice->setName($ei_version_notice->getElementsByTagName("name")->item(0)->nodeValue);
                         $new_ei_version_notice->setIsActive($ei_version_notice->getElementsByTagName("is_active")->item(0)->nodeValue);
                         $collection->add($new_ei_version_notice);
                     }
                 }
             }
             if ($collection->getFirst()) {
                 $collection->save($conn);
             }
             //Sauvegarde de la collection
             return 1;
         }
         return null;
     }
 }
Exemple #13
0
 /**
  * Add a group of wiki pages selected to a category
  * @param integer $category_id
  * @param array $wikiIDS
  * @param integer $locale
  */
 public static function addWikiPages2Categories($category_id, $wikiIDS)
 {
     $records = new Doctrine_Collection('Wikilinks');
     self::removeWikiCategoriesPages($category_id);
     for ($i = 0; $i < count($wikiIDS); $i++) {
         $records[$i]->category_id = $category_id;
         $records[$i]->wiki_id = $wikiIDS[$i];
     }
     $records->save();
     return true;
 }
Exemple #14
0
 public function testInit()
 {
     $user = new BookmarkUser();
     $user['name'] = 'Anonymous';
     $user->save();
     $pages = new Doctrine_Collection('Page');
     $pages[0]['name'] = 'Yahoo';
     $pages[0]['url'] = 'http://www.yahoo.com';
     $pages->save();
     $this->assertEqual(count($pages), 1);
 }
Exemple #15
0
 private function _saveEmployeeWorkShift($workShiftId, $empArray)
 {
     $empWorkShiftCollection = new Doctrine_Collection('EmployeeWorkShift');
     for ($i = 0; $i < sizeof($empArray); $i++) {
         $empWorkShift = new EmployeeWorkShift();
         $empWorkShift->setWorkShiftId($workShiftId);
         $empWorkShift->setEmpNumber($empArray[$i]);
         $empWorkShiftCollection->add($empWorkShift);
     }
     $this->getWorkShiftService()->saveEmployeeWorkShiftCollection($empWorkShiftCollection);
 }
 public function initRelated(Doctrine_Record $record, $name)
 {
     if (!isset($this->_initializedRelations[$record->getOid()][$name])) {
         $relation = $record->getTable()->getRelation($name);
         $coll = new Doctrine_Collection($relation->getTable()->getComponentName());
         $coll->setReference($record, $relation);
         $record[$name] = $coll;
         $this->_initializedRelations[$record->getOid()][$name] = true;
     }
     return true;
 }
Exemple #17
0
 public function loadCategoriesConnections($cats, &$dataArray)
 {
     $coll = new Doctrine_Collection('ProductGroup', 'import_code');
     $allCats = Doctrine::getTable('ProductGroup')->createQuery('imported_groups')->from('ProductGroup pg')->where('pg.import_code != ?', 'NULL')->execute();
     $allCats = $coll->merge($allCats);
     foreach ($cats as $index => $cat) {
         if ($allCats->contains($cat['id'])) {
             $cat_obj = $allCats->get($cat['id']);
             $dataArray['ProductGroups'][$index]['group_id'] = $cat_obj['id'];
         }
     }
 }
 public function getVotosAus()
 {
     $this->getCamara() == 'C.Diputados' ? $camara = 'D' : ($camara = 'S');
     $parlamentarios = Doctrine_Core::getTable('Parlamentario')->createQuery('p')->where('p.senador_diputado = ?', $camara)->andWhere('p.activo = ?', 1)->execute();
     $ausentes = new Doctrine_Collection('Parlamentario');
     foreach ($parlamentarios as $i => $parl) {
         if (Doctrine_Core::getTable('VotacionParlamentario')->find(array($this->getIdVotacion(), $parl->getIdParlamentario())) == null) {
             $ausentes->add($parl);
         }
     }
     return $ausentes;
 }
Exemple #19
0
 public function executeDissociate(sfWebRequest $request)
 {
     $this->rfid_groupe = $this->getRoute()->getObject();
     $rfids = Doctrine_Core::getTable('Rfid')->findByGroupeId($this->rfid_groupe->getGuid());
     $collection = new Doctrine_Collection('Rfid');
     foreach ($rfids as $rfid) {
         $rfid->setGroupeId(null);
         $collection->add($rfid);
     }
     $collection->save();
     $this->redirect('@rfid_groupe');
 }
 public function getResults()
 {
     if (is_null($this->results)) {
         $this->getQuery()->orderBy($this->sqlOrderColumn . ' ' . $this->sqlOrder);
         $this->results = parent::getResults();
         if ($this->sqlOrder !== $this->listOrder) {
             $obj = new Doctrine_Collection($this->results->getTable(), $this->results->getKeyColumn());
             $obj->fromArray(array_reverse($this->results->toArray(true)));
             $this->results = $obj;
         }
     }
     return $this->results;
 }
 /**
  * @param $campaign_id
  * @param $orders
  */
 public function getAllCampaignExecutions($campaign_id, $orders = array())
 {
     // Création de la requête SQL de récupération
     $sql = "SELECT * FROM ei_campaign_status_vw WHERE campaign_id = " . $campaign_id . " ORDER BY created_at DESC;";
     // Récupération des résultats.
     $resultats = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll($sql);
     // Création de la collection.
     $collection = new Doctrine_Collection("EiCampaignExecution");
     foreach ($resultats as $resultat) {
         $collection->add($this->createObjectStatusFromArray($resultat));
     }
     return $collection;
 }
 public function updateObject($values = null)
 {
     $issues = new Doctrine_Collection('Issue');
     $values = $this->getChangedValues();
     foreach ($this->ids as $id) {
         $issue = Doctrine::getTable('Issue')->getForShow(array('id' => $id));
         $issue->takeSnapshot();
         $issue->fromArray($values);
         $issue->addActivityNote($this->getValue('body'));
         $issues->add($issue);
     }
     $this->object = $issues;
     return $issues;
 }
 public function testInitData()
 {
     // Since the tests do a $this->objTable()->clear() before each method call
     // using the User model is not recommended for this test
     $albums = new Doctrine_Collection('Album');
     $albums[0]->name = 'Revolution';
     $albums[0]->Song[0]->title = 'Revolution';
     $albums[0]->Song[1]->title = 'Hey Jude';
     $albums[0]->Song[2]->title = 'Across the Universe';
     $albums[0]->Song[3]->title = 'Michelle';
     $albums->save();
     $this->assertEqual(count($albums[0]->Song), 4);
     $this->_albums = $albums;
 }
 /**
  *
  * @return Doctrine_Collection 
  */
 protected function getSampleDoctrineCollection()
 {
     $employee1 = new Employee();
     $employee2 = new Employee();
     $employee3 = new Employee();
     $employee1->fromArray(array('firstName' => 'John', 'lastName' => 'Smith'));
     $employee2->fromArray(array('firstName' => 'John', 'lastName' => 'Carter'));
     $employee3->fromArray(array('firstName' => 'John', 'lastName' => 'Jayapala'));
     $collection = new Doctrine_Collection('Employee');
     $collection->add($employee1);
     $collection->add($employee2);
     $collection->add($employee3);
     return $collection;
 }
 public function testMultiplePrimaryKeys()
 {
     $r = new Doctrine_Collection('NestReference');
     $r[0]->parent_id = 1;
     $r[0]->child_id = 2;
     $r[1]->parent_id = 2;
     $r[1]->child_id = 3;
     $r->save();
     $r->delete();
     $this->conn->clear();
     $q = new Doctrine_Query();
     $coll = $q->from('NestReference')->execute();
     $this->assertEqual(count($coll), 0);
 }
 public function testInitData()
 {
     $users = new Doctrine_Collection('User');
     $users[0]->name = 'John';
     $users[0]->Phonenumber[0]->phonenumber = '123 123';
     $users[0]->Phonenumber[1]->phonenumber = '222 222';
     $users[0]->Phonenumber[2]->phonenumber = '333 333';
     $users[1]->name = 'John';
     $users[2]->name = 'James';
     $users[2]->Phonenumber[0]->phonenumber = '222 344';
     $users[2]->Phonenumber[1]->phonenumber = '222 344';
     $users[3]->name = 'James';
     $users[3]->Phonenumber[0]->phonenumber = '123 123';
     $users->save();
 }
Exemple #27
0
 /**
  * fetchRelatedFor
  *
  * fetches a component related to given record
  *
  * @param Doctrine_Record $record
  * @return Doctrine_Record|Doctrine_Collection
  */
 public function fetchRelatedFor(Doctrine_Record $record)
 {
     $id = array();
     $localTable = $record->getTable();
     foreach ((array) $this->definition['local'] as $local) {
         $value = $record->get($localTable->getFieldName($local));
         if (isset($value)) {
             $id[] = $value;
         }
     }
     if ($this->isOneToOne()) {
         if (!$record->exists() || empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
             $related = $this->getTable()->create();
         } else {
             $dql = 'FROM ' . $this->getTable()->getComponentName() . ' WHERE ' . $this->getCondition();
             $coll = $this->getTable()->getConnection()->query($dql, $id);
             $related = $coll[0];
         }
         $related->set($related->getTable()->getFieldName($this->definition['foreign']), $record, false);
     } else {
         if (!$record->exists() || empty($id) || !$this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
             $related = Doctrine_Collection::create($this->getTable());
         } else {
             $query = $this->getRelationDql(1);
             $related = $this->getTable()->getConnection()->query($query, $id);
         }
         $related->setReference($record, $this);
     }
     return $related;
 }
Exemple #28
0
 public function fetchRelatedFor(Doctrine_Record $record)
 {
     $id = $record->getIncremented();
     if (empty($id) || !$this->definition['table']->getAttribute(Doctrine_Core::ATTR_LOAD_REFERENCES)) {
         return Doctrine_Collection::create($this->getTable());
     } else {
         $q = new Doctrine_RawSql($this->getTable()->getConnection());
         $assocTable = $this->getAssociationFactory()->getTableName();
         $tableName = $record->getTable()->getTableName();
         $identifierColumnNames = $record->getTable()->getIdentifierColumnNames();
         $identifier = array_pop($identifierColumnNames);
         $sub = 'SELECT ' . $this->getForeignRefColumnName() . ' FROM ' . $assocTable . ' WHERE ' . $this->getLocalRefColumnName() . ' = ?';
         $condition[] = $tableName . '.' . $identifier . ' IN (' . $sub . ')';
         $joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getForeignRefColumnName();
         if ($this->definition['equal']) {
             $sub2 = 'SELECT ' . $this->getLocalRefColumnName() . ' FROM ' . $assocTable . ' WHERE ' . $this->getForeignRefColumnName() . ' = ?';
             $condition[] = $tableName . '.' . $identifier . ' IN (' . $sub2 . ')';
             $joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getLocalRefColumnName();
         }
         $q->select('{' . $tableName . '.*}, {' . $assocTable . '.*}')->from($tableName . ' INNER JOIN ' . $assocTable . ' ON ' . implode(' OR ', $joinCondition))->where(implode(' OR ', $condition))->orderBy($tableName . '.' . $identifier . ' ASC');
         if ($orderBy = $this->getOrderByStatement($tableName, true)) {
             $q->addOrderBy($orderBy);
         }
         $q->addComponent($tableName, $this->getClass());
         $path = $this->getClass() . '.' . $this->getAssociationFactory()->getComponentName();
         if ($this->definition['refClassRelationAlias']) {
             $path = $this->getClass() . '.' . $this->definition['refClassRelationAlias'];
         }
         $q->addComponent($assocTable, $path);
         $params = $this->definition['equal'] ? array($id, $id) : array($id);
         $res = $q->execute($params);
         return $res;
     }
 }
 public function getSegmentItems($items, $root_level = 0, $iterations = null)
 {
     $segment = new Doctrine_Collection('csNavigationItem');
     foreach ($items as $item) {
         $children = $this->getSegmentItems($item->getChildren(), $root_level, $iterations);
         // If the level is beneath this one, return the children of this object
         if ($item->level <= $root_level) {
             $segment->merge($children);
         } elseif (!$iterations || $item->getLevel() <= $root_level + $iterations) {
             $new_segment = clone $item;
             $new_segment->setChildren($children);
             $segment[] = $new_segment;
         }
     }
     return $segment;
 }
 /**
  * Send email to audience, and if requested copy to sender
  *
  * @param Doctrine_Collection $object
  * @param Array $form_values
  */
 protected function notifyAudience($object, $form_values, $route_name)
 {
     $user = $this->getUser();
     $signed_in = $user->isAuthenticated() ? true : false;
     $from_email = $form_values['from_email'];
     $to_email = $this->getRecipients($form_values['to_email']);
     // Variables
     $vars = array('object' => $object);
     $vars['form_values'] = $form_values;
     $vars['route_name'] = $route_name;
     if ($signed_in) {
         $vars['from_text'] = sprintf('%s %s (%s)', $user->getGuardUser()->getFirstName(), $user->getGuardUser()->getLastName(), $user->getGuardUser()->getEmailAddress());
     } else {
         $vars['from_text'] = sprintf('%s (%s)', $form_values['from_name'], $form_values['from_email']);
     }
     $vars['name'] = $object->getTitle() ? $object->getTitle() : __('Item Page');
     // Email templates
     $message_html = $this->getPartial('rtSocial/email_html', $vars);
     $message_html = $this->getPartial('rtEmail/layout_html', array('content' => $message_html));
     $message_plain = $this->getPartial('rtSocial/email_plain', $vars);
     $message_plain = $this->getPartial('rtEmail/layout_plain', array('content' => html_entity_decode($message_plain)));
     // Subject
     $subject_text = 'I thought you might be interested in this';
     $subject = $object->getTitle() ? sprintf('%s: %s', $subject_text, $object->getTitle()) : $subject_text . '...';
     // Email
     $message = Swift_Message::newInstance()->setFrom($from_email)->setTo($to_email)->setSubject($subject)->setBody($message_html, 'text/html')->addPart($message_plain, 'text/plain');
     // Send copy to sender
     if ($form_values['copy'] == true) {
         $message->setBcc($from_email);
     }
     $this->getMailer()->send($message);
 }