本文整理汇总了PHP中PropelObjectCollection::setModel方法的典型用法代码示例。如果您正苦于以下问题:PHP PropelObjectCollection::setModel方法的具体用法?PHP PropelObjectCollection::setModel怎么用?PHP PropelObjectCollection::setModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropelObjectCollection
的用法示例。
在下文中一共展示了PropelObjectCollection::setModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Form constructor.
*
* Available options:
* - embedded_form_class: The class name of the forms to embed. Uses the model name by default.
* (a form based on a collection of Book objects embeds BookForm objects)
* - item_pattern: The pattern used to name each embedded form. Defaults to '%index%'.
* - add_delete: Whether to add a delete widget for each object. Defaults to true.
* - delete_name: Name of the delete widget. Defaults to 'delete'.
* - delete_widget: Optional delete widget object. If left null, uses a sfWidgetFormDelete instance.
* - alert_text: The text of the Javascript alert to show
* - hide_parent: Whether to hide the parent form when clicking the checkbox
* - parent_level: The number of times parentNode must be called to reach the parent to hide.
* Recommended values: 6 for embedded form, 7 for merged form
* - remove_fields: The list of fields to remove from the embedded object forms
*
* @param PropelCollection $collection A collection of Propel objects
* used to initialize default values
* @param array $options An array of options
* @param string $CSRFSecret A CSRF secret (false to disable CSRF protection, null to use the global CSRF secret)
*
* @see sfForm
*/
public function __construct($collection = null, $options = array(), $CSRFSecret = null)
{
$options = array_merge(array(
'item_pattern' => '%index%',
'add_delete' => false,
'delete_name' => 'delete',
'delete_widget' => null,
'remove_fields' => array(),
), $options);
if (!$collection)
{
$this->model = $options['model'];
$collection = new PropelObjectCollection();
$collection->setModel($this->model);
$this->collection = $collection;
}
else
{
if (!$collection instanceof PropelObjectCollection)
{
throw new sfException(sprintf('The "%s" form only accepts a PropelObjectCollection object.', get_class($this)));
}
$this->collection = $collection;
$this->model = $collection->getModel();
}
$this->isEmpty = $this->getCollection()->isEmpty();
parent::__construct(array(), $options, $CSRFSecret);
}
示例2: createBooks
protected function createBooks($nb = 15, $con = null)
{
BookQuery::create()->deleteAll($con);
$books = new PropelObjectCollection();
$books->setModel('Book');
for ($i = 0; $i < $nb; $i++) {
$b = new Book();
$b->setTitle('Book' . $i);
$books[] = $b;
}
$books->save($con);
}
示例3: testFromArray
public function testFromArray()
{
$author = new Author();
$author->setFirstName('Jane');
$author->setLastName('Austen');
$author->save();
$books = array(array('Title' => 'Mansfield Park', 'AuthorId' => $author->getId()), array('Title' => 'Pride And PRejudice', 'AuthorId' => $author->getId()));
$col = new PropelObjectCollection();
$col->setModel('Book');
$col->fromArray($books);
$col->save();
$nbBooks = PropelQuery::from('Book')->count();
$this->assertEquals(6, $nbBooks);
$booksByJane = PropelQuery::from('Book b')->join('b.Author a')->where('a.LastName = ?', 'Austen')->count();
$this->assertEquals(2, $booksByJane);
}
示例4: testConstruct
public function testConstruct()
{
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\\Bundle\\PropelAclBundle\\Model\\Acl\\Entry');
$acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
$model = $this->createEntry();
$model->setAuditFailure(true);
$model->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity()));
$entry = new Entry($model, $acl);
$this->assertEquals($model->getMask(), $entry->getMask());
$this->assertEquals($model->getGranting(), $entry->isGranting());
$this->assertEquals($model->getGrantingStrategy(), $entry->getStrategy());
$this->assertEquals($model->getAuditFailure(), $entry->isAuditFailure());
$this->assertEquals($model->getAuditSuccess(), $entry->isAuditSuccess());
$this->assertEquals($this->getRoleSecurityIdentity(), $entry->getSecurityIdentity());
return $entry;
}
示例5: showRoles
public function showRoles()
{
if (!$this->hasPermission(self::PERMISSION_ROLES)) {
throw new Exception('You dont have permission to access this view.');
}
$this->addMenu();
$user = User::getUser();
$backendModules = Curry_Backend::getBackendList();
$disable = array();
$backend = array("*" => "All");
if (!$user->hasAccess('*')) {
$disable[] = '*';
}
foreach ($backendModules as $backendClass => $backendName) {
$backend[$backendClass] = $backendName;
$permissions = method_exists($backendClass, 'getPermissions') ? call_user_func(array($backendClass, 'getPermissions')) : array();
foreach ($permissions as $permission) {
$backend[$backendClass . "/" . $permission] = Curry_Core::SELECT_TREE_PREFIX . $permission;
if (!$user->hasAccess($backendClass . "/" . $permission)) {
$disable[] = $backendClass . "/" . $permission;
}
}
if (!$user->hasAccess($backendClass)) {
$disable[] = $backendClass;
}
}
$content = array();
$contentAccess = array("*" => "All") + Curry_Module::getModuleList();
$allContentAccess = $user->hasAccess('Curry_Backend_Content/*');
foreach ($contentAccess as $k => $v) {
$content['Curry_Backend_Content/' . $k] = $v;
if (!$allContentAccess && !$user->hasAccess('Curry_Backend_Content/' . $k)) {
$disable[] = 'Curry_Backend_Content/' . $k;
}
}
$form = new Curry_ModelView_Form('UserRole', array('elements' => array('backend' => array('multiselect', array('label' => 'Backend access', 'multiOptions' => $backend, 'size' => 10, 'order' => 1, 'disable' => $disable, 'validators' => array(array('InArray', true, array(array_diff(array_keys($backend), $disable)))))), 'content' => array('multiselect', array('label' => 'Content access', 'multiOptions' => $content, 'size' => 10, 'order' => 2, 'disable' => $disable, 'validators' => array(array('InArray', true, array(array_diff(array_keys($content), $disable))))))), 'onFillForm' => function (UserRole $role, $form) {
$access = UserRoleAccessQuery::create()->filterByUserRole($role)->select('Module')->find()->getArrayCopy();
$form->backend->setValue($access);
$form->content->setValue($access);
}, 'onFillModel' => function (UserRole $role, $form, $values) {
$access = array_merge((array) $values['backend'], (array) $values['content']);
$collection = new PropelObjectCollection();
$collection->setModel('UserRoleAccess');
foreach ($access as $a) {
$ura = new UserRoleAccess();
$ura->setModule($a);
$collection->append($ura);
}
$role->setUserRoleAccesss($collection);
}));
$q = UserRoleQuery::create();
$list = new Curry_ModelView_List($q, array('modelForm' => $form));
$list->addAction('file_permissions', array('action' => $this->getFileAccessList(), 'class' => 'inline', 'single' => true));
$list->show($this);
}
示例6: testContentsDeletion
/**
* Basic deletion of a 1-to-n relation through set<RelationName>().
*
*/
public function testContentsDeletion()
{
$contentCollection = new PropelObjectCollection();
$contentCollection->setModel('MoreRelationTest\\Content');
$content = new \MoreRelationTest\Content();
$content->setTitle('I should be alone :-(');
$contentCollection[] = $content;
$page = \MoreRelationTest\PageQuery::create()->findOne();
$id = $page->getId();
$count = \MoreRelationTest\ContentQuery::create()->filterByPageId($id)->count();
$this->assertEquals(3, $count, 'We created for each page 3 contents.');
$page->setContents($contentCollection);
$page->save();
unset($page);
$count = \MoreRelationTest\ContentQuery::create()->filterByPageId($id)->count();
$this->assertEquals(1, $count, 'We assigned a collection of only one item.');
}
示例7: buildCollection
protected function buildCollection($arr)
{
$coll = new PropelObjectCollection();
$coll->setData($arr);
$coll->setModel('Table10');
return $coll;
}
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:7,代码来源:NestedSetBehaviorQueryBuilderModifierWithScopeTest.php
示例8: populateCreatedAt
protected function populateCreatedAt()
{
Table2Query::create()->deleteAll();
$ts = new PropelObjectCollection();
$ts->setModel('Table2');
for ($i = 0; $i < 10; $i++) {
$t = new Table2();
$t->setTitle('CreatedAt' . $i);
$t->setCreatedAt(time() - $i * 24 * 60 * 60 - 30);
$ts[] = $t;
}
$ts->save();
}
示例9: testUpdateClassFieldAuditing
/**
* @depends testUpdateObjectAuditing
*/
public function testUpdateClassFieldAuditing()
{
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\\Bundle\\PropelAclBundle\\Model\\Acl\\Entry');
$entry = $this->createEntry();
$entry->setFieldName('name')->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity()))->setAclClass($this->getAclClass());
$collection->append($entry);
$acl = new AuditableAcl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
$aces = $acl->getClassFieldAces('name');
$this->assertCount(1, $aces);
$acl->updateClassFieldAuditing(0, 'name', true, true);
$aces = $acl->getClassFieldAces('name');
$this->assertTrue($aces[0]->isAuditSuccess());
$this->assertTrue($aces[0]->isAuditFailure());
$acl->updateClassFieldAuditing(0, 'name', false, false);
$aces = $acl->getClassFieldAces('name');
$this->assertFalse($aces[0]->isAuditSuccess());
$this->assertFalse($aces[0]->isAuditFailure());
}
示例10: createEmptyAcl
protected function createEmptyAcl($identifier = 1, array $securityIdentities = array(), AclInterface $parentAcl = null, $inherited = null)
{
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\\PropelBundle\\Model\\Acl\\Entry');
return new MutableAcl($collection, $this->getAclObjectIdentity($identifier), new PermissionGrantingStrategy(), $securityIdentities, $parentAcl, $inherited, $this->con);
}
示例11: testSerializeUnserialize
public function testSerializeUnserialize()
{
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\\PropelBundle\\Model\\Acl\\Entry');
$entry = $this->createEntry();
$entry->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity('ROLE_ADMIN')))->setAclClass($this->getAclClass());
$collection->append($entry);
$acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
$serialized = serialize($acl);
$unserialized = unserialize($serialized);
$this->assertNotEmpty($serialized);
$this->assertNotEmpty($unserialized);
$this->assertInstanceOf('Propel\\PropelBundle\\Security\\Acl\\Domain\\Acl', $unserialized);
$this->assertEquals($serialized, serialize($unserialized));
}
示例12: getModelCollectionInstance
/**
* @param string $class
*
* @return \PropelObjectCollection
*/
public function getModelCollectionInstance($class)
{
$collection = new \PropelObjectCollection();
$collection->setModel($class);
return $collection;
}
示例13: getSaisiesContradictoiresManquementObligation
/**
*
* Renvoi un liste de saisies qui sont en contradiction avec celle la concernant le manquement des obligations de presence (apparition dans le bulletin)
*
* @param boolean $retourne_booleen la fonction retourne vrai ou faux selon qu'il y ai des saisies contradictoires au lieu de retourner une collection
*
* @return mixed boolean or PropelObjectCollection AbsenceEleveSaisie[]
*
*/
public function getSaisiesContradictoiresManquementObligation($retourne_booleen = false) {
//if (isset($this->boolSaisiesContradictoiresManquementObligation)) {echo 'mis en cache';} else {echo 'pas de cache';}
if (($retourne_booleen && (!isset($this->boolSaisiesContradictoiresManquementObligation) || $this->boolSaisiesContradictoiresManquementObligation === null))
|| (!$retourne_booleen && (!isset($this->collectionSaisiesContradictoiresManquementObligation) || $this->collectionSaisiesContradictoiresManquementObligation === null))) {
$result = new PropelObjectCollection();
$result->setModel('AbsenceEleveSaisie');
if ($this->getEleve() === null) {
$this->boolSaisiesContradictoiresManquementObligation = false;
$this->collectionSaisiesContradictoiresManquementObligation = $result;
} else {
//on regarde les saisies sur cet eleve
$eleve = $this->getEleve();
$manque = $this->getManquementObligationPresence();
foreach ($eleve->getAbsenceEleveSaisiesFilterByDate($this->getDebutAbs(null), $this->getFinAbs(null)) as $saisie) {
if ($manque !== $saisie->getManquementObligationPresence()) {
if ($retourne_booleen) {
$this->boolSaisiesContradictoiresManquementObligation = true;
return true;
}
$result->append($saisie);
}
}
if ($manque == true) {
//on recupere les saisies de marquage d'absence (donc sans eleves) qui se chevauchent avec celle-la
//optimisation : utiliser la requete pour stocker ca
if (isset($_REQUEST['query_AbsenceEleveSaisieQuery_getSaisiesContradictoires_'.$this->getDebutAbs('U').'_'.$this->getFinAbs('U')])
&& $_REQUEST['query_AbsenceEleveSaisieQuery_getSaisiesContradictoires_'.$this->getDebutAbs('U').'_'.$this->getFinAbs('U')] != null) {
$saisie_col = $_REQUEST['query_AbsenceEleveSaisieQuery_getSaisiesContradictoires_'.$this->getDebutAbs('U').'_'.$this->getFinAbs('U')];
} else {
$query = AbsenceEleveSaisieQuery::create();
$query->filterByPlageTemps($this->getDebutAbs(null), $this->getFinAbs(null))
->add(AbsenceEleveSaisiePeer::ELEVE_ID, NULL)
->addOr(AbsenceEleveSaisiePeer::ELEVE_ID, $this->getEleveId())
;
$saisie_col = $query->find();
$_REQUEST['query_AbsenceEleveSaisieQuery_getSaisiesContradictoires_'.$this->getDebutAbs('U').'_'.$this->getFinAbs('U')] = $saisie_col;
}
//on va filtrer pour supprimer de la liste les aid, classe ou groupe qui serait le meme que cette saisie la
$temp_saisie_col = new PropelObjectCollection();
$temp_saisie_col->setModel('AbsenceEleveSaisie');
if ($this->getClasse() != null) {
foreach ($saisie_col as $saisie) {
if ($saisie->getIdClasse() != $this->getIdClasse()) {
$temp_saisie_col->append($saisie);
}
}
} elseif ($this->getGroupe() != null) {
foreach ($saisie_col as $saisie) {
if ($saisie->getIdGroupe() != $this->getIdGroupe()) {
$temp_saisie_col->append($saisie);
}
}
} elseif ($this->getAidDetails() != null) {
foreach ($saisie_col as $saisie) {
if ($saisie->getIdAid() != $this->getIdAid()) {
$temp_saisie_col->append($saisie);
}
}
} else {
foreach ($saisie_col as $saisie) {
if ($saisie->getId() != $this->getId()) {
$temp_saisie_col->append($saisie);
}
}
}
$saisie_col = $temp_saisie_col;
//on regarde si un groupe, classe ou aid auquel appartient cet eleve a été saisi et pour lequel l'eleve en question n'a pas ete saisi (c'est donc que l'eleve est present)
//on va utiliser comme periode pour determiner les classes et groupes la periode correspondant au debut de l'absence
$periode = $eleve->getPeriodeNote($this->getDebutAbs(null));
//on recupere la liste des classes de l'eleve et on regarde si il y a eu des saisies pour ces classes
$classes = $eleve->getClasses($periode);
$saisie_col_classe_id_array = $saisie_col->toKeyValue('PrimaryKey','IdClasse');
$saisie_col_array_copy = $saisie_col->getArrayCopy('Id');
foreach ($classes as $classe) {
$keys = array_keys($saisie_col_classe_id_array, $classe->getId());
if (!empty($keys)) {
//on a des saisies pour cette classe
//est-ce que l'eleve a bien été saisi absent ?
$temp_col = new PropelObjectCollection();
$bool_eleve_saisi = false;
foreach ($keys as $key) {
$saisie_temp = $saisie_col_array_copy[$key];
if ($saisie_temp->getEleveId() === null) {
$temp_col->append($saisie_temp);
}
if ($this->getEleveId() == $saisie_temp->getEleveId()) {
//.........这里部分代码省略.........
示例14: getAbsenceEleveSaisiesFilterByDate
/**
*
* Retourne une liste de saisie dont la periode de temps coincide avec les dates passees en paremetre (methode optimisee)
*
* @param $dt_debut DateTime
* @param $dt_fin DateTime
*
* @return PropelColection AbsenceEleveSaisie[]
*/
public function getAbsenceEleveSaisiesFilterByDate($dt_debut, $dt_fin) {
$result = new PropelObjectCollection();
$result->setModel('AbsenceEleveSaisie');
if ($dt_debut != null && $dt_debut->format('d/m/Y') == $dt_fin->format('d/m/Y')) {
//on a une date de debut et de fin le meme jour, on va optimiser un peu
$saisie_col = $this->getAbsenceEleveSaisiesDuJour($dt_debut);
} else {
if ($this->countAbsenceEleveSaisies() > 100) {
//il y a trop de saisie, on passe l'optimisation et on fait une requete db
$query = AbsenceEleveSaisieQuery::create()->filterByEleve($this);
$query->filterByPlageTemps($dt_debut, $dt_fin)
->leftJoinWith('AbsenceEleveSaisie.JTraitementSaisieEleve')
->leftJoinWith('JTraitementSaisieEleve.AbsenceEleveTraitement')
->leftJoinWith('AbsenceEleveTraitement.AbsenceEleveType');
return $query->distinct()->find();
} else {
$saisie_col = $this->getAbsenceEleveSaisies();
}
}
foreach ($saisie_col as $saisie) {
if ($dt_debut != null && $dt_fin!= null && $dt_debut->format('U') == $dt_fin->format('U')) {
//si on a un seul dateTime pour la plage de recherche, on renvoi les saisie qui chevauchent cette date
//ainsi que les saisies qui commence juste à cette date
if ($dt_debut->format('U') >= $saisie->getFinAbs('U')) {
continue;
}
if ($dt_fin != null && ($dt_fin->format('U') < $saisie->getDebutAbs('U'))) {
continue;
}
$result->append($saisie);
} else {
if ($dt_debut != null && ($dt_debut->format('U') >= $saisie->getFinAbs('U'))) {
continue;
}
if ($dt_fin != null && ($dt_fin->format('U') <= $saisie->getDebutAbs('U'))) {
continue;
}
$result->append($saisie);
}
}
return $result;
}
示例15: initNestedSetChildren
/**
* Initializes the $collNestedSetChildren collection.
*
* @return void
*/
public function initNestedSetChildren()
{
$this->collNestedSetChildren = new PropelObjectCollection();
$this->collNestedSetChildren->setModel('Page');
}