31 const NAME =
"advice_license";
33 function __construct()
35 parent::__construct(self::NAME, array(
36 self::TITLE =>
"Advice Licenses",
37 self::MENU_LIST =>
"Organize::Licenses",
38 self::REQUIRES_LOGIN =>
true 47 protected function handle(Request $request)
49 $rf = intval($request->get(
'rf'));
54 $canEdit = $userDao->isAdvisorOrAdmin($userId, $groupId);
55 if (empty($rf) || ! $canEdit) {
57 'aaData' => json_encode($this->getArrayArrayData($groupId, $canEdit)),
60 return $this->
render(
'advice_license.html.twig', $this->mergeWithDefault($vars));
63 $vars = $this->getDataRow($groupId, $rf);
64 if ($vars ===
false) {
65 return $this->flushContent( _(
'invalid license candidate'));
68 if ($request->get(
'save')) {
70 $vars = $this->
saveInput($request, $vars);
71 $vars[
'message'] =
'Successfully updated.';
72 }
catch (\Exception $e) {
73 $vars = array(
'rf_shortname' => $request->get(
'shortname'),
74 'rf_fullname' => $request->get(
'fullname'),
75 'rf_text' => $request->get(
'rf_text'),
76 'rf_url' => $request->get(
'url'),
77 'rf_notes' => $request->get(
'note'),
78 'rf_risk' => intval($request->get(
'risk'))
80 $vars[
'message'] = $e->getMessage();
84 return $this->
render(
'advice_license-edit.html.twig', $this->mergeWithDefault($vars));
88 private function getArrayArrayData($groupId,$canEdit)
90 $sql =
"SELECT rf_pk,rf_shortname,rf_fullname,rf_text,rf_url,rf_notes,marydone FROM license_candidate WHERE group_fk=$1";
92 $dbManager = $this->
getObject(
'db.manager');
93 $dbManager->prepare($stmt = __METHOD__, $sql);
94 $res = $dbManager->execute($stmt, array($groupId));
96 while ($row = $dbManager->fetchArray($res)) {
97 $aData = array(htmlentities($row[
'rf_shortname']),
98 htmlentities($row[
'rf_fullname']),
99 '<div style="overflow-y:scroll;max-height:150px;margin:0;">' . nl2br(htmlentities($row[
'rf_text'])) .
'</div>',
100 htmlentities($row[
'rf_url']),
101 $this->bool2checkbox($dbManager->booleanFromDb($row[
'marydone'])));
104 $edit =
'<a href="' . $link .
'"><img border="0" src="images/button_edit.png"></a>';
105 array_unshift($aData,$edit);
109 $dbManager->freeResult($res);
114 private function getDataRow($groupId, $licId)
117 return array(
'rf_pk' => -1,
'rf_shortname' =>
'');
119 $sql =
"SELECT rf_pk,rf_shortname,rf_fullname,rf_text,rf_url,rf_notes,marydone,rf_risk FROM license_candidate WHERE group_fk=$1 AND rf_pk=$2";
121 $dbManager = $this->
getObject(
'db.manager');
122 $row = $dbManager->getSingleRow($sql, array($groupId, $licId), __METHOD__);
123 if (
false !== $row) {
124 $row[
'marydone'] = $dbManager->booleanFromDb($row[
'marydone']);
130 private function bool2checkbox($bool)
132 $check = $bool ?
' checked="checked"' :
'';
133 return '<input type="checkbox"' . $check .
' disabled="disabled"/>';
144 $shortname = $request->get(
'shortname');
145 $fullname = $request->get(
'fullname');
146 $rfText = $request->get(
'rf_text');
147 $url = $request->get(
'url');
148 $marydone = $request->get(
'marydone');
149 $note = $request->get(
'note');
150 $riskLvl = intval($request->get(
'risk'));
152 if (empty($shortname) || empty($fullname) || empty($rfText)) {
153 throw new \Exception(
'missing shortname (or) fullname (or) reference text');
157 $licenseDao = $this->
getObject(
'dao.license');
158 $ok = ($oldRow[
'rf_shortname'] == $shortname);
163 throw new \Exception(
'shortname already in use');
165 if ($oldRow[
'rf_pk'] == -1) {
166 $oldRow[
'rf_pk'] = $licenseDao->insertUploadLicense($shortname, $rfText,
Auth::getGroupId());
169 $licenseDao->updateCandidate($oldRow[
'rf_pk'], $shortname, $fullname,
170 $rfText, $url, $note, !empty($marydone), $riskLvl);
171 return array(
'rf_pk' => $oldRow[
'rf_pk'],
172 'rf_shortname' => $shortname,
173 'rf_fullname' => $fullname,
174 'rf_text' => $rfText,
177 'rf_risk' => $riskLvl,
178 'marydone' => $marydone);
Traceback_uri()
Get the URI without query to this location.
static getUserId()
Get the current user's id.
Traceback_parm($ShowMod=1)
Get the URI query to this location.
render($templateName, $vars=null, $headers=null)
static getGroupId()
Get the current user's group id.
saveInput(Request $request, $oldRow)