Permalink
Browse files

Merge remote-tracking branch 'dstockto/cs_event_getlist'

  • Loading branch information...
2 parents bb705bc + e37e875 commit 888aa627528ba0c1e33c0645146d917b89cf98cb @lornajane lornajane committed Jan 9, 2013
Showing with 92 additions and 25 deletions.
  1. +92 −25 src/system/application/libraries/wsactions/event/Getlist.php
@@ -1,44 +1,98 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
+/**
+ * Joindin webservice for getting event lists
+ *
+ * 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 Getlist extends BaseWsRequest {
-
- private $CI = null;
- private $xml= null;
+if (!defined('BASEPATH')) {
+ exit('No direct script access allowed');
+}
+
+/**
+ * Joindin webservice for getting event lists
+ *
+ * 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 Getlist extends BaseWsRequest
+{
+ protected $CI = null;
+ protected $xml = null;
private $_valid_types = array(
- 'hot','upcoming','past','pending'
+ 'hot', 'upcoming', 'past', 'pending'
);
- public function Getlist($xml) {
- $this->CI=&get_instance();
- $this->xml=$xml;
+ /**
+ * Instantiates the webservice
+ *
+ * @param string $xml XML sent to service
+ */
+ public function Getlist($xml)
+ {
+ $this->CI = &get_instance();
+ $this->xml = $xml;
}
- public function checkSecurity($xml) {
+
+ /**
+ * Public method
+ *
+ * @param string $xml XML sent to service
+ *
+ * @return true
+ */
+ public function checkSecurity($xml)
+ {
// public method!
return true;
}
- //-----------------------
- public function run() {
+
+ /**
+ * Does the work to fetch the list of events
+ *
+ * @return array
+ */
+ public function run()
+ {
$this->CI->load->library('wsvalidate');
- $rules=array(
- 'event_type' =>'required',
+ $rules = array(
+ 'event_type' =>'required',
);
- $valid=$this->CI->wsvalidate->validate($rules, $this->xml->action);
+
+ $valid = $this->CI->wsvalidate->validate($rules, $this->xml->action);
if (!$valid) {
$this->CI->load->model('event_model');
$this->CI->load->model('user_attend_model');
- $type=strtolower($this->xml->action->event_type);
+ $type = strtolower($this->xml->action->event_type);
if (!in_array($type, $this->_valid_types)) {
- return array('output'=>'json','data'=>array('items'=>array('msg'=>'Invalid event type!')));
+ return array(
+ 'output'=>'json',
+ 'data'=>array(
+ 'items'=>array(
+ 'msg'=>'Invalid event type!')
+ )
+ );
}
// retrieve the events
$events = $this->CI->event_model->getEventsOfType($type);
- // identify user so we can do the attending (or not if they're not identified)
- $uid = false;
- $user=$this->CI->user_model->getUserByUsername((string)$this->xml->auth->user);
+ // identify user so we can do the attending (or not if they're not
+ // identified)
+ $uid = false;
+ $user = $this->CI->user_model
+ ->getUserByUsername((string)$this->xml->auth->user);
if ($user) {
$uid = $user[0]->ID;
}
@@ -48,9 +102,13 @@ public function run() {
unset($events[$k]->score);
if ($uid) {
- $evt->user_attending = $this->CI->user_attend_model->chkAttend($uid, $evt->ID);
+ $evt->user_attending = $this->CI->user_attend_model
+ ->chkAttend($uid, $evt->ID);
}
- if (($evt->private==1 || $evt->private == 'Y') && !$evt->user_attending) {
+ if (($evt->private==1
+ || $evt->private == 'Y')
+ && !$evt->user_attending
+ ) {
// not allowed to see the event!
unset($events[$k]);
}
@@ -59,10 +117,19 @@ public function run() {
// Re-index the array, as the unsetting may have upset the apple-cart
$events = array_values($events);
- return array('output'=>'json','data'=>array('items'=>$events));
+ return array(
+ 'output'=>'json',
+ 'data'=>array(
+ 'items'=>$events)
+ );
} else {
- return array('output'=>'json','data'=>array('items'=>array('msg'=>'Invalid event type!')));
+ return array(
+ 'output'=>'json',
+ 'data'=>array(
+ 'items'=>array(
+ 'msg'=>'Invalid event type!')
+ )
+ );
}
}
-
}

0 comments on commit 888aa62

Please sign in to comment.