* Fix plugin filename

* Make questions save!
This commit is contained in:
Zach Copley
2011-03-21 15:50:36 -07:00
parent 424670a5eb
commit 73c3344cc3
8 changed files with 92 additions and 523 deletions

View File

@@ -44,7 +44,7 @@ if (!defined('STATUSNET')) {
*/
class QnA_Answer extends Managed_DataObject
{
CONST ANSWER = 'http://activityschema.org/object/answer';
const OBJECT_TYPE = 'http://activityschema.org/object/answer';
public $__table = 'qna_answer'; // table name
public $id; // char(36) primary key not null -> UUID
@@ -162,6 +162,11 @@ class QnA_Answer extends Managed_DataObject
return Question::staticGet('id', $this->question_id);
}
static function fromNotice($notice)
{
return QnA_Answer::staticGet('uri', $notice->uri);
}
/**
* Save a new answer notice
*
@@ -171,32 +176,32 @@ class QnA_Answer extends Managed_DataObject
*
* @return Notice saved notice
*/
static function saveNew($profile, $question, $options=null)
static function saveNew($profile, $question, $options = null)
{
if (empty($options)) {
$options = array();
}
$a = new Answer();
$a->id = UUID::gen();
$a->profile_id = $profile->id;
$a->question_id = $question->id;
$a->created = common_sql_now();
$a->uri = common_local_url(
$answer = new Answer();
$answer->id = UUID::gen();
$answer->profile_id = $profile->id;
$answer->question_id = $question->id;
$answer->created = common_sql_now();
$answer->uri = common_local_url(
'showanswer',
array('id' => $pr->id)
array('id' => $answer->id)
);
common_log(LOG_DEBUG, "Saving answer: $pr->id $pr->uri");
$a->insert();
common_log(LOG_DEBUG, "Saving answer: $answer->id, $answer->uri");
$answer->insert();
// TRANS: Notice content answering a question.
// TRANS: %s is the answer
$content = sprintf(
_m('answered "%s"'),
$answer
$answer->uri
);
$link = '<a href="' . htmlspecialchars($question->uri) . '">' . htmlspecialchars($answer) . '</a>';
$link = '<a href="' . htmlspecialchars($answer->uri) . '">' . htmlspecialchars($answer) . '</a>';
// TRANS: Rendered version of the notice content answering a question.
// TRANS: %s a link to the question with question title as the link content.
$rendered = sprintf(_m('answered "%s"'), $link);
@@ -206,17 +211,17 @@ class QnA_Answer extends Managed_DataObject
$options = array_merge(
array(
'urls' => array(),
'rendered' => $rendered,
'tags' => $tags,
'replies' => $replies,
'reply_to' => $question->getNotice()->id,
'object_type' => QnA::ANSWER_OBJECT),
'urls' => array(),
'rendered' => $rendered,
'tags' => $tags,
'replies' => $replies,
'reply_to' => $question->getNotice()->id,
'object_type' => self::OBJECT_TYPE),
$options
);
if (!array_key_exists('uri', $options)) {
$options['uri'] = $pr->uri;
$options['uri'] = $answer->uri;
}
$saved = Notice::saveNew(

View File

@@ -45,9 +45,8 @@ if (!defined('STATUSNET')) {
class QnA_Question extends Managed_DataObject
{
const QUESTION = 'http://activityschema.org/object/question';
const OBJECT_TYPE = 'http://activityschema.org/object/question';
public $__table = 'qna_question'; // table name
public $id; // char(36) primary key not null -> UUID
public $uri;
@@ -99,22 +98,22 @@ class QnA_Question extends Managed_DataObject
'description' => 'Per-notice question data for QNA plugin',
'fields' => array(
'id' => array(
'type' => 'char',
'length' => 36,
'not null' => true,
'type' => 'char',
'length' => 36,
'not null' => true,
'description' => 'UUID'
),
'uri' => array(
'type' => 'varchar',
'length' => 255,
'type' => 'varchar',
'length' => 255,
'not null' => true
),
'profile_id' => array('type' => 'int'),
'title' => array('type' => 'text'),
'closed' => array('type' => 'int', size => 'tiny'),
'closed' => array('type' => 'int', 'size' => 'tiny'),
'description' => array('type' => 'text'),
'created' => array(
'type' => 'datetime',
'type' => 'datetime',
'not null' => true
),
),
@@ -174,6 +173,12 @@ class QnA_Question extends Managed_DataObject
return $a-count();
}
static function fromNotice($notice)
{
common_debug('xxxxxxxxxxxxxxx notice-uri = ' . $notice->uri);
return QnA_Question::staticGet('uri', $notice->uri);
}
/**
* Save a new question notice
*
@@ -185,7 +190,7 @@ class QnA_Question extends Managed_DataObject
*
* @return Notice saved notice
*/
static function saveNew($profile, $question, $title, $description, $options = array())
static function saveNew($profile, $title, $description, $options = array())
{
$q = new QnA_Question();
@@ -219,7 +224,7 @@ class QnA_Question extends Managed_DataObject
$title,
$q->uri
);
$link = '<a href="' . htmlspecialchars($q->uri) . '">' . htmlspecialchars($title) . '</a>';
// TRANS: Rendered version of the notice content creating a question.
// TRANS: %s a link to the question as link description.
@@ -234,13 +239,13 @@ class QnA_Question extends Managed_DataObject
'rendered' => $rendered,
'tags' => $tags,
'replies' => $replies,
'object_type' => QnAPlugin::QUESTION_OBJECT
'object_type' => self::OBJECT_TYPE
),
$options
);
if (!array_key_exists('uri', $options)) {
$options['uri'] = $p->uri;
$options['uri'] = $q->uri;
}
$saved = Notice::saveNew(

View File

@@ -47,11 +47,11 @@ class QnA_Vote extends Managed_DataObject
const UP = 'http://activitystrea.ms/schema/1.0/like';
const DOWN = 'http://activityschema.org/object/dislike'; // Gar!
public $__table = 'qa_vote'; // table name
public $__table = 'qna_vote'; // table name
public $id; // char(36) primary key not null -> UUID
public $question_id; // char(36) -> question.id UUID
public $answer_id; // char(36) -> question.id UUID
public $type // tinyint -> vote: up (1) or down (-1)
public $type; // tinyint -> vote: up (1) or down (-1)
public $profile_id; // int -> question.id
public $created; // datetime