YaWK  24.1
Yet another WebKit
faq-backend.php
Go to the documentation of this file.
1 <?php
2 namespace YAWK\PLUGINS\FAQ {
3  /**
4  * @details <b>Build FAQ's for your users.</b>
5  * <p>FAQs are useful. Beware to underrate this. You can answer the most interesting questions
6  * before your user even ask. This saves time - your website should be informative. If you answer
7  * a question on your website, users may not need to ask your email or phone support. If you do
8  * it clever, this could be a big selling helper for you!</p>
9  * <p><i>This class covers backend functionality. See Methods Summary for Details!</i></p>
10  *
11  * @author Daniel Retzl <[email protected]>
12  * @version 1.0.0
13  * @brief Handles the FAQ backend methods.
14  */
15  class faq {
16  /** * @param int faq ID */
17  public $id;
18  /** * @param int order sortation number */
19  public $sort;
20  /** * @param int category ID */
21  public $cat;
22  /** * @param string question */
23  public $question;
24  /** * @param string answer */
25  public $answer;
26  /** * @param int 0|1 published or not */
27  public $published;
28 
29  /**
30  * @brief get all FAQ data and draw (output) as html table
31  * @param object $db database
32  */
33  function drawBackEndTableBody($db)
34  { /** @var $db \YAWK\db */
35  if ($res = $db->query("SELECT * FROM {plugin_faq} ORDER BY id"))
36  { // fetch data in loop
37  while ($row = mysqli_fetch_assoc($res))
38  { // set object properties
39  $this->id = $row['id'];
40  $this->sort = $row['sort'];
41  $this->published = $row['published'];
42  $this->cat = $row['cat'];
43  $this->question = $row['question'];
44  $this->answer = $row['answer'];
45 
46  // get published status
47  if ($row['published'] == 1)
48  { // published
49  $pub = "success";
50  $pubtext = "On";
51  }
52  else
53  { // not published
54  $pub = "danger";
55  $pubtext = "Off";
56  }
57 
58  echo "<tr>
59  <td><a href=\"index.php?plugin=faq&pluginpage=faq-toggleitem&published=" . $this->published . "&id=" . $this->id . "\">
60  <span class=\"label label-$pub\">$pubtext</span></a></td>
61  <td class=\"text-center\">$this->id</td>
62  <td class=\"text-center\">$this->sort</td>
63  <td><a href=\"index.php?plugin=faq&pluginpage=faq-edit&id=".$this->id."\"><b>$this->question</a></b><br><small>$this->answer</small></td>
64  <td class=\"text-center\">$this->cat</td>
65  <td class=\"text-center\">
66  <a class=\"fa fa-edit\" title=\"edit\" href=\"index.php?plugin=faq&pluginpage=faq-edit&id=" . $this->id . "\"></a>&nbsp;
67  <a class=\"fa fa-trash\" data-confirm=\"Soll der Eintrag &laquo;" . $this->id . " - " . $this->question . " &raquo; wirklich gel&ouml;scht werden?\"
68  title=\"DELETE ".$this->id."\" href=\"index.php?plugin=faq&pluginpage=faq-delete&delete=1&id=".$this->id."\">
69  </a>
70  </td>
71  </tr>";
72  }
73  }
74  }
75 
76  /**
77  * @brief create a new question
78  * @param object $db database
79  * @param string $question question
80  * @param string $answer answer
81  * @return bool|mixed
82  */
83  function create($db, $question, $answer)
84  { /** @var $db \YAWK\db */
85  if ($res = $db->query("INSERT INTO {plugin_faq}
86  (sort, question , answer)
87  VALUES('" . $this->sort . "',
88  '" . $question . "',
89  '" . $answer . "')"))
90  { // success
91  return true;
92  }
93  else
94  {
95  // q failed
96  return false;
97  }
98  }
99 
100  /**
101  * @brief delete an FAQ entry
102  * @param object $db database
103  * @param int $id faq ID to delete
104  * @return bool|mixed
105  */
106  function delete($db, $id)
107  { /** @var $db \YAWK\db */
108  // remove data from db
109  if ($res = $db->query("DELETE FROM {plugin_faq} WHERE id = '" . $id . "'"))
110  { // success
111  return $res;
112  }
113  else
114  { // q failed
115  return false;
116  }
117  }
118 
119  /**
120  * @brief save (update) an faq entry
121  * @param object $db database
122  * @return bool
123  */
124  function save($db)
125  { /** @var $db \YAWK\db */
126  if ($res = $db->query("UPDATE {plugin_faq} SET
127  sort = '" . $this->sort . "',
128  question = '" . $this->question . "',
129  answer = '" . $this->answer . "'
130  WHERE id = '" . $this->id . "'"))
131  { // success
132  return true;
133  }
134  else
135  { // q failed
136  return false;
137  }
138  }
139 
140  /**
141  * @brief load faq item properties into faq object
142  * @param object $db database
143  * @param int $id affected faq ID
144  * @return bool
145  */
146  function loadItemProperties($db, $id)
147  { /** @var $db \YAWK\db */
148  if ($res = $db->query("SELECT * FROM {plugin_faq}
149  WHERE id = '" . $id . "'"))
150  {
151  if ($row = mysqli_fetch_assoc($res))
152  { // set object vars
153  $this->id = $row['id'];
154  $this->sort = $row['sort'];
155  $this->question = $row['question'];
156  $this->answer = $row['answer'];
157  return true;
158  }
159  else
160  { // fetch failed
161  return false;
162  }
163  }
164  else
165  { // q failed
166  return false;
167  }
168  }
169  } // end class
170 } // end namespace
if(!isset($blog)) if(!isset($language)||(!isset($lang))) if(!isset($db)) $blog published
Definition: blog-toggle.php:17
Handles the FAQ backend methods.
Definition: faq-backend.php:15