Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
21dab95f
Commit
21dab95f
authored
Feb 18, 2014
by
pupi1985
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small refactoring of the qa_set_up_category_field function
parent
04bd3cde
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
45 deletions
+49
-45
qa-app-format.php
qa-include/qa-app-format.php
+49
-45
No files found.
qa-include/qa-app-format.php
View file @
21dab95f
...
...
@@ -1454,82 +1454,86 @@
(or null for no maximum) and $excludecategoryid to a category that should not be included.
*/
{
$pathcategories
=
qa_category_path
(
$navcategories
,
$categoryid
);
$startpath
=
''
;
$pathcategories
=
qa_category_path
(
$navcategories
,
$categoryid
);
$startpath
=
''
;
foreach
(
$pathcategories
as
$category
)
$startpath
.=
'/'
.
$category
[
'categoryid'
];
if
(
!
isset
(
$maxdepth
))
$maxdepth
=
QA_CATEGORY_DEPTH
;
$maxdepth
=
min
(
QA_CATEGORY_DEPTH
,
$maxdepth
);
$qa_content
[
'script_rel'
][]
=
'qa-content/qa-ask.js?'
.
QA_VERSION
;
$qa_content
[
'script_onloads'
][]
=
'qa_category_select('
.
qa_js
(
$fieldname
)
.
', '
.
qa_js
(
$startpath
)
.
');'
;
$startpath
.=
'/'
.
$category
[
'categoryid'
];
$qa_content
[
'script_var'
][
'qa_cat_exclude'
]
=
$excludecategoryid
;
$qa_content
[
'script_var'
][
'qa_cat_allownone'
]
=
(
int
)
$allownone
;
$qa_content
[
'script_var'
][
'qa_cat_allownosub'
]
=
(
int
)
$allownosub
;
$qa_content
[
'script_var'
][
'qa_cat_maxdepth'
]
=
$maxdepth
;
$field
[
'type'
]
=
'select'
;
$field
[
'tags'
]
=
'name="'
.
$fieldname
.
'_0" id="'
.
$fieldname
.
'_0" onchange="qa_category_select('
.
qa_js
(
$fieldname
)
.
');"'
;
$field
[
'options'
]
=
array
();
if
(
isset
(
$maxdepth
))
$maxdepth
=
min
(
QA_CATEGORY_DEPTH
,
$maxdepth
);
else
$maxdepth
=
QA_CATEGORY_DEPTH
;
$qa_content
[
'script_rel'
][]
=
'qa-content/qa-ask.js?'
.
QA_VERSION
;
$qa_content
[
'script_onloads'
][]
=
sprintf
(
'qa_category_select(%s, %s);'
,
qa_js
(
$fieldname
),
qa_js
(
$startpath
));
$qa_content
[
'script_var'
]
=
array
(
'qa_cat_exclude'
=>
$excludecategoryid
,
'qa_cat_allownone'
=>
(
int
)
$allownone
,
'qa_cat_allownosub'
=>
(
int
)
$allownosub
,
'qa_cat_maxdepth'
=>
$maxdepth
,
);
$field
[
'type'
]
=
'select'
;
$field
[
'tags'
]
=
sprintf
(
'name="%s_0" id="%s_0" onchange="qa_category_select(%s);"'
,
$fieldname
,
$fieldname
,
qa_js
(
$fieldname
));
$field
[
'options'
]
=
array
();
// create the menu that will be shown if Javascript is disabled
if
(
$allownone
)
$field
[
'options'
][
''
]
=
qa_lang_html
(
'main/no_category'
);
// this is also copied to first menu created by Javascript
$field
[
'options'
][
''
]
=
qa_lang_html
(
'main/no_category'
);
// this is also copied to first menu created by Javascript
$keycategoryids
=
array
();
$keycategoryids
=
array
();
if
(
$allownosub
)
{
$category
=@
$navcategories
[
$categoryid
];
$upcategory
=
$category
;
while
(
true
)
{
// first get supercategories
$upcategory
=@
$navcategories
[
$upcategory
[
'parentid'
]];
$category
=
@
$navcategories
[
$categoryid
];
if
(
!
isset
(
$upcategory
))
break
;
$
keycategoryids
[
$upcategory
[
'categoryid'
]]
=
true
;
$upcategory
=
@
$navcategories
[
$category
[
'parentid'
]];
// first get supercategories
while
(
isset
(
$upcategory
))
{
$keycategoryids
[
$upcategory
[
'categoryid'
]]
=
true
;
$
upcategory
=
@
$navcategories
[
$upcategory
[
'parentid'
]]
;
}
$keycategoryids
=
array_reverse
(
$keycategoryids
,
true
);
$depth
=
count
(
$keycategoryids
);
// number of levels above
$keycategoryids
=
array_reverse
(
$keycategoryids
,
true
);
$depth
=
count
(
$keycategoryids
);
// number of levels above
if
(
isset
(
$category
))
{
$depth
++
;
// to count category itself
foreach
(
$navcategories
as
$navcategory
)
// now get siblings and self
if
(
!
strcmp
(
$navcategory
[
'parentid'
],
$category
[
'parentid'
]))
$keycategoryids
[
$navcategory
[
'categoryid'
]]
=
true
;
$keycategoryids
[
$navcategory
[
'categoryid'
]]
=
true
;
}
if
(
$depth
<
$maxdepth
)
if
(
$depth
<
$maxdepth
)
foreach
(
$navcategories
as
$navcategory
)
// now get children, if not too deep
if
(
!
strcmp
(
$navcategory
[
'parentid'
],
$categoryid
))
$keycategoryids
[
$navcategory
[
'categoryid'
]]
=
true
;
$keycategoryids
[
$navcategory
[
'categoryid'
]]
=
true
;
}
else
{
$haschildren
=
false
;
$haschildren
=
false
;
foreach
(
$navcategories
as
$navcategory
)
// check if it has any children
if
(
!
strcmp
(
$navcategory
[
'parentid'
],
$categoryid
))
$haschildren
=
true
;
if
(
!
strcmp
(
$navcategory
[
'parentid'
],
$categoryid
))
{
$haschildren
=
true
;
break
;
}
if
(
!
$haschildren
)
$keycategoryids
[
$categoryid
]
=
true
;
// show this category if it has no children
$keycategoryids
[
$categoryid
]
=
true
;
// show this category if it has no children
}
foreach
(
$keycategoryids
as
$keycategoryid
=>
$dummy
)
if
(
strcmp
(
$keycategoryid
,
$excludecategoryid
))
$field
[
'options'
][
$keycategoryid
]
=
qa_category_path_html
(
$navcategories
,
$keycategoryid
);
$field
[
'value'
]
=@
$field
[
'options'
][
$categoryid
];
$field
[
'note'
]
=
'<div id="'
.
$fieldname
.
'_note"><noscript style="color:red;">'
.
qa_lang_html
(
'question/category_js_note'
)
.
'</noscript></div>'
;
$field
[
'options'
][
$keycategoryid
]
=
qa_category_path_html
(
$navcategories
,
$keycategoryid
);
$field
[
'value'
]
=
@
$field
[
'options'
][
$categoryid
];
$field
[
'note'
]
=
'<div id="'
.
$fieldname
.
'_note">'
.
'<noscript style="color:red;">'
.
qa_lang_html
(
'question/category_js_note'
)
.
'</noscript>'
.
'</div>'
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment