Permalink
Browse files

Merge remote-tracking branch 'dstockto/cs_event_addcomment'

  • Loading branch information...
2 parents fdd6558 + 838d416 commit 9265230152a8b817b4011d3417db79b1df14efeb @lornajane lornajane committed Jan 19, 2013
Showing with 85 additions and 29 deletions.
  1. +85 −29 src/system/application/libraries/wsactions/event/Addcomment.php
@@ -1,66 +1,122 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
+/**
+ * Joindin webservice for adding a comment
+ *
+ * PHP version 5
+ *
+ * @category Joind.in
+ * @package Configuration
+ * @copyright 2009 - 2012 Joind.in
+ * @license http://github.com/joindin/joind.in/blob/master/doc/LICENSE JoindIn
+ */
+if (!defined('BASEPATH')) {
+ exit('No direct script access allowed');
+}
/**
- * Web Service Action: Add an event comment
+ * Joindin webservice for adding a comment
+ *
+ * PHP version 5
+ *
+ * @category Joind.in
+ * @package Configuration
+ * @copyright 2009 - 2012 Joind.in
+ * @license http://github.com/joindin/joind.in/blob/master/doc/LICENSE JoindIn
*/
-class Addcomment extends BaseWsRequest {
-
- var $CI = null;
- var $xml= null;
+class Addcomment extends BaseWsRequest
+{
+ public $CI = null;
+ public $xml = null;
- public function Addcomment($xml) {
- $this->CI=&get_instance(); //print_r($this->CI);
- $this->xml=$xml;
+ /**
+ * Instantiates web service for adding a comment
+ *
+ * @param string $xml XML provided to web service
+ *
+ * @return void
+ */
+ public function __construct($xml)
+ {
+ $this->CI = &get_instance(); //print_r($this->CI);
+ $this->xml = $xml;
}
- public function checkSecurity($xml) {
+
+ /**
+ * Publicly accessible service
+ *
+ * @param string $xml XML sent to webservice
+ *
+ * @return true
+ */
+ public function checkSecurity($xml)
+ {
// users can comment anonymously, don't require login
return true;
}
- //-----------------------
- public function run() {
+
+ /**
+ * Adds a comment
+ *
+ * @return array
+ */
+ public function run()
+ {
$this->CI->load->library('wsvalidate');
$unq = false;
- $rules=array(
- 'event_id' =>'required',
- 'comment' =>'required'
+ $rules = array(
+ 'event_id' =>'required',
+ 'comment' =>'required'
);
- $ret=$this->CI->wsvalidate->validate($rules, $this->xml->action);
+
+ $ret = $this->CI->wsvalidate->validate($rules, $this->xml->action);
if ($ret) {
return $this->throwError($ret);
}
- $unq=$this->CI->wsvalidate->validate_unique('event_comments', $this->xml->action);
+
+ $unq = $this->CI->wsvalidate->validate_unique(
+ 'event_comments',
+ $this->xml->action
+ );
+
if ($unq) {
- $in=(array)$this->xml->action;
- $user=$this->CI->user_model->getUserByUsername((string)$this->xml->auth->user);
+ $in = (array)$this->xml->action;
+ $user = $this->CI->user_model
+ ->getUserByUsername((string)$this->xml->auth->user);
if ($user && !$this->isValidLogin($this->xml)) {
return $this->throwError('Invalid permissions');
}
// Check to see if you can submit a comment to the event....
$this->CI->load->model('event_model');
- $event_detail=$this->CI->event_model->getEventDetail($in['event_id']);
+ $event_detail = $this->CI->event_model
+ ->getEventDetail($in['event_id']);
- $adv_mo=strtotime('+3 months', $event_detail[0]->event_start);
+ $adv_mo = strtotime('+3 months', $event_detail[0]->event_start);
if (time()>$adv_mo) {
return $this->throwError('Comments not allowed for this talk!');
}
- $arr=array(
- 'event_id' => $in['event_id'],
- 'comment' => $in['comment'],
- 'source' => isset($in['source']) ? $in['source'] : 'api',
- 'date_made' => time(),
- 'active' => 1
+ $arr = array(
+ 'event_id' => $in['event_id'],
+ 'comment' => $in['comment'],
+ 'source' => isset($in['source']) ? $in['source'] : 'api',
+ 'date_made' => time(),
+ 'active' => 1
);
+
if ($user) {
$arr['user_id'] = $user[0]->ID;
- $arr['cname'] = $user[0]->full_name;
+ $arr['cname'] = $user[0]->full_name;
}
+
$this->CI->db->insert('event_comments', $arr);
+
return $this->throwError('Comments added');
} else {
- if (!$unq) { $ret='Non-unique entry!'; }
+ if (!$unq) {
+ $ret = 'Non-unique entry!';
+ }
return $this->throwError($ret);
}
return $ret;

0 comments on commit 9265230

Please sign in to comment.