예제 #1
0
파일: ForeignKey.php 프로젝트: swk/bluebox
 /**
  * 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;
 }
예제 #2
0
파일: Indexer.php 프로젝트: swk/bluebox
 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 = Doctrine_Collection::create('Doctrine_File');
     foreach ($files as $file) {
         $coll[]->url = $file;
     }
     $coll->save();
 }
예제 #3
0
파일: Nest.php 프로젝트: tests1/zendcasts
 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;
     }
 }
예제 #4
0
 public function getApiVersions()
 {
     $versions = Doctrine_Collection::create('SymfonyApiVersion');
     $versions->setKeyColumn('id');
     foreach ($this['Releases'] as $release) {
         $versions->merge($release->getApiVersions());
     }
     return $versions;
 }
예제 #5
0
 public function getCities()
 {
     $mainCities = Doctrine_Collection::create('City');
     $user = sfContext::getInstance()->getUser();
     if (!$user->isAnonymous() && $user->getProfile()->getCity()) {
         $mainCities->add($user->getProfile()->getCity());
     }
     $mainCities->merge($this->createQuery()->where('weight >1')->orderBy('weight desc')->execute());
     return $mainCities;
 }
예제 #6
0
파일: RecordDriver.php 프로젝트: hunde/bsc
 public function initRelated(&$record, $name, $keyColumn = null)
 {
     if (!isset($this->_initializedRelations[$record->getOid()][$name])) {
         $relation = $record->getTable()->getRelation($name);
         $coll = Doctrine_Collection::create($relation->getTable()->getComponentName(), $keyColumn);
         $coll->setReference($record, $relation);
         $record[$name] = $coll;
         $this->_initializedRelations[$record->getOid()][$name] = true;
     }
     return true;
 }
 public function filterOne($wheres)
 {
     $collection = Doctrine_Collection::create($this->_table->getOption('name'));
     foreach ($this->data as $record) {
         foreach ($wheres as $property => $value) {
             if ($record[$property] == $value) {
                 return $record;
             }
         }
     }
     return null;
 }
 public function getFriends($memberId, $limit = null, $isRandom = false)
 {
     $collection = Doctrine_Collection::create('Member');
     $friendIds = $this->getFriendMemberIds($memberId);
     if ($isRandom) {
         shuffle($friendIds);
     }
     $limitedFriendIds = is_null($limit) ? $friendIds : array_slice($friendIds, 0, $limit);
     foreach ($limitedFriendIds as $friendId) {
         $collection[] = Doctrine::getTable('Member')->find($friendId);
     }
     return $collection;
 }
 public function testGetAllowedWorkflowItems()
 {
     $flow = "Time";
     $state = "SUBMITTED";
     $role = "ESS USER";
     $fetchedRecord1 = TestDataService::fetchObject('WorkflowStateMachine', 10);
     $fetchedRecord2 = TestDataService::fetchObject('WorkflowStateMachine', 12);
     $expected = Doctrine_Collection::create('WorkflowStateMachine');
     $expected->add($fetchedRecord1);
     $expected->add($fetchedRecord2);
     $acessFlowStateMachineDaoMock = $this->getMock('AccessFlowStateMachineDao', array('getAllowedWorkflowItems'));
     $acessFlowStateMachineDaoMock->expects($this->once())->method('getAllowedWorkflowItems')->with($flow, $state, $role)->will($this->returnValue($expected));
     $this->accessFlowStateMachineService->setAccessFlowStateMachineDao($acessFlowStateMachineDaoMock);
     $results = $this->accessFlowStateMachineService->getAllowedWorkflowItems($flow, $state, $role);
     $this->assertEquals($expected, $results);
 }
예제 #10
0
 public function configure()
 {
     /** @var sfGuardUser $object */
     $object = $this->getOption('object');
     /** @var TeamMember[]|Doctrine_Collection $links */
     $team = Doctrine_Collection::create('TeamMember');
     if (!$object->isNew()) {
         $team = $object->Team;
         foreach ($team as $i => $teamMember) {
             $this->embedForm($i, new TeamMemberForm($teamMember));
         }
     }
     for ($i = $team->count(); $i < 20; $i++) {
         $teamMember = new TeamMember();
         $teamMember->Manager = $object;
         $this->embedForm($i, new TeamMemberForm($teamMember));
     }
 }
예제 #11
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 = $record->getIncremented();
     if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine_Core::ATTR_LOAD_REFERENCES)) {
         $coll = Doctrine_Collection::create($this->getTable());
     } else {
         $coll = $this->getTable()->getConnection()->query($this->getRelationDql(1), array($id));
     }
     $coll->setReference($record, $this);
     return $coll;
 }
 /**
  * Populate the relationship $name for all records in the passed collection
  *
  * @param string $name
  * @param Doctrine_Collection $coll
  * @return void
  */
 public function populateRelated($name, Doctrine_Collection $coll)
 {
     $rel = $this->_table->getRelation($name);
     $table = $rel->getTable();
     $foreign = $rel->getForeign();
     $local = $rel->getLocal();
     if ($rel instanceof Doctrine_Relation_LocalKey) {
         foreach ($this->data as $key => $record) {
             foreach ($coll as $k => $related) {
                 if ($related[$foreign] == $record[$local]) {
                     $this->data[$key]->setRelated($name, $related);
                 }
             }
         }
     } elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
         foreach ($this->data as $key => $record) {
             if (!$record->exists()) {
                 continue;
             }
             $sub = Doctrine_Collection::create($table);
             foreach ($coll as $k => $related) {
                 if ($related[$foreign] == $record[$local]) {
                     $sub->add($related);
                     $coll->remove($k);
                 }
             }
             $this->data[$key]->setRelated($name, $sub);
         }
     } elseif ($rel instanceof Doctrine_Relation_Association) {
         $identifier = $this->_table->getIdentifier();
         $asf = $rel->getAssociationFactory();
         $name = $table->getComponentName();
         foreach ($this->data as $key => $record) {
             if (!$record->exists()) {
                 continue;
             }
             $sub = Doctrine_Collection::create($table);
             foreach ($coll as $k => $related) {
                 if ($related->get($local) == $record[$identifier]) {
                     $sub->add($related->get($name));
                 }
             }
             $this->data[$key]->setRelated($name, $sub);
         }
     }
 }
 /**
  * Создать коллекцию опреаций
  */
 public function makeOperationCollection($count, Account $account = null, array $props = array(), $save = true)
 {
     $coll = Doctrine_Collection::create('Operation');
     if (!$account) {
         $account = $this->makeAccount(null, array(), $save);
     }
     for ($i = 0; $i < (int) $count; $i++) {
         if (isset($props[$i])) {
             $itemProps = $props[$i];
         } else {
             $itemProps = array();
         }
         $coll->add($this->makeOperation($account, $itemProps, $save));
     }
     return $coll;
 }
 public function getInvitingMembers()
 {
     return Doctrine_Collection::create('Member');
 }
예제 #15
0
 function getServiciosAccesibles($entidad = 0)
 {
     foreach ($this->Servicios as $s) {
         $array_servicios[] = $s->codigo;
     }
     $servicios = Doctrine_Collection::create('Servicio');
     if ($this->interministerial) {
         if (!$entidad) {
             $servicios = Doctrine::getTable('Servicio')->findAll();
         } else {
             $servicios = Doctrine::getTable('Entidad')->find($entidad)->Servicios;
         }
     } else {
         if ($this->ministerial) {
             if (!$entidad) {
                 $servicios = Doctrine_Query::create()->from('Servicio s, s.Entidad e, e.Servicios serv')->whereIn('serv.codigo', $array_servicios)->execute();
             } else {
                 $servicios = Doctrine_Query::create()->from('Servicio s, s.Entidad e, e.Servicios serv')->whereIn('serv.codigo', $array_servicios)->andWhere('e.codigo = ?', $entidad)->execute();
             }
         } else {
             if (!$entidad) {
                 $servicios = $this->Servicios;
             } else {
                 $servicios = Doctrine_Query::create()->from('Servicio s, s.Entidad e')->whereIn('s.codigo', $array_servicios)->andWhere('e.codigo = ?', $entidad)->execute();
             }
         }
     }
     return $servicios;
 }
예제 #16
0
$t->info('Test deleting a collection of sortable items');
    
    $d1 = new SortableArticle();
    $d1->name = 'Article To Delete 1';
    $d1->save();

    $d2 = new SortableArticle();
    $d2->name = 'Article To Delete 2';
    $d2->save();
    
    $d3 = new SortableArticle();
    $d3->name = 'Article To Delete 3';
    $d3->save();
    
    $d4 = new SortableArticle();
    $d4->name = 'Article To Delete 4';
    $d4->save();
    
    $collection = Doctrine_Collection::create('SortableArticle');
    $collection[] = $d1;
    $collection[] = $d2;
    $collection[] = $d3;
    $collection[] = $d4;
    
    $collection->delete();
    
    $t->ok(!$d1->exists(), '"Article To Delete 1" has been removed');
    $t->ok(!$d2->exists(), '"Article To Delete 2" has been removed');
    $t->ok(!$d3->exists(), '"Article To Delete 3" has been removed');
    $t->ok(!$d4->exists(), '"Article To Delete 4" has been removed');