Skip to content

Commit

Permalink
Work on module
Browse files Browse the repository at this point in the history
  • Loading branch information
voltan committed Jul 31, 2017
1 parent be661a0 commit a09d06b
Show file tree
Hide file tree
Showing 31 changed files with 253 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Created by .ignore support plugin (hsz.mobi)
13 changes: 13 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
'title' => _a('Question'),
'name' => 'question'
),
array(
'title' => _a('Project'),
'name' => 'project'
),
array(
'title' => _a('Feed'),
'name' => 'feed'
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion config/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
32 changes: 32 additions & 0 deletions config/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions config/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
'controller' => 'question',
'permission' => 'question',
),
array(
'title' => _a('projects'),
'controller' => 'project',
'permission' => 'project',
),
array(
'title' => _a('Tools'),
'controller' => 'tools',
Expand Down
6 changes: 6 additions & 0 deletions config/permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
//'admin',
),
),
'project' => array(
'title' => _a('projects'),
'access' => array(
//'admin',
),
),
'tools' => array(
'title' => _a('Tools'),
'access' => array(
Expand Down
91 changes: 56 additions & 35 deletions sql/mysql.sql
Original file line number Diff line number Diff line change
@@ -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`)
);
3 changes: 0 additions & 3 deletions src/Api/.directory

This file was deleted.

8 changes: 4 additions & 4 deletions src/Api/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/Api/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ class Search extends AbstractSearch
*/
protected $searchIn = array(
'title',
'content',
'text_description',
'tags',
);

/**
* {@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',
);

/**
Expand Down
29 changes: 29 additions & 0 deletions src/Controller/Admin/ProjectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Pi Engine (http://pialog.org)
*
* @link http://code.pialog.org for the Pi Engine source repository
* @copyright Copyright (c) Pi Engine http://pialog.org
* @license http://pialog.org/license.txt New BSD License
*/

/**
* @author Hossein Azizabadi <[email protected]>
*/
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');
}
}
4 changes: 2 additions & 2 deletions src/Controller/Admin/QuestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Admin/ToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class ToolsController extends ActionController
{
public function indexAction()
{
$this->view()->setTemplate('tools_index');
$this->view()->setTemplate('tools-index');
}
}
2 changes: 1 addition & 1 deletion src/Controller/Feed/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Front/AnswerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Front/QuestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Form/AnswerFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions src/Form/AnswerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
),
Expand Down
4 changes: 2 additions & 2 deletions src/Form/AskFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function __construct()
),
),
));
// content
// text_description
$this->add(array(
'name' => 'content',
'name' => 'text_description',
'required' => true,
'filters' => array(
array(
Expand Down
4 changes: 2 additions & 2 deletions src/Form/AskForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading

0 comments on commit a09d06b

Please sign in to comment.