PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_easyblog/tables/teamblog.php

https://github.com/joomleiros/tpl_joomleiros
PHP | 351 lines | 252 code | 61 blank | 38 comment | 35 complexity | 373f7d2029b263bbb646f0bee822a4fe MD5 | raw file
  1. <?php
  2. /**
  3. * @package EasyBlog
  4. * @copyright Copyright (C) 2010 Stack Ideas Private Limited. All rights reserved.
  5. * @license GNU/GPL, see LICENSE.php
  6. * EasyBlog is free software. This version may have been modified pursuant
  7. * to the GNU General Public License, and as distributed it includes or
  8. * is derivative of works licensed under the GNU General Public License or
  9. * other free or open source software licenses.
  10. * See COPYRIGHT.php for copyright notices and details.
  11. */
  12. defined('_JEXEC') or die('Restricted access');
  13. jimport('joomla.filesystem.file');
  14. jimport('joomla.filesystem.folder');
  15. require_once( JPATH_ROOT.DS.'components'.DS.'com_easyblog'.DS.'constants.php' );
  16. require_once( EBLOG_HELPERS . DS . 'router.php' );
  17. class TableTeamBlog extends JTable
  18. {
  19. var $id = null;
  20. var $title = null;
  21. var $description = null;
  22. var $published = null;
  23. var $created = null;
  24. var $alias = null;
  25. var $access = null;
  26. var $avatar = null;
  27. /**
  28. * Constructor for this class.
  29. *
  30. * @return
  31. * @param object $db
  32. */
  33. function __construct(& $db )
  34. {
  35. parent::__construct( '#__easyblog_team' , 'id' , $db );
  36. }
  37. function load( $key , $permalink = false )
  38. {
  39. if( !$permalink )
  40. {
  41. return parent::load( $key );
  42. }
  43. $db =& $this->getDBO();
  44. $query = 'SELECT id FROM ' . $this->_tbl . ' '
  45. . 'WHERE `alias`=' . $db->Quote( $key );
  46. $db->setQuery( $query );
  47. $id = $db->loadResult();
  48. // Try replacing ':' to '-' since Joomla replaces it
  49. if( !$id )
  50. {
  51. $query = 'SELECT id FROM ' . $this->_tbl . ' '
  52. . 'WHERE `alias`=' . $db->Quote( JString::str_ireplace( ':' , '-' , $key ) );
  53. $db->setQuery( $query );
  54. $id = $db->loadResult();
  55. }
  56. return parent::load( $id );
  57. }
  58. function delete()
  59. {
  60. if( parent::delete() )
  61. {
  62. $this->deleteMembers();
  63. return true;
  64. }
  65. }
  66. function deleteMembers($userId = '')
  67. {
  68. // Delete existing members first so we dont have to worry what's changed
  69. if( $this->id != 0 )
  70. {
  71. $db =& JFactory::getDBO();
  72. $query = 'DELETE FROM #__easyblog_team_users ';
  73. $query .= ' WHERE `team_id`=' . $db->Quote( $this->id );
  74. if(! empty($userId))
  75. $query .= ' AND `user_id`=' . $db->Quote( $userId );
  76. $db->setQuery( $query );
  77. $db->Query();
  78. }
  79. }
  80. function getMembers()
  81. {
  82. if( $this->id != 0 )
  83. {
  84. $db =& JFactory::getDBO();
  85. $query = 'SELECT user_id FROM #__easyblog_team_users '
  86. . 'WHERE `team_id`=' . $db->Quote( $this->id );
  87. $db->setQuery( $query );
  88. return $db->loadResultArray();
  89. }
  90. return false;
  91. }
  92. function isMember($userId)
  93. {
  94. if( $this->id != 0 )
  95. {
  96. $db =& JFactory::getDBO();
  97. $query = 'SELECT `user_id` FROM `#__easyblog_team_users`';
  98. $query .= ' WHERE `team_id`=' . $db->Quote( $this->id );
  99. $query .= ' AND `user_id` = ' . $db->Quote( $userId );
  100. $db->setQuery( $query );
  101. $result = $db->loadResult();
  102. return $result;
  103. }
  104. return false;
  105. }
  106. /**
  107. * Overrides parent's bind method to add our own logic.
  108. *
  109. * @param Array $data
  110. **/
  111. function bind( $data )
  112. {
  113. parent::bind( $data );
  114. if( empty( $this->created ) )
  115. {
  116. $date =& JFactory::getDate();
  117. $this->created = $date->toMySQL();
  118. }
  119. jimport( 'joomla.filesystem.filter.filteroutput');
  120. $i = 1;
  121. while( $this->aliasExists() || empty($this->alias) )
  122. {
  123. $this->alias = empty($this->alias) ? $this->title : $this->alias . '-' . $i;
  124. $i++;
  125. }
  126. $this->alias = EasyBlogRouter::generatePermalink( $this->alias );
  127. }
  128. function aliasExists()
  129. {
  130. $db =& $this->getDBO();
  131. $query = 'SELECT COUNT(1) FROM ' . $db->nameQuote( '#__easyblog_team' ) . ' '
  132. . 'WHERE ' . $db->nameQuote( 'alias' ) . '=' . $db->Quote( $this->alias );
  133. if( $this->id != 0 )
  134. {
  135. $query .= ' AND ' . $db->nameQuote( 'id' ) . '!=' . $db->Quote( $this->id );
  136. }
  137. $db->setQuery( $query );
  138. return $db->loadResult() > 0 ? true : false;
  139. }
  140. function getAvatar()
  141. {
  142. $avatar_link = '';
  143. if($this->avatar == 'tdefault.png' || $this->avatar == 'default_teamblog.png' || $this->avatar == 'components/com_easyblog/assets/images/default_teamblog.png' || $this->avatar == 'components/com_easyblog/assets/images/tdefault.png' || empty($this->avatar))
  144. {
  145. $avatar_link = 'components/com_easyblog/assets/images/default_teamblog.png';
  146. }
  147. else
  148. {
  149. $avatar_link = EasyImageHelper::getAvatarRelativePath('team') . '/' . $this->avatar;
  150. }
  151. return rtrim(JURI::root(), '/') . '/' . $avatar_link;
  152. }
  153. function getTeamAdminEmails()
  154. {
  155. $db =& $this->getDBO();
  156. $query = 'select `email` from `#__users` as a inner join `#__easyblog_team_users` as b on a.`id` = b.`user_id`';
  157. $query .= ' where b.`team_id` = ' . $db->Quote($this->id);
  158. $query .= ' and b.isadmin = ' . $db->Quote('1');
  159. $db->setQuery($query);
  160. $result = $db->loadResultArray();
  161. if(count($result) == 0)
  162. {
  163. $notify =& EasyBlogHelper::getNotification();
  164. $adminEmails = $notify->getAdminEmails();
  165. foreach($adminEmails as $row)
  166. {
  167. $result[] = $row->email;
  168. }
  169. }
  170. return $result;
  171. }
  172. function allowSubscription($access, $userid, $ismember, $aclallowsubscription=false)
  173. {
  174. $allowSubscription = false;
  175. $config =& EasyBlogHelper::getConfig();
  176. if($config->get('main_teamsubscription', false))
  177. {
  178. switch($access)
  179. {
  180. case EBLOG_TEAMBLOG_ACCESS_MEMBER:
  181. if($ismember && $aclallowsubscription)
  182. $allowSubscription = true;
  183. else
  184. $allowSubscription = false;
  185. break;
  186. case EBLOG_TEAMBLOG_ACCESS_REGISTERED:
  187. if($userid != 0 && $aclallowsubscription)
  188. $allowSubscription = true;
  189. else
  190. $allowSubscription = false;
  191. break;
  192. case EBLOG_TEAMBLOG_ACCESS_EVERYONE:
  193. if($aclallowsubscription || (empty($userid) && $config->get('main_allowguestsubscribe')))
  194. $allowSubscription = true;
  195. else
  196. $allowSubscription = false;
  197. break;
  198. default:
  199. $allowSubscription = false;
  200. }
  201. }
  202. return $allowSubscription;
  203. }
  204. /**
  205. * Retrieve a list of tags created by this team
  206. **/
  207. public function getTags()
  208. {
  209. $db = JFactory::getDBO();
  210. $query = 'SELECT a.* FROM ' . $db->nameQuote( '#__easyblog_tag' ) . ' AS a '
  211. . 'INNER JOIN ' . $db->nameQuote( '#__easyblog_post_tag' ) . ' AS b '
  212. . 'ON b.' . $db->nameQuote( 'tag_id' ) . '=a.' . $db->nameQuote( 'id' ) . ' '
  213. . 'INNER JOIN ' . $db->nameQuote( '#__easyblog_team_post' ) . ' AS c '
  214. . 'ON c.' . $db->nameQuote( 'post_id' ) . '=b.' . $db->nameQuote( 'post_id' ) . ' '
  215. . 'INNER JOIN ' . $db->nameQuote( '#__easyblog_post' ) . ' AS d '
  216. . 'ON d.' . $db->nameQuote( 'id' ) . '=c.' . $db->nameQuote( 'post_id' ) . ' '
  217. . 'WHERE c.' . $db->nameQuote( 'team_id' ) . '=' . $db->Quote( $this->id ) . ' '
  218. . 'AND d.' . $db->nameQuote( 'published' ) . '=' . $db->Quote( POST_ID_PUBLISHED ) . ' '
  219. . 'GROUP BY a.' . $db->nameQuote( 'id' );
  220. $db->setQuery( $query );
  221. $rows = $db->loadObjectList();
  222. $tags = array();
  223. foreach( $rows as $row )
  224. {
  225. $tag = JTable::getInstance( 'Tag' , 'Table' );
  226. $tag->bind( $row );
  227. $tags[] = $tag;
  228. }
  229. return $tags;
  230. }
  231. /**
  232. * Retrieve a list of tags created by this team
  233. **/
  234. public function getPostCount()
  235. {
  236. $db =& JFactory::getDBO();
  237. $query = 'SELECT COUNT(1) FROM ' . $db->nameQuote( '#__easyblog_post' ) . ' AS a '
  238. . 'INNER JOIN ' . $db->nameQuote( '#__easyblog_team_post' ) . ' AS b '
  239. . 'ON b.' . $db->nameQuote( 'post_id' ) . '=a.' . $db->nameQuote( 'id' ) . ' '
  240. . 'WHERE b.' . $db->nameQuote( 'team_id' ) . '=' . $db->Quote( $this->id ) . ' '
  241. . 'AND ' . $db->nameQuote( 'published' ) . '=' . $db->Quote( 1 );
  242. $db->setQuery( $query );
  243. return $db->loadResult();
  244. }
  245. /**
  246. * Retrieve a list of categories used and created by this team members
  247. **/
  248. public function getCategories()
  249. {
  250. $db = JFactory::getDBO();
  251. $query = 'SELECT DISTINCT a.*, COUNT( b.' . $db->nameQuote( 'id' ) . ' ) AS ' . $db->nameQuote( 'post_count' ) . ' '
  252. . 'FROM ' . $db->nameQuote( '#__easyblog_category' ) . ' AS a '
  253. . 'INNER JOIN ' . $db->nameQuote( '#__easyblog_post' ) . ' AS b '
  254. . 'ON a.' . $db->nameQuote( 'id' ) . '=b.' . $db->nameQuote( 'category_id' ) . ' '
  255. . 'INNER JOIN ' . $db->nameQuote( '#__easyblog_team_post' ) . ' AS c '
  256. . 'ON c.' . $db->nameQuote( 'post_id' ) . '=b.' . $db->nameQuote( 'id' ) . ' '
  257. . 'WHERE c.' . $db->nameQuote( 'team_id' ) . '=' . $db->Quote( $this->id ) . ' '
  258. . 'GROUP BY a.' . $db->nameQuote( 'id' );
  259. $db->setQuery($query);
  260. return $db->loadObjectList();
  261. }
  262. /*
  263. * Determines whether the current blog entry belongs to the team.
  264. *
  265. * @param int $entryId The subject's id.
  266. * @return boolean True if entry was contributed to the team and false otherwise.
  267. */
  268. public function isPostOwner( $postId )
  269. {
  270. if( empty( $postId ) )
  271. {
  272. return false;
  273. }
  274. $db =& $this->getDBO();
  275. $query = 'SELECT COUNT(1) FROM ' . $db->nameQuote( '#__easyblog_team_post' ) . ' '
  276. . 'WHERE ' . $db->nameQuote( 'post_id' ) . '=' . $db->Quote( $postId ) . ' '
  277. . 'AND ' . $db->nameQuote( 'team_id' ) . '=' . $db->Quote( $this->id );
  278. $db->setQuery( $query );
  279. $result = $db->loadResult();
  280. return $result > 0;
  281. }
  282. function getRSS()
  283. {
  284. return EasyBlogHelper::getHelper( 'Feeds' )->getFeedURL( 'index.php?option=com_easyblog&view=teamblog&id=' . $this->id );
  285. }
  286. function getAtom()
  287. {
  288. return EasyBlogHelper::getHelper( 'Feeds' )->getFeedURL( 'index.php?option=com_easyblog&view=teamblog&id=' . $this->id , true );
  289. }
  290. }