From a09d06b953a26a20abbc6ce1df6b6825aee1b1d1 Mon Sep 17 00:00:00 2001 From: voltan Date: Mon, 31 Jul 2017 10:29:50 +0430 Subject: [PATCH] Work on module --- .gitignore | 1 + config/config.php | 13 +++ config/module.php | 2 +- config/navigation.php | 32 +++++++ config/page.php | 5 + config/permission.php | 6 ++ sql/mysql.sql | 91 ++++++++++++------- src/Api/.directory | 3 - src/Api/Question.php | 8 +- src/Api/Search.php | 14 +-- src/Controller/Admin/ProjectController.php | 29 ++++++ src/Controller/Admin/QuestionController.php | 4 +- src/Controller/Admin/ToolsController.php | 2 +- src/Controller/Feed/IndexController.php | 2 +- src/Controller/Front/AnswerController.php | 2 +- src/Controller/Front/QuestionController.php | 2 +- src/Form/AnswerFilter.php | 8 +- src/Form/AnswerForm.php | 7 +- src/Form/AskFilter.php | 4 +- src/Form/AskForm.php | 4 +- src/Form/UpdateFilter.php | 4 +- src/Form/UpdateForm.php | 4 +- src/Model/Project.php | 35 +++++++ src/Model/Question.php | 23 ++++- template/admin/project-index.phtml | 7 ++ template/admin/project-update.phtml | 7 ++ ...stion_index.phtml => question-index.phtml} | 0 ...ion_update.phtml => question-update.phtml} | 2 +- .../{tools_index.phtml => tools-index.phtml} | 0 template/front/answer_index.phtml | 4 +- template/front/question_index.phtml | 6 +- 31 files changed, 253 insertions(+), 78 deletions(-) create mode 100644 .gitignore delete mode 100644 src/Api/.directory create mode 100644 src/Controller/Admin/ProjectController.php create mode 100644 src/Model/Project.php create mode 100644 template/admin/project-index.phtml create mode 100644 template/admin/project-update.phtml rename template/admin/{question_index.phtml => question-index.phtml} (100%) rename template/admin/{question_update.phtml => question-update.phtml} (80%) rename template/admin/{tools_index.phtml => tools-index.phtml} (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bfa6a22 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +# Created by .ignore support plugin (hsz.mobi) diff --git a/config/config.php b/config/config.php index 345a806..deb8b2a 100644 --- a/config/config.php +++ b/config/config.php @@ -24,6 +24,10 @@ 'title' => _a('Question'), 'name' => 'question' ), + array( + 'title' => _a('Project'), + 'name' => 'project' + ), array( 'title' => _a('Feed'), 'name' => 'feed' @@ -76,6 +80,15 @@ 'filter' => 'number_int', 'value' => 1 ), + // Project + 'project_active' => array( + 'category' => 'project', + 'title' => _a('Active project system'), + 'description' => '', + 'edit' => 'checkbox', + 'filter' => 'number_int', + 'value' => 1 + ), // Question 'question_ask' => array( 'category' => 'question', diff --git a/config/module.php b/config/module.php index 1f0583f..b2f7b8b 100644 --- a/config/module.php +++ b/config/module.php @@ -14,7 +14,7 @@ 'meta' => array( 'title' => _a('Ask'), 'description' => _a('Ask and Answer'), - 'version' => '0.1.3', + 'version' => '0.2.0', 'license' => 'New BSD', 'logo' => 'image/logo.png', 'readme' => 'docs/readme.txt', diff --git a/config/navigation.php b/config/navigation.php index 1141b52..ae21f30 100644 --- a/config/navigation.php +++ b/config/navigation.php @@ -22,6 +22,38 @@ 'controller' => 'question', 'action' => 'index', ), + 'project' => array( + 'label' => _a('projects'), + 'permission' => array( + 'resource' => 'project', + ), + 'route' => 'admin', + 'module' => 'ask', + 'controller' => 'project', + 'action' => 'index', + 'pages' => array( + 'project' => array( + 'label' => _a('projects'), + 'permission' => array( + 'resource' => 'project', + ), + 'route' => 'admin', + 'module' => 'ask', + 'controller' => 'project', + 'action' => 'index', + ), + 'update' => array( + 'label' => _a('New project'), + 'permission' => array( + 'resource' => 'project', + ), + 'route' => 'admin', + 'module' => 'ask', + 'controller' => 'project', + 'action' => 'update', + ), + ), + ), 'tools' => array( 'label' => _a('Tools'), 'permission' => array( diff --git a/config/page.php b/config/page.php index d4aee75..2365789 100644 --- a/config/page.php +++ b/config/page.php @@ -18,6 +18,11 @@ 'controller' => 'question', 'permission' => 'question', ), + array( + 'title' => _a('projects'), + 'controller' => 'project', + 'permission' => 'project', + ), array( 'title' => _a('Tools'), 'controller' => 'tools', diff --git a/config/permission.php b/config/permission.php index 36667d2..5da70eb 100755 --- a/config/permission.php +++ b/config/permission.php @@ -41,6 +41,12 @@ //'admin', ), ), + 'project' => array( + 'title' => _a('projects'), + 'access' => array( + //'admin', + ), + ), 'tools' => array( 'title' => _a('Tools'), 'access' => array( diff --git a/sql/mysql.sql b/sql/mysql.sql index d38f08e..2173ab8 100644 --- a/sql/mysql.sql +++ b/sql/mysql.sql @@ -1,37 +1,58 @@ CREATE TABLE `{question}` ( - `id` int(10) unsigned NOT NULL auto_increment, - `type` enum('Q','A') NOT NULL default 'Q', - `pid` int(10) unsigned NOT NULL default '0', - `answer` smallint(5) unsigned NOT NULL default '0', - `uid` int(10) unsigned NOT NULL default '0', - `point` int(10) NOT NULL default '0', - `count` int(10) unsigned NOT NULL default '0', - `favorite` int(10) unsigned NOT NULL default '0', - `hits` int(10) unsigned NOT NULL default '0', - `status` tinyint(1) unsigned NOT NULL default '0', - `time_create` int(10) unsigned NOT NULL default '0', - `time_update` int(10) unsigned NOT NULL default '0', - `title` varchar(255) NOT NULL default '', - `slug` varchar(255) NOT NULL default '', - `content` text, - `tag` varchar(255) NOT NULL default '', - `seo_title` varchar(255) NOT NULL default '', - `seo_keywords` varchar(255) NOT NULL default '', - `seo_description` varchar(255) NOT NULL default '', - PRIMARY KEY (`id`), - UNIQUE KEY `slug` (`slug`), - KEY `title` (`title`), - KEY `status` (`status`), - KEY `time_create` (`time_create`), - KEY `hits` (`hits`), - KEY `point` (`point`), - KEY `uid` (`uid`), - KEY `question_list` (`status`, `type`), - KEY `answer_list` (`status`, `pid`, `type`), - KEY `submit_list` (`status`, `type`, `title`), - KEY `author_list` (`status`, `type`, `uid`), - KEY `order_id` (`time_create`, `id`), - KEY `order_point` (`point`, `id`), - KEY `order_hits` (`hits`, `id`), - KEY `order_answer` (`answer`, `id`) + `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `type` ENUM ('Q', 'A') NOT NULL DEFAULT 'Q', + `question_id` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `project_id` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `answer` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0', + `uid` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `point` INT(10) NOT NULL DEFAULT '0', + `count` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `favorite` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `hits` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `status` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', + `time_create` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `time_update` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `title` VARCHAR(255) NOT NULL DEFAULT '', + `slug` VARCHAR(255) NOT NULL DEFAULT '', + `text_description` TEXT, + `tag` VARCHAR(255) NOT NULL DEFAULT '', + `seo_title` VARCHAR(255) NOT NULL DEFAULT '', + `seo_keywords` VARCHAR(255) NOT NULL DEFAULT '', + `seo_description` VARCHAR(255) NOT NULL DEFAULT '', + `main_image` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `additional_images` TEXT, + PRIMARY KEY (`id`), + UNIQUE KEY `slug` (`slug`), + KEY `question_id` (`question_id`), + KEY `title` (`title`), + KEY `status` (`status`), + KEY `time_create` (`time_create`), + KEY `hits` (`hits`), + KEY `point` (`point`), + KEY `uid` (`uid`), + KEY `question_list` (`status`, `type`), + KEY `answer_list` (`status`, `question_id`, `type`), + KEY `submit_list` (`status`, `type`, `title`), + KEY `author_list` (`status`, `type`, `uid`), + KEY `order_id` (`time_create`, `id`), + KEY `order_point` (`point`, `id`), + KEY `order_hits` (`hits`, `id`), + KEY `order_answer` (`answer`, `id`) +); + +CREATE TABLE `{project}` ( + `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `title` VARCHAR(255) NOT NULL DEFAULT '', + `slug` VARCHAR(255) NOT NULL DEFAULT '', + `text_description` TEXT, + `time_create` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `time_update` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `status` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', + `seo_title` VARCHAR(255) NOT NULL DEFAULT '', + `seo_keywords` VARCHAR(255) NOT NULL DEFAULT '', + `seo_description` VARCHAR(255) NOT NULL DEFAULT '', + PRIMARY KEY (`id`), + KEY `title` (`title`), + KEY `status` (`status`), + KEY `time_create` (`time_create`) ); \ No newline at end of file diff --git a/src/Api/.directory b/src/Api/.directory deleted file mode 100644 index 02afdb4..0000000 --- a/src/Api/.directory +++ /dev/null @@ -1,3 +0,0 @@ -[Dolphin] -Timestamp=2012,11,9,12,51,46 -Version=3 diff --git a/src/Api/Question.php b/src/Api/Question.php index af0fce7..f696371 100644 --- a/src/Api/Question.php +++ b/src/Api/Question.php @@ -77,8 +77,8 @@ public function canonizeQuestion($question) // Set info for Q and A switch ($question['type']) { case 'Q': - // Set content - $question['content'] = Pi::service('markup')->render($question['content'], 'html', 'html'); + // Set text_description + $question['text_description'] = Pi::service('markup')->render($question['text_description'], 'html', 'html'); // Set question url $question['questionUrl'] = Pi::url(Pi::service('url')->assemble('ask', array( 'module' => $this->getModule(), @@ -88,8 +88,8 @@ public function canonizeQuestion($question) break; case 'A': - // Set content - $question['content'] = Pi::service('markup')->render($question['content'], 'html', 'text'); + // Set text_description + $question['text_description'] = Pi::service('markup')->render($question['text_description'], 'html', 'text'); // Set question url $question['questionUrl'] = '#'; break; diff --git a/src/Api/Search.php b/src/Api/Search.php index f728482..803a1a1 100644 --- a/src/Api/Search.php +++ b/src/Api/Search.php @@ -27,7 +27,7 @@ class Search extends AbstractSearch */ protected $searchIn = array( 'title', - 'content', + 'text_description', 'tags', ); @@ -35,12 +35,12 @@ class Search extends AbstractSearch * {@inheritDoc} */ protected $meta = array( - 'id' => 'id', - 'title' => 'title', - 'content' => 'content', - 'time_create' => 'time', - 'uid' => 'uid', - 'slug' => 'slug', + 'id' => 'id', + 'title' => 'title', + 'text_description' => 'content', + 'time_create' => 'time', + 'uid' => 'uid', + 'slug' => 'slug', ); /** diff --git a/src/Controller/Admin/ProjectController.php b/src/Controller/Admin/ProjectController.php new file mode 100644 index 0000000..22eb1ad --- /dev/null +++ b/src/Controller/Admin/ProjectController.php @@ -0,0 +1,29 @@ + + */ +namespace Module\Ask\Controller\Admin; + +use Pi; +use Pi\Mvc\Controller\ActionController; + +class ProjectController extends ActionController +{ + public function indexAction() + { + $this->view()->setTemplate('project-index'); + } + + public function updateAction() + { + $this->view()->setTemplate('project-update'); + } +} \ No newline at end of file diff --git a/src/Controller/Admin/QuestionController.php b/src/Controller/Admin/QuestionController.php index 9b114e4..e7fa0c2 100644 --- a/src/Controller/Admin/QuestionController.php +++ b/src/Controller/Admin/QuestionController.php @@ -64,7 +64,7 @@ public function indexAction() )), )); // Set view - $this->view()->setTemplate('question_index'); + $this->view()->setTemplate('question-index'); $this->view()->assign('questions', $question); $this->view()->assign('paginator', $paginator); } @@ -168,7 +168,7 @@ public function updateAction() $form->setData($question); } // Set view - $this->view()->setTemplate('question_update'); + $this->view()->setTemplate('question-update'); $this->view()->assign('form', $form); $this->view()->assign('question', $question); } diff --git a/src/Controller/Admin/ToolsController.php b/src/Controller/Admin/ToolsController.php index 668b222..727d262 100644 --- a/src/Controller/Admin/ToolsController.php +++ b/src/Controller/Admin/ToolsController.php @@ -19,6 +19,6 @@ class ToolsController extends ActionController { public function indexAction() { - $this->view()->setTemplate('tools_index'); + $this->view()->setTemplate('tools-index'); } } \ No newline at end of file diff --git a/src/Controller/Feed/IndexController.php b/src/Controller/Feed/IndexController.php index 1b16aae..16007b7 100644 --- a/src/Controller/Feed/IndexController.php +++ b/src/Controller/Feed/IndexController.php @@ -34,7 +34,7 @@ public function indexAction() foreach ($rowset as $row) { $entry = array(); $entry['title'] = $row->title; - $entry['description'] = strtolower(trim($row->content)); + $entry['description'] = strtolower(trim($row->text_description)); $entry['date_modified'] = (int)$row->time_create; $entry['link'] = Pi::url(Pi::service('url')->assemble('news', array( 'module' => $this->getModule(), diff --git a/src/Controller/Front/AnswerController.php b/src/Controller/Front/AnswerController.php index c4b1e9d..2aefd26 100644 --- a/src/Controller/Front/AnswerController.php +++ b/src/Controller/Front/AnswerController.php @@ -90,7 +90,7 @@ public function indexAction() $this->jump($url, $message); } } else { - $values['pid'] = $question['id']; + $values['question_id'] = $question['id']; $form->setData($values); } // Set header and title diff --git a/src/Controller/Front/QuestionController.php b/src/Controller/Front/QuestionController.php index 60f9b82..c792592 100644 --- a/src/Controller/Front/QuestionController.php +++ b/src/Controller/Front/QuestionController.php @@ -51,7 +51,7 @@ public function indexAction() // Get answers if ($question['answer'] > 0) { $answers = array(); - $where = array('status' => 1, 'pid' => $question['id'], 'type' => 'A'); + $where = array('status' => 1, 'question_id' => $question['id'], 'type' => 'A'); $order = array('point DESC', 'id DESC'); $select = $this->getModel('question')->select()->where($where)->order($order); $rowset = $this->getModel('question')->selectWith($select); diff --git a/src/Form/AnswerFilter.php b/src/Form/AnswerFilter.php index f882dca..96ed17b 100644 --- a/src/Form/AnswerFilter.php +++ b/src/Form/AnswerFilter.php @@ -25,14 +25,14 @@ public function __construct() 'name' => 'id', 'required' => false, )); - // pid + // question_id $this->add(array( - 'name' => 'pid', + 'name' => 'question_id', 'required' => true, )); - // content + // text_description $this->add(array( - 'name' => 'content', + 'name' => 'text_description', 'required' => true, 'filters' => array( array( diff --git a/src/Form/AnswerForm.php b/src/Form/AnswerForm.php index 7a83806..dc30418 100644 --- a/src/Form/AnswerForm.php +++ b/src/Form/AnswerForm.php @@ -35,15 +35,16 @@ public function init() 'type' => 'hidden', ), )); - // pid + // question_id $this->add(array( - 'name' => 'pid', + 'name' => 'question_id', 'attributes' => array( 'type' => 'hidden', ), )); + // text_description $this->add(array( - 'name' => 'content', + 'name' => 'text_description', 'options' => array( 'label' => __('Answer'), ), diff --git a/src/Form/AskFilter.php b/src/Form/AskFilter.php index a6a17db..96c6f40 100644 --- a/src/Form/AskFilter.php +++ b/src/Form/AskFilter.php @@ -35,9 +35,9 @@ public function __construct() ), ), )); - // content + // text_description $this->add(array( - 'name' => 'content', + 'name' => 'text_description', 'required' => true, 'filters' => array( array( diff --git a/src/Form/AskForm.php b/src/Form/AskForm.php index f109649..2fec238 100644 --- a/src/Form/AskForm.php +++ b/src/Form/AskForm.php @@ -46,9 +46,9 @@ public function init() 'description' => '', ) )); - // content + // text_description $this->add(array( - 'name' => 'content', + 'name' => 'text_description', 'options' => array( 'label' => __('Question'), 'editor' => 'html', diff --git a/src/Form/UpdateFilter.php b/src/Form/UpdateFilter.php index 0c97607..8c9e6ba 100644 --- a/src/Form/UpdateFilter.php +++ b/src/Form/UpdateFilter.php @@ -35,9 +35,9 @@ public function __construct() ), ), )); - // content + // text_description $this->add(array( - 'name' => 'content', + 'name' => 'text_description', 'required' => true, 'filters' => array( array( diff --git a/src/Form/UpdateForm.php b/src/Form/UpdateForm.php index 6a4d378..a7430a5 100644 --- a/src/Form/UpdateForm.php +++ b/src/Form/UpdateForm.php @@ -46,9 +46,9 @@ public function init() 'description' => '', ) )); - // content + // text_description $this->add(array( - 'name' => 'content', + 'name' => 'text_description', 'options' => array( 'label' => __('Question'), 'editor' => 'html', diff --git a/src/Model/Project.php b/src/Model/Project.php new file mode 100644 index 0000000..f8ab12d --- /dev/null +++ b/src/Model/Project.php @@ -0,0 +1,35 @@ + + */ + +namespace Module\Ask\Model; + +use Pi\Application\Model\Model; + +class Project extends Model +{ + /** + * {@inheritDoc} + */ + protected $columns = array( + 'id', + 'title', + 'slug', + 'text_description', + 'time_create', + 'time_update', + 'status', + 'seo_title', + 'seo_keywords', + 'seo_description', + ); +} diff --git a/src/Model/Question.php b/src/Model/Question.php index 0f0bd6f..cdc7199 100644 --- a/src/Model/Question.php +++ b/src/Model/Question.php @@ -21,8 +21,25 @@ class Question extends Model * {@inheritDoc} */ protected $columns = array( - 'id', 'type', 'pid', 'answer', 'uid', 'point', 'count', 'favorite', 'hits', 'status', - 'time_create', 'time_update', 'title', 'slug', 'content', 'tag', 'seo_title', - 'seo_keywords','seo_description' + 'id', + 'type', + 'question_id', + 'answer', + 'uid', 'point', + 'count', + 'favorite', + 'hits', + 'status', + 'time_create', + 'time_update', + 'title', + 'slug', + 'text_description', + 'tag', + 'seo_title', + 'seo_keywords', + 'seo_description', + 'main_image', + 'additional_images', ); } diff --git a/template/admin/project-index.phtml b/template/admin/project-index.phtml new file mode 100644 index 0000000..c02761d --- /dev/null +++ b/template/admin/project-index.phtml @@ -0,0 +1,7 @@ +

: escape($question['title']); ?>

: escape($question['slug']); ?>

-

:

+

:

: escape($question['time_create_view']); ?>

templateComponent('form'); ?> diff --git a/template/admin/tools_index.phtml b/template/admin/tools-index.phtml similarity index 100% rename from template/admin/tools_index.phtml rename to template/admin/tools-index.phtml diff --git a/template/front/answer_index.phtml b/template/front/answer_index.phtml index ffb06bc..90e4eca 100644 --- a/template/front/answer_index.phtml +++ b/template/front/answer_index.phtml @@ -1,7 +1,9 @@

escape($title); ?>

-
+
+ +
templateComponent('form'); ?>
\ No newline at end of file diff --git a/template/front/question_index.phtml b/template/front/question_index.phtml index e5f2ab3..2dfd089 100644 --- a/template/front/question_index.phtml +++ b/template/front/question_index.phtml @@ -2,7 +2,9 @@ -
+
+ +
@@ -30,7 +32,7 @@

escape($answer['title']); ?>

- +
escape($answer['time_create_view']); ?>