Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
clivi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NF17 - CAMP - P14
clivi
Commits
b54dc94a
Commit
b54dc94a
authored
10 years ago
by
Matthieu Guffroy
Browse files
Options
Downloads
Patches
Plain Diff
implement foreignfield
parent
54452c19
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
class/foreignfield.php
+50
-0
50 additions, 0 deletions
class/foreignfield.php
class/objet.php
+4
-0
4 additions, 0 deletions
class/objet.php
class/race.php
+4
-0
4 additions, 0 deletions
class/race.php
with
58 additions
and
0 deletions
class/foreignfield.php
0 → 100644
+
50
−
0
View file @
b54dc94a
<?php
class
ForeignField
{
protected
$name
;
protected
$value
;
protected
$primary
;
protected
$choices
;
public
function
__construct
(
$name
,
&
$value
,
$primary
=
false
)
{
$this
->
name
=
$name
;
$this
->
value
=&
$value
;
$this
->
primary
=
$primary
;
$this
->
choices
=
ucfirst
(
$name
)
::
getAll
();
}
public
function
html
(
$form
)
{
// Todo, if isset($_POST[$this->name]) && !$this->validate() => Show a error msg explanation for this line.
$disabled
=
""
;
if
(
$this
->
primary
&&
$form
->
action
==
"Ajouter"
)
{
return
""
;
}
if
(
$this
->
primary
&&
$form
->
action
==
"Modifier"
)
{
$disabled
=
"disabled"
;
}
$html
=
'<div class="form-group">
<label for="form'
.
$this
->
name
.
'">'
.
ucfirst
(
$this
->
name
)
.
'</label>
<select class="form-control" name="'
.
$this
->
name
.
'">'
;
foreach
(
$this
->
choices
as
$value
)
{
if
(
$this
->
value
==
$value
->
{
$value
->
$_primaryAttr
}())
{
$selected
=
"selected"
}
else
{
$selected
=
""
}
$html
.
=
"<option value="
.
$value
->
{
$value
->
$_primaryAttr
}()
.
" "
.
$selected
.
" >"
.
$value
->
str
()
.
"</option>"
;
}
$html
.
=
'</select>
</div>'
;
return
$html
;
}
/*
Load the data from $_POST
and return false, if data is not valid !
*/
public
function
validate
()
{
// On ne peut pas changer la valeur de la clef primaire
if
(
$this
->
primary
&&
$this
->
value
)
{
return
true
;
}
$this
->
value
=
$_POST
[
$this
->
name
];
return
true
;
}
}
This diff is collapsed.
Click to expand it.
class/objet.php
+
4
−
0
View file @
b54dc94a
...
...
@@ -136,4 +136,8 @@ class Objet
$ligne
=
$requete_prepare
->
fetch
(
PDO
::
FETCH_ASSOC
);
$this
->
fromDb
(
$ligne
);
}
public
function
str
()
{
return
self
::
dbName
()
.
" #"
.
$this
->
{
$this
->
_primaryAttr
};
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
class/race.php
+
4
−
0
View file @
b54dc94a
...
...
@@ -6,6 +6,10 @@ class Race extends Objet
protected
$nom
;
protected
$espece
;
protected
$prix_intervention
;
public
$_specialFields
=
array
(
"espece"
=>
array
(
"t"
=>
"ForeignField"
));
public
function
nom
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment