|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @package K2 API plugin |
| 4 | + * @version 1.0 |
| 5 | + * @author Rafael Corral |
| 6 | + * @link http://www.rafaelcorral.com |
| 7 | + * @copyright Copyright (C) 2011 Rafael Corral. All rights reserved. |
| 8 | + * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php |
| 9 | + */ |
| 10 | + |
| 11 | +defined('_JEXEC') or die( 'Restricted access' ); |
| 12 | + |
| 13 | +jimport('joomla.plugin.plugin'); |
| 14 | +jimport('joomla.html.html'); |
| 15 | + |
| 16 | +require_once JPATH_ADMINISTRATOR.'/components/com_easysocial/includes/foundry.php'; |
| 17 | +require_once JPATH_ADMINISTRATOR.'/components/com_easysocial/models/groups.php'; |
| 18 | +require_once JPATH_ADMINISTRATOR.'/components/com_easysocial/models/covers.php'; |
| 19 | +require_once JPATH_ADMINISTRATOR.'/components/com_easysocial/models/albums.php'; |
| 20 | + |
| 21 | +require_once JPATH_SITE.'/plugins/api/easysocial/libraries/mappingHelper.php'; |
| 22 | + |
| 23 | +class EasysocialApiResourceComments extends ApiResource |
| 24 | +{ |
| 25 | + public function get() |
| 26 | + { |
| 27 | + $this->plugin->setResponse($this->getComments()); |
| 28 | + } |
| 29 | + |
| 30 | + public function post() |
| 31 | + { |
| 32 | + $app = JFactory::getApplication(); |
| 33 | + |
| 34 | + $element = $app->input->get('element', '', 'string'); |
| 35 | + $group = $app->input->get('group', '', 'string'); |
| 36 | + $verb = $app->input->get('verb', '', 'string'); |
| 37 | + $uid = $app->input->get('uid', 0, 'int');//element id |
| 38 | + |
| 39 | + $input = $app->input->get( 'comment', '' ,'STRING'); |
| 40 | + $params = $app->input->get( 'params',array(),'ARRAY');//params |
| 41 | + $streamid = $app->input->get( 'stream_id', '' , 'INT');//whole stream id |
| 42 | + $parent = $app->input->get( 'parent', 0 ,'INT');//parent comment id |
| 43 | + |
| 44 | + $result = new stdClass; |
| 45 | + $valid = 1; |
| 46 | + |
| 47 | + if(!$uid) |
| 48 | + { |
| 49 | + $result->id = 0; |
| 50 | + $result->status = 0; |
| 51 | + $result->message = 'Empty element id not allowed'; |
| 52 | + $valid = 0; |
| 53 | + } |
| 54 | + |
| 55 | + // Message should not be empty. |
| 56 | + if(!$streamid) |
| 57 | + { |
| 58 | + $result->id = 0; |
| 59 | + $result->status = 0; |
| 60 | + $result->message = 'Empty stream id not allowed'; |
| 61 | + $valid = 0; |
| 62 | + } |
| 63 | + else if($valid) |
| 64 | + { |
| 65 | + |
| 66 | + $compositeElement = $element . '.' . $group . '.' . $verb; |
| 67 | + |
| 68 | + $table = FD::table('comments'); |
| 69 | + |
| 70 | + $table->element = $compositeElement; |
| 71 | + $table->uid = $uid; |
| 72 | + $table->comment = $input; |
| 73 | + $table->created_by = FD::user()->id; |
| 74 | + $table->created = FD::date()->toSQL(); |
| 75 | + $table->parent = $parent; |
| 76 | + $table->params = $params; |
| 77 | + $table->stream_id = $streamid; |
| 78 | + |
| 79 | + $state = $table->store(); |
| 80 | + |
| 81 | + if($state) |
| 82 | + { |
| 83 | + //create result obj |
| 84 | + $result->status = 1; |
| 85 | + $result->message = 'comment saved successfully'; |
| 86 | + } |
| 87 | + else |
| 88 | + { |
| 89 | + //create result obj |
| 90 | + $result->status = 0; |
| 91 | + $result->message = 'Unable to save comment'; |
| 92 | + } |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + $this->plugin->setResponse($result); |
| 97 | + } |
| 98 | + |
| 99 | + public function getComments() |
| 100 | + { |
| 101 | + $app = JFactory::getApplication(); |
| 102 | + |
| 103 | + $row = new stdClass(); |
| 104 | + $row->uid = $app->input->get('uid',0,'INT'); |
| 105 | + $row->element = $app->input->get('element','','STRING');//discussions.group.reply |
| 106 | + $row->stream_id = $app->input->get('stream_id',0,'INT'); |
| 107 | + |
| 108 | + $row->limitstart = $app->input->get('limitstart',0,'INT'); |
| 109 | + $row->limit = $app->input->get('limit',10,'INT'); |
| 110 | + |
| 111 | + $data = array(); |
| 112 | + $mapp = new EasySocialApiMappingHelper(); |
| 113 | + $data['data'] = $mapp->createCommentsObj( $row ,$row->limitstart,$row->limit ); |
| 114 | + |
| 115 | + return $data; |
| 116 | + } |
| 117 | + |
| 118 | + public function delete() |
| 119 | + { |
| 120 | + $app = JFactory::getApplication(); |
| 121 | + |
| 122 | + $conversion_id = $app->input->get('conversation_id',0,'INT'); |
| 123 | + $valid = 1; |
| 124 | + $result = new stdClass; |
| 125 | + |
| 126 | + if( !$conversion_id ) |
| 127 | + { |
| 128 | + |
| 129 | + $result->status = 0; |
| 130 | + $result->message = 'Invalid Conversations'; |
| 131 | + $valid = 0; |
| 132 | + } |
| 133 | + |
| 134 | + if($valid) |
| 135 | + { |
| 136 | + // Try to delete the group |
| 137 | + $conv_model = FD::model('Conversations'); |
| 138 | + //$my = FD::user($this->plugin->get('user')->id); |
| 139 | + $result->status = $conv_model->delete( $conversion_id , $this->plugin->get('user')->id ); |
| 140 | + $result->message = 'Conversations deleted successfully'; |
| 141 | + } |
| 142 | + |
| 143 | + $this->plugin->setResponse($result); |
| 144 | + } |
| 145 | +} |
0 commit comments