Flagbit_Faq - Version 1.0.4

Version Notes

* Initial Release

Download this release

Release Info

Developer Magento Core Team
Extension Flagbit_Faq
Version 1.0.4
Comparing to
See all releases


Version 1.0.4

app/code/community/Flagbit/Faq/Block/Admin/Edit.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Block_Admin_Edit extends Mage_Adminhtml_Block_Widget_Form_Container {
18
+
19
+ /**
20
+ * Constructor for the FAQ edit form
21
+ *
22
+ */
23
+ public function __construct() {
24
+
25
+ $this->_objectId = 'faq_id';
26
+ $this->_controller = 'admin';
27
+ $this->_blockGroup = 'faq';
28
+
29
+ parent :: __construct();
30
+
31
+ $this->_updateButton('save', 'label', Mage :: helper('faq')->__('Save FAQ item'));
32
+ $this->_updateButton('delete', 'label', Mage :: helper('faq')->__('Delete FAQ item'));
33
+
34
+ $this->_addButton('saveandcontinue', array (
35
+ 'label' => Mage :: helper('faq')->__('Save and continue edit'),
36
+ 'onclick' => 'saveAndContinueEdit()',
37
+ 'class' => 'save' ), -100);
38
+
39
+ $this->_formScripts[] = "
40
+ function saveAndContinueEdit(){
41
+ editForm.submit($('edit_form').action+'back/edit/');
42
+ }
43
+ ";
44
+ }
45
+
46
+ /**
47
+ * Helper function to edit the header of the current form
48
+ *
49
+ * @return string Returns an "edit" or "new" text depending on the type of modifications.
50
+ */
51
+ public function getHeaderText() {
52
+
53
+ if (Mage :: registry('faq')->getFaqId()) {
54
+ return Mage :: helper('faq')->__("Edit FAQ item '%s'", $this->htmlEscape(Mage :: registry('faq')->getQuestion()));
55
+ }
56
+ else {
57
+ return Mage :: helper('faq')->__('New FAQ item');
58
+ }
59
+ }
60
+
61
+ public function getFormActionUrl() {
62
+ return $this->getUrl('*/faq/save');
63
+ }
64
+ }
app/code/community/Flagbit/Faq/Block/Admin/Edit/Form.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Block_Admin_Edit_Form extends Mage_Adminhtml_Block_Widget_Form {
18
+
19
+ /**
20
+ * Preperation of current form
21
+ *
22
+ * @return Flagbit_Faq_Block_Admin_Edit_Form Self
23
+ */
24
+ protected function _prepareForm() {
25
+
26
+ $form = new Varien_Data_Form(array (
27
+ 'id' => 'edit_form',
28
+ 'action' => $this->getData('action'),
29
+ 'method' => 'post',
30
+ 'enctype' => 'multipart/form-data' ));
31
+ $form->setUseContainer(true);
32
+ $this->setForm($form);
33
+ return parent :: _prepareForm();
34
+ }
35
+
36
+ }
app/code/community/Flagbit/Faq/Block/Admin/Edit/Tab/Main.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Block_Admin_Edit_Tab_Main extends Mage_Adminhtml_Block_Widget_Form {
18
+
19
+
20
+ /**
21
+ * Prepares the page layout
22
+ *
23
+ * Loads the WYSIWYG editor on demand if enabled.
24
+ *
25
+ * @return Flagbit_Faq_Block_Admin_Edit
26
+ */
27
+ protected function _prepareLayout() {
28
+ $return = parent::_prepareLayout();
29
+ if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
30
+ $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
31
+ }
32
+ return $return;
33
+ }
34
+
35
+ /**
36
+ * Preparation of current form
37
+ *
38
+ * @return Flagbit_Faq_Block_Admin_Edit_Tab_Main Self
39
+ */
40
+ protected function _prepareForm() {
41
+
42
+ $model = Mage :: registry('faq');
43
+
44
+ $form = new Varien_Data_Form();
45
+ $form->setHtmlIdPrefix('faq_');
46
+
47
+ $fieldset = $form->addFieldset('base_fieldset', array (
48
+ 'legend' => Mage :: helper('faq')->__('General information'),
49
+ 'class' => 'fieldset-wide' ));
50
+
51
+ if ($model->getFaqId()) {
52
+ $fieldset->addField('faq_id', 'hidden', array (
53
+ 'name' => 'faq_id' ));
54
+ }
55
+
56
+ $fieldset->addField('question', 'text', array (
57
+ 'name' => 'question',
58
+ 'label' => Mage :: helper('faq')->__('FAQ item question'),
59
+ 'title' => Mage :: helper('faq')->__('FAQ item question'),
60
+ 'required' => true ));
61
+
62
+ /**
63
+ * Check is single store mode
64
+ */
65
+ if (!Mage :: app()->isSingleStoreMode()) {
66
+ $fieldset->addField('store_id', 'multiselect',
67
+ array (
68
+ 'name' => 'stores[]',
69
+ 'label' => Mage :: helper('faq')->__('Store view'),
70
+ 'title' => Mage :: helper('faq')->__('Store view'),
71
+ 'required' => true,
72
+ 'values' => Mage :: getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true) ));
73
+ }
74
+ else {
75
+ $fieldset->addField('store_id', 'hidden', array (
76
+ 'name' => 'stores[]',
77
+ 'value' => Mage :: app()->getStore(true)->getId() ));
78
+ $model->setStoreId(Mage :: app()->getStore(true)->getId());
79
+ }
80
+
81
+ $fieldset->addField('is_active', 'select',
82
+ array (
83
+ 'label' => Mage :: helper('faq')->__('Status'),
84
+ 'title' => Mage :: helper('faq')->__('Page status'),
85
+ 'name' => 'is_active',
86
+ 'required' => true,
87
+ 'options' => array (
88
+ '1' => Mage :: helper('faq')->__('Enabled'),
89
+ '0' => Mage :: helper('faq')->__('Disabled') ) ));
90
+
91
+ $fieldset->addField('answer', 'editor',
92
+ array (
93
+ 'name' => 'answer',
94
+ 'label' => Mage :: helper('faq')->__('Content'),
95
+ 'title' => Mage :: helper('faq')->__('Content'),
96
+ 'style' => 'height:36em;',
97
+ 'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
98
+ 'required' => true ));
99
+
100
+ $fieldset->addField('answer_html', 'select',
101
+ array (
102
+ 'label' => Mage :: helper('faq')->__('HTML answer'),
103
+ 'title' => Mage :: helper('faq')->__('HTML answer'),
104
+ 'name' => 'answer_html',
105
+ 'required' => true,
106
+ 'options' => array (
107
+ '1' => Mage :: helper('faq')->__('Enabled'),
108
+ '0' => Mage :: helper('faq')->__('Disabled') ) ));
109
+
110
+ $form->setValues($model->getData());
111
+ $this->setForm($form);
112
+
113
+ return parent :: _prepareForm();
114
+ }
115
+ }
app/code/community/Flagbit/Faq/Block/Admin/Edit/Tabs.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Block_Admin_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {
18
+
19
+ /**
20
+ * Constructs current object
21
+ *
22
+ */
23
+ public function __construct() {
24
+
25
+ parent :: __construct();
26
+ $this->setId('qaq_tabs');
27
+ $this->setDestElementId('edit_form');
28
+ $this->setTitle(Mage :: helper('faq')->__('FAQ item information'));
29
+ }
30
+
31
+ /**
32
+ * Prepares the page layout
33
+ *
34
+ * Adds the tabs to the left tab menu.
35
+ *
36
+ * @return Flagbit_Faq_Block_Admin_Edit
37
+ */
38
+ protected function _prepareLayout()
39
+ {
40
+ $return = parent::_prepareLayout();
41
+
42
+ $this->addTab('main_section',
43
+ array (
44
+ 'label' => Mage :: helper('faq')->__('General information'),
45
+ 'title' => Mage :: helper('faq')->__('General information'),
46
+ 'content' => $this->getLayout()->createBlock('faq/admin_edit_tab_main')->toHtml(),
47
+ 'active' => true ));
48
+
49
+ return $return;
50
+ }
51
+ }
app/code/community/Flagbit/Faq/Block/Admin/List.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+
18
+ class Flagbit_Faq_Block_Admin_List extends Mage_Adminhtml_Block_Widget_Grid_Container {
19
+
20
+ /**
21
+ * Constructor for FAQ Admin Block
22
+ *
23
+ */
24
+ public function __construct() {
25
+
26
+ $this->_controller = 'admin_list';
27
+ $this->_blockGroup = 'faq';
28
+ $this->_headerText = Mage :: helper('faq')->__('FAQ');
29
+ $this->_addButtonLabel = Mage :: helper('sales')->__('Add new FAQ item');
30
+
31
+ parent :: __construct();
32
+
33
+ }
34
+
35
+
36
+ /**
37
+ * Standard grid function for new elements
38
+ *
39
+ * @return string URL to add element page
40
+ */
41
+ public function getCreateUrl() {
42
+
43
+ return $this->getUrl('adminhtml/faq/new');
44
+ }
45
+ }
app/code/community/Flagbit/Faq/Block/Admin/List/Grid.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Block_Admin_List_Grid extends Mage_Adminhtml_Block_Widget_Grid {
18
+
19
+
20
+ /**
21
+ * Constructor of Grid
22
+ *
23
+ */
24
+ public function __construct() {
25
+
26
+ parent :: __construct();
27
+ $this->setId('faq_grid');
28
+ $this->setUseAjax(false);
29
+ $this->setDefaultSort('creation_time');
30
+ $this->setDefaultDir('DESC');
31
+ $this->setSaveParametersInSession(true);
32
+ }
33
+
34
+
35
+ /**
36
+ * Preparation of the data that is displayed by the grid.
37
+ *
38
+ * @return Flagbit_Faq_Block_Admin_Grid Self
39
+ */
40
+ protected function _prepareCollection() {
41
+
42
+ //TODO: add full name logic
43
+ $collection = Mage :: getResourceModel('faq/faq_collection');
44
+ $this->setCollection($collection);
45
+ #Mage::Log($collection->getData());
46
+ return parent :: _prepareCollection();
47
+ }
48
+
49
+
50
+ /**
51
+ * Preparation of the requested columns of the grid
52
+ *
53
+ * @return Flagbit_Faq_Block_Admin_Grid Self
54
+ */
55
+ protected function _prepareColumns() {
56
+
57
+ $this->addColumn('faq_id', array (
58
+ 'header' => Mage :: helper('faq')->__('FAQ #'),
59
+ 'width' => '80px',
60
+ 'type' => 'text',
61
+ 'index' => 'faq_id' ));
62
+
63
+ if (!Mage :: app()->isSingleStoreMode()) {
64
+ $this->addColumn('store_id',
65
+ array (
66
+ 'header' => Mage :: helper('cms')->__('Store view'),
67
+ 'index' => 'store_id',
68
+ 'type' => 'store',
69
+ 'store_all' => true,
70
+ 'store_view' => true,
71
+ 'sortable' => false,
72
+ 'filter_condition_callback' => array (
73
+ $this,
74
+ '_filterStoreCondition' ) ));
75
+ }
76
+
77
+ $this->addColumn('question', array (
78
+ 'header' => Mage :: helper('faq')->__('Question'),
79
+ 'index' => 'question' ));
80
+
81
+ $this->addColumn('is_active',
82
+ array (
83
+ 'header' => Mage :: helper('faq')->__('Active'),
84
+ 'index' => 'is_active',
85
+ 'type' => 'options',
86
+ 'width' => '70px',
87
+ 'options' => array (
88
+ 0 => Mage :: helper('faq')->__('No'),
89
+ 1 => Mage :: helper('faq')->__('Yes') ) ));
90
+
91
+ $this->addColumn('action',
92
+ array (
93
+ 'header' => Mage :: helper('faq')->__('Action'),
94
+ 'width' => '50px',
95
+ 'type' => 'action',
96
+ 'getter' => 'getId',
97
+ 'actions' => array (
98
+ array (
99
+ 'caption' => Mage :: helper('faq')->__('Edit'),
100
+ 'url' => array (
101
+ 'base' => 'adminhtml/faq/edit' ),
102
+ 'field' => 'faq_id' ) ),
103
+ 'filter' => false,
104
+ 'sortable' => false,
105
+ 'index' => 'stores',
106
+ 'is_system' => true ));
107
+
108
+ return parent :: _prepareColumns();
109
+ }
110
+
111
+
112
+ /**
113
+ * Helper function to do after load modifications
114
+ *
115
+ */
116
+ protected function _afterLoadCollection() {
117
+
118
+ $this->getCollection()->walk('afterLoad');
119
+ parent :: _afterLoadCollection();
120
+ }
121
+
122
+
123
+ /**
124
+ * Helper function to add store filter condition
125
+ *
126
+ * @param Mage_Core_Model_Mysql4_Collection_Abstract $collection Data collection
127
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column Column information to be filtered
128
+ */
129
+ protected function _filterStoreCondition($collection, $column) {
130
+
131
+ if (!$value = $column->getFilter()->getValue()) {
132
+ return;
133
+ }
134
+
135
+ $this->getCollection()->addStoreFilter($value);
136
+ }
137
+
138
+
139
+ /**
140
+ * Helper function to reveive on row click url
141
+ *
142
+ * @param Flagbit_Faq_Model_Faq $row Current rows dataset
143
+ * @return string URL for current row's onclick event
144
+ */
145
+ public function getRowUrl($row) {
146
+
147
+ return $this->getUrl('adminhtml/faq/edit', array (
148
+ 'faq_id' => $row->getFaqId() ));
149
+ }
150
+
151
+
152
+ /**
153
+ * Helper function to receive grid functionality urls for current grid
154
+ *
155
+ * @return string Requested URL
156
+ */
157
+ public function getGridUrl() {
158
+
159
+ return $this->getUrl('adminhtml/faq/index', array (
160
+ '_current' => true ));
161
+ }
162
+
163
+ }
app/code/community/Flagbit/Faq/Block/Frontend/Detail.php ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Block_Frontend_Detail extends Mage_Core_Block_Template {
18
+
19
+ protected $_faq;
20
+ protected $_images;
21
+
22
+
23
+ protected function _prepareLayout()
24
+ {
25
+ $faq = $this->getFaq();
26
+
27
+ if ($faq !== false && $head = $this->getLayout()->getBlock('head')) {
28
+ $head->setTitle($this->htmlEscape($faq->getQuestion()) . ' - ' . $head->getTitle());
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Function to gather the current faq item
34
+ *
35
+ * @return Flagbit_Faq_Model_Faq The current faq item
36
+ */
37
+ public function getFaq() {
38
+ if (!$this->_faq) {
39
+ $id = intval($this->getRequest()->getParam('faq'));
40
+ try {
41
+ $this->_faq = Mage :: getModel('faq/faq')->load($id);
42
+
43
+ if ($this->_faq->getIsActive() != 1){
44
+ Mage::throwException('Faq Item is not active');
45
+ }
46
+ }
47
+ catch (Exception $e) {
48
+ $this->_faq = false;
49
+ }
50
+ }
51
+
52
+ return $this->_faq;
53
+ }
54
+
55
+
56
+ /**
57
+ * Extracting available images
58
+ *
59
+ * @param string $thumbSize dimensions of thumbnail image (either number of width pixels or {width]x{height}
60
+ * @param string $imageSize dimensions of detail image (either number of width pixels or {width]x{height}
61
+ * @return unknown
62
+ */
63
+ public function getImages($thumbSize = null, $imageSize = null) {
64
+ if (!$faq = $this->getFaq()) {
65
+ return false;
66
+ }
67
+
68
+ // read images from dataset
69
+ $images = $faq->getImage();
70
+ $result = array();
71
+
72
+ // if we have found images - process them
73
+ if (is_array($images) && !empty($images)) {
74
+
75
+ // get media model
76
+ $mediaConfig = Mage :: getSingleton('faq/faq_media_config');
77
+ $mediaModel = Mage :: getSingleton('media/image')->setConfig($mediaConfig);
78
+
79
+ // iterate through images
80
+ foreach ($images as $image) {
81
+
82
+ // only go on if the image can be found
83
+ if (file_exists(Mage::getBaseDir('media') . DS . 'faq' . DS . $image)) {
84
+
85
+ // gather needed information
86
+ $newImage = array(
87
+ 'original' => $image,
88
+ 'galleryUrl' => $this->getGalleryUrl($image)
89
+ );
90
+
91
+ if ($thumbSize) {
92
+ $newImage['src'] = $mediaModel->getSpecialLink($image, $thumbSize);
93
+ }
94
+
95
+ if ($imageSize) {
96
+ $newImage['href'] = $mediaModel->getSpecialLink($image, $imageSize);
97
+ $newImage['width'] = intval($imageSize);
98
+ }
99
+ else {
100
+ $newImage['href'] = Mage::getBaseUrl('media') . '/faq/' . $image;
101
+ $newImage['width'] = $mediaModel->setFileName($image)->getDimensions()->getWidth();
102
+ }
103
+
104
+ $result[] = $newImage;
105
+ }
106
+ }
107
+ }
108
+
109
+ return $result;
110
+ }
111
+
112
+
113
+ /**
114
+ * Get gallery link for given image
115
+ *
116
+ * @param string $image File name
117
+ * @return string URL to gallery
118
+ */
119
+ public function getGalleryUrl($image) {
120
+ $params = array('faq' => $this->getFaq()->getFaqId() . '_' . urlencode(str_replace(array(' ', 'ä', 'ö', 'ü', 'ß'), array('_', 'ae', 'oe', 'ue', 'ss'), (strtolower($this->getFaq()->getQuestion())))));
121
+ if ($image) {
122
+ $params['image'] = $image;
123
+ return $this->getUrl('*/*/gallery', $params);
124
+ }
125
+ return $this->getUrl('*/*/gallery', $params);
126
+ }
127
+
128
+
129
+ /**
130
+ * Get gallery images for current gallery view
131
+ *
132
+ * @param string $type needed Image information type ('previous', 'current' or 'next') - if not given the function returns all of them.
133
+ * @return array Requested image information
134
+ */
135
+ public function getGalleryImages($type = null) {
136
+
137
+ // only do processing once (since parameters don't change during gallery view)
138
+ if (!$this->_images) {
139
+
140
+ // get images and parameters
141
+ $currentParam = $this->getRequest()->getParam('image');
142
+ $images = $this->getImages();
143
+
144
+ // initialization
145
+ $result = array(
146
+ 'previous' => NULL,
147
+ 'current' => NULL,
148
+ 'next' => NULL
149
+ );
150
+
151
+ // if we have images -> process them
152
+ if (is_array($images) && !empty($images)) {
153
+ $previousImage = null;
154
+
155
+ foreach ($images as $image) {
156
+
157
+ // if we found the requested pic -> save it
158
+ // if the requested pic was not found the first pic of the collection is used
159
+ if ($image['original'] == $currentParam || !$result['current']) {
160
+ $result['current'] = $image;
161
+
162
+ // save the previous image to get back to it
163
+ $result['previous'] = $previousImage;
164
+
165
+ if ($image['original'] == $currentParam) {
166
+ $current = true;
167
+ }
168
+ }
169
+ // save next image for pagination
170
+ elseif ($result['current']) {
171
+ $result['next'] = $image;
172
+
173
+ // if we found the requested image -> break
174
+ if ($current) {
175
+ break;
176
+ }
177
+ }
178
+
179
+ // save current image as previous image for further processing
180
+ $previousImage = $image;
181
+ }
182
+ }
183
+
184
+ // save results in class variable
185
+ $this->_images = $result;
186
+ }
187
+
188
+ // if the requested type is given - return the image
189
+ if ($type) {
190
+ return (isset($this->_images[$type]) ? $this->_images[$type] : false);
191
+ }
192
+
193
+ // if no type given -> return all the three images
194
+ return $this->_images;
195
+ }
196
+
197
+
198
+ /**
199
+ * Gets the current image
200
+ *
201
+ * @return array Image information
202
+ */
203
+ public function getCurrentImage() {
204
+ return $this->getGalleryImages('current');
205
+ }
206
+
207
+
208
+ /**
209
+ * Gets the previous image
210
+ *
211
+ * @return array Image information
212
+ */
213
+ public function getPreviousImage() {
214
+ return $this->getGalleryImages('previous');
215
+ }
216
+
217
+
218
+ /**
219
+ * Gets the next image
220
+ *
221
+ * @return array Image information
222
+ */
223
+ public function getNextImage() {
224
+ return $this->getGalleryImages('next');
225
+ }
226
+
227
+ /**
228
+ * Returns the current image's width
229
+ *
230
+ * @return int Width of current image
231
+ */
232
+ public function getImageWidth() {
233
+ $current = $this->getCurrentImage();
234
+ return $current['width'];
235
+ }
236
+ }
app/code/community/Flagbit/Faq/Block/Frontend/list.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Block_Frontend_List extends Mage_Core_Block_Template {
18
+
19
+ protected $_faqCollection;
20
+
21
+ protected function _prepareLayout()
22
+ {
23
+ if ($head = $this->getLayout()->getBlock('head')) {
24
+ $head->setTitle($this->htmlEscape($this->__('Frequently Asked Questions')) . ' - ' . $head->getTitle());
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Returns collection of current FAQ entries
30
+ *
31
+ * @param int $pageSize
32
+ * @return Flagbit_Faq_Model_Mysql_Faq_Collection collection of current FAQ entries
33
+ */
34
+ public function getFaqCollection($pageSize = null) {
35
+ if (!$this->_faqCollection || (intval($pageSize) > 0
36
+ && $this->_faqCollection->getSize() != intval($pageSize))
37
+ ) {
38
+ $this->_faqCollection = Mage :: getModel('faq/faq')
39
+ ->getCollection()
40
+ ->addStoreFilter(Mage :: app()->getStore())
41
+ ->addIsActiveFilter();
42
+
43
+ if (isset($pageSize) && intval($pageSize) && intval($pageSize) > 0) {
44
+ $this->_faqCollection->setPageSize(intval($pageSize));
45
+ }
46
+ }
47
+
48
+ return $this->_faqCollection;
49
+ }
50
+
51
+
52
+ /**
53
+ * Simple helper function to determine, whether there are FAQ entries or not.
54
+ *
55
+ * @return boolean True, if FAQ are given.
56
+ */
57
+ public function hasFaq() {
58
+ return $this->getFaqCollection()->getSize() > 0;
59
+ }
60
+
61
+
62
+ public function getIntro($faqItem) {
63
+ $_intro = strip_tags($faqItem->getContent());
64
+ $_intro = mb_substr($_intro, 0, mb_strpos($_intro, "\n"));
65
+
66
+ $length = 100 - mb_strlen($faqItem->getQuestion());
67
+ if ($length < 0) {
68
+ return '';
69
+ }
70
+ if (mb_strlen($_intro) > $length) {
71
+ $_intro = mb_substr($_intro, 0, $length);
72
+ $_intro = mb_substr($_intro, 0, mb_strrpos($_intro, ' ')).'...';
73
+ }
74
+
75
+ return $_intro;
76
+ }
77
+
78
+
79
+ /**
80
+ * Returns
81
+ *
82
+ * @return array
83
+ */
84
+ public function getFaqJumplist()
85
+ {
86
+ if(is_null($this->_faqJumplist))
87
+ {
88
+ $this->_faqJumplist = Mage::helper('faq/jumplist');
89
+ $this->_faqJumplist->setFaqItems($this->getFaqCollection());
90
+ }
91
+ return $this->_faqJumplist;
92
+ }
93
+
94
+
95
+ /**
96
+ * Simple helper function to determine, whether we should display a jumplist or not.
97
+ *
98
+ * @return boolean True if the jumplist should be displayed
99
+ */
100
+ public function hasFaqJumplist() {
101
+ // TODO add configuration option to enable/disable jumplist
102
+ return count($this->getFaqJumplist()) > 0;
103
+ }
104
+
105
+
106
+
107
+ public function encodeQuestionForUrl($question) {
108
+ return urlencode(
109
+ trim(
110
+ str_replace(
111
+ array(' ', 'ä', 'ö', 'ü', 'ß', '.', '/', ';', ':', '=', '?', '__'),
112
+ array('_', 'ae', 'oe', 'ue', 'ss', '_', '', '', '', '', '', '_'),
113
+ strtolower($question)
114
+ ), ' _'
115
+ )
116
+ );
117
+ }
118
+ }
app/code/community/Flagbit/Faq/Helper/Data.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Helper_Data extends Mage_Core_Helper_Abstract
18
+ {
19
+
20
+ /**
21
+ * Returns config data
22
+ *
23
+ * @param string $field Requested field
24
+ * @return array config Configuration information
25
+ */
26
+ public function getConfigData($field)
27
+ {
28
+ $path = 'faq/config/'.$field;
29
+ $config = Mage::getStoreConfig($path, Mage::app()->getStore());
30
+ return $config;
31
+ }
32
+ }
app/code/community/Flagbit/Faq/Helper/Jumplist.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Helper_Jumplist extends Mage_Core_Helper_Abstract implements Countable, Iterator
18
+ {
19
+ protected $items = array();
20
+
21
+ /**
22
+ * The "garbage can" for items not fitting in the default range
23
+ *
24
+ * @var string
25
+ */
26
+ const KEY_OTHER = 'other';
27
+
28
+ public function __construct()
29
+ {
30
+ // TODO make init range configurable
31
+ // create items from A (65) to Z (90)
32
+ for($ord = 65; $ord <= 90; $ord++)
33
+ {
34
+ $chr = chr($ord);
35
+ $this->items[$chr] = new Flagbit_Faq_Helper_JumplistItem($chr);
36
+ }
37
+
38
+ // TODO make configurable if KEY_OTHER is appended or prepended
39
+ $this->items[self::KEY_OTHER] = new Flagbit_Faq_Helper_JumplistItem(self::KEY_OTHER);
40
+ }
41
+
42
+ public function setFaqItems(Flagbit_Faq_Model_Mysql4_Faq_Collection $items)
43
+ {
44
+ foreach($items as $item)
45
+ {
46
+ $key = strtoupper(substr($item->getQuestion(), 0, 1));
47
+ if(!array_key_exists($key, $this->items))
48
+ {
49
+ $key = self::KEY_OTHER;
50
+ }
51
+ $this->items[$key]->addFaqItem($item);
52
+ }
53
+ }
54
+
55
+ /**
56
+ * @see ArrayIterator::current()
57
+ */
58
+ public function current() {
59
+ return current($this->items);
60
+ }
61
+
62
+ /**
63
+ * @see ArrayIterator::key()
64
+ */
65
+ public function key() {
66
+ return key($this->items);
67
+ }
68
+
69
+ /**
70
+ * @see ArrayIterator::next()
71
+ */
72
+ public function next() {
73
+ return next($this->items);
74
+ }
75
+
76
+ /**
77
+ * @see ArrayIterator::rewind()
78
+ */
79
+ public function rewind() {
80
+ return reset($this->items);
81
+ }
82
+
83
+ /**
84
+ * @see ArrayIterator::valid()
85
+ */
86
+ public function valid() {
87
+ return array_key_exists($this->key(), $this->items);
88
+ }
89
+ /**
90
+ * @see Countable::count()
91
+ */
92
+ public function count() {
93
+ return count($this->items);
94
+ }
95
+
96
+
97
+ }
app/code/community/Flagbit/Faq/Helper/JumplistItem.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Helper_JumplistItem extends Mage_Core_Helper_Abstract implements Countable, Iterator
18
+ {
19
+ /**
20
+ * @var string
21
+ */
22
+ protected $label;
23
+
24
+ /**
25
+ * @var array
26
+ */
27
+ protected $faqItems = array();
28
+
29
+ /**
30
+ * The constructor
31
+ *
32
+ * @param string $label
33
+ * @param array $faqItems
34
+ */
35
+ public function __construct($label = null, $faqItems = null)
36
+ {
37
+ $this->setLabel($label);
38
+ if(!is_null($faqItems))
39
+ {
40
+ $this->setFaqItems($faqItems);
41
+ }
42
+ }
43
+
44
+ /**
45
+ * @return array
46
+ */
47
+ public function getFaqItems()
48
+ {
49
+ return $this->faqItems;
50
+ }
51
+
52
+ /**
53
+ * @param array $faqItems
54
+ */
55
+ public function setFaqItems(array $faqItems)
56
+ {
57
+ $this->faqItems = $faqItems;
58
+ }
59
+
60
+ public function addFaqItem($item)
61
+ {
62
+ $this->faqItems[] = $item;
63
+ }
64
+
65
+ /**
66
+ * @return string
67
+ */
68
+ public function getLabel()
69
+ {
70
+ return $this->label;
71
+ }
72
+
73
+ /**
74
+ * @param string $label
75
+ */
76
+ public function setLabel($label)
77
+ {
78
+ $this->label = (string) $label;
79
+ }
80
+
81
+ /**
82
+ * Count elements of the jumplist
83
+ *
84
+ * @return int
85
+ */
86
+ public function count()
87
+ {
88
+ return count($this->faqItems);
89
+ }
90
+
91
+ /**
92
+ * Returns the current element
93
+ *
94
+ * @return mixed
95
+ */
96
+ public function current()
97
+ {
98
+ return current($this->faqItems);
99
+ }
100
+
101
+ /**
102
+ * Returns the key of the current element
103
+ *
104
+ * @return scalar
105
+ */
106
+ public function key()
107
+ {
108
+ return key($this->faqItems);
109
+ }
110
+
111
+ /**
112
+ * Move forward to the next element
113
+ *
114
+ * @return void
115
+ */
116
+ public function next()
117
+ {
118
+ next($this->faqItems);
119
+ }
120
+
121
+ /**
122
+ * Rewind the Iterator to the first element
123
+ *
124
+ * @void
125
+ */
126
+ public function rewind()
127
+ {
128
+ reset($this->faqItems);
129
+ }
130
+
131
+ /**
132
+ * Checks if current position is valid
133
+ *
134
+ * @return boolean
135
+ */
136
+ public function valid()
137
+ {
138
+ return array_key_exists($this->key(), $this->faqItems);
139
+ }
140
+ }
app/code/community/Flagbit/Faq/Model/Faq.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Model_Faq extends Mage_Core_Model_Abstract {
18
+
19
+
20
+ /**
21
+ * Constructor
22
+ *
23
+ */
24
+ protected function _construct() {
25
+
26
+ $this->_init('faq/faq');
27
+ }
28
+
29
+ }
app/code/community/Flagbit/Faq/Model/Mysql4/Faq.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Model_Mysql4_Faq extends Mage_Core_Model_Mysql4_Abstract {
18
+
19
+
20
+ /**
21
+ * Constructor
22
+ *
23
+ */
24
+ protected function _construct() {
25
+
26
+ $this->_init('faq/faq', 'faq_id');
27
+ }
28
+
29
+
30
+ /**
31
+ * Retrieve select object for load object data
32
+ *
33
+ * @param string $field
34
+ * @param mixed $value
35
+ * @return Zend_Db_Select
36
+ */
37
+ protected function _getLoadSelect($field, $value, $object) {
38
+
39
+ $select = parent :: _getLoadSelect($field, $value, $object);
40
+
41
+ if ($object->getStoreId()) {
42
+ $select->join(
43
+ array('nns' => $this->getTable('faq/faq_store')),
44
+ $this->getMainTable() . '.item_id = `nns`.faq_id'
45
+ )->where('is_active=1 AND `nns`.store_id in (0, ?) ',
46
+ $object->getStoreId())->order('creation_time DESC')->limit(1);
47
+ }
48
+ return $select;
49
+ }
50
+
51
+
52
+ /**
53
+ * Some processing prior to saving to database - processes the given images
54
+ * and the store configuration
55
+ *
56
+ * @param Mage_Core_Model_Abstract $object Current faq item
57
+ */
58
+ protected function _beforeSave(Mage_Core_Model_Abstract $object) {
59
+
60
+ if (!$object->getId()) {
61
+ $object->setCreationTime(Mage :: getSingleton('core/date')->gmtDate());
62
+ }
63
+
64
+ $object->setPublicationTime(
65
+ Mage::app()->getLocale()->date($object->getPublicationTime(),
66
+ Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
67
+ null, false)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
68
+ );
69
+
70
+ $object->setUpdateTime(Mage :: getSingleton('core/date')->gmtDate());
71
+ }
72
+
73
+
74
+ /**
75
+ * Assign page to store views
76
+ *
77
+ * @param Mage_Core_Model_Abstract $object
78
+ */
79
+ protected function _afterSave(Mage_Core_Model_Abstract $object) {
80
+
81
+ $condition = $this->_getWriteAdapter()->quoteInto('faq_id = ?', $object->getId());
82
+ $this->_getWriteAdapter()->delete($this->getTable('faq/faq_store'), $condition);
83
+
84
+ foreach ((array) $object->getData('stores') as $store) {
85
+ $storeArray = array ();
86
+ $storeArray['faq_id'] = $object->getId();
87
+ $storeArray['store_id'] = $store;
88
+ $this->_getWriteAdapter()->insert(
89
+ $this->getTable('faq/faq_store'), $storeArray
90
+ );
91
+ }
92
+
93
+ return parent :: _afterSave($object);
94
+ }
95
+
96
+
97
+ /**
98
+ * Do some processing after loading (stores and images)
99
+ *
100
+ * @param Mage_Core_Model_Abstract $object Current faq item
101
+ */
102
+ protected function _afterLoad(Mage_Core_Model_Abstract $object) {
103
+
104
+ $select = $this->_getReadAdapter()->select()->from(
105
+ $this->getTable('faq/faq_store')
106
+ )->where('faq_id = ?', $object->getId());
107
+
108
+ if ($data = $this->_getReadAdapter()->fetchAll($select)) {
109
+ $storesArray = array ();
110
+ foreach ($data as $row) {
111
+ $storesArray[] = $row['store_id'];
112
+ }
113
+ $object->setData('store_id', $storesArray);
114
+ }
115
+
116
+ $images = trim($object->getData('image'));
117
+ if ($images && !empty($images)) {
118
+ $object->setData('image', explode(',', $images));
119
+ }
120
+ else {
121
+ $object->setData('image', null);
122
+ }
123
+
124
+ return parent :: _afterLoad($object);
125
+ }
126
+ }
app/code/community/Flagbit/Faq/Model/Mysql4/Faq/Collection.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * FAQ for Magento
4
+ *
5
+ * @category Flagbit
6
+ * @package Flagbit_Faq
7
+ * @copyright Copyright (c) 2009 Flagbit GmbH & Co. KG <magento@flagbit.de>
8
+ */
9
+
10
+ /**
11
+ * FAQ for Magento
12
+ *
13
+ * @category Flagbit
14
+ * @package Flagbit_Faq
15
+ * @author Flagbit GmbH & Co. KG <magento@flagbit.de>
16
+ */
17
+ class Flagbit_Faq_Model_Mysql4_Faq_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
18
+
19
+ protected $_previewFlag;
20
+
21
+
22
+ /**
23
+ * Constructor
24
+ *
25
+ */
26
+ protected function _construct() {
27
+
28
+ $this->_init('faq/faq')
29
+ ->setOrder('question', 'ASC');
30
+ }
31
+
32
+
33
+ /**
34
+ * Creates an options array for grid filter functionality
35
+ *
36
+ * @return array Options array
37
+ */
38
+ public function toOptionArray() {
39
+
40
+ return $this->_toOptionArray('faq_id', 'question');
41
+ }
42
+
43
+
44
+ public function addIsActiveFilter(){
45
+ $this->addFilter('is_active', 1);
46
+
47
+ return $this;
48
+ }
49
+
50
+
51
+ /**
52
+ * Add Filter by store
53
+ *
54
+ * @param int|Mage_Core_Model_Store $store Store to be filtered
55
+ * @return Flagbit_Faq_Model_Mysql4_Faq_Collection Self
56
+ */
57
+ public function addStoreFilter($store) {
58
+
59
+ if ($store instanceof Mage_Core_Model_Store) {
60
+ $store = array (
61
+ $store->getId() );
62
+ }
63
+
64
+ $this->getSelect()->join(
65
+ array('store_table' => $this->getTable('faq/faq_store')),
66
+ 'main_table.faq_id = store_table.faq_id',
67
+ array ()
68
+ )->where('store_table.store_id in (?)', array (
69
+ 0,
70
+ $store
71
+ ))->group('main_table.faq_id');
72
+
73
+ return $this;
74
+ }
75
+
76
+
77
+ /**
78
+ * After load processing - adds store information to the datasets
79
+ *
80
+ */
81
+ protected function _afterLoad() {
82
+
83
+ if ($this->_previewFlag) {
84
+ $items = $this->getColumnValues('faq_id');
85
+ if (count($items)) {
86
+ $select = $this->getConnection()->select()->from(
87
+ $this->getTable('faq/faq_store')
88
+ )->where(
89
+ $this->getTable('faq/faq_store') . '.faq_id IN (?)',
90
+ $items
91
+ );
92
+ if ($result = $this->getConnection()->fetchPairs($select)) {
93
+ foreach ($this as $item) {
94
+ if (!isset($result[$item->getData('faq_id')])) {
95
+ continue;
96
+ }
97
+ if ($result[$item->getData('faq_id')] == 0) {
98
+ $stores = Mage :: app()->getStores(false, true);
99
+ $storeId = current($stores)->getId();
100
+ $storeCode = key($stores);
101
+ }
102
+ else {
103
+ $storeId = $result[$item->getData('faq_id')];
104
+ $storeCode = Mage :: app()->getStore($storeId)->getCode();
105
+ }
106
+ $item->setData('_first_store_id', $storeId);
107
+ $item->setData('store_code', $storeCode);
108
+ }
109
+ }
110
+ }
111
+ }
112
+
113
+ parent :: _afterLoad();
114
+ }
115
+ }
app/code/community/Flagbit/Faq/controllers/AdminController.php ADDED
@@ -0,0 +1,212 @@