start.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * Assemblies -- Essentials for group decision making
  4. *
  5. * @package Lorea
  6. * @subpackage Assemblies
  7. * @homepage http://lorea.org/plugin/assemblies
  8. * @copyright 2011-2013 Lorea Faeries <federation@lorea.org>
  9. * @license COPYING, http://www.gnu.org/licenses/agpl
  10. *
  11. * Copyright 2011-2013 Lorea Faeries <federation@lorea.org>
  12. *
  13. * This program is free software: you can redistribute it and/or
  14. * modify it under the terms of the GNU Affero General Public License
  15. * as published by the Free Software Foundation, either version 3 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful, but
  19. * WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public
  24. * License along with this program. If not, see
  25. * <http://www.gnu.org/licenses/>.
  26. */
  27. elgg_register_event_handler('init', 'system', 'assemblies_init');
  28. /**
  29. * Init assemblies plugin.
  30. */
  31. function assemblies_init() {
  32. if (!elgg_is_active_plugin('crud')) {
  33. return;
  34. }
  35. elgg_register_library('elgg:assemblies', elgg_get_plugins_path() . 'assemblies/lib/assemblies.php');
  36. // add to the main css
  37. elgg_extend_view('css/elgg', 'assemblies/css');
  38. // notifications
  39. register_notification_object('object', 'assembly', elgg_echo('assemblies:newpost'));
  40. elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'assemblies_notify_message');
  41. // handler for link to assembly menu item
  42. elgg_register_plugin_hook_handler('crud:decision:view_buttons', 'view_buttons', 'assemblies_decision_view_buttons');
  43. // Add group option
  44. add_group_tool_option('assemblies', elgg_echo('assemblies:enableassemblies'), false);
  45. #elgg_extend_view('groups/tool_latest', 'assemblies/group_module');
  46. elgg_extend_view('groups/profile/summary','assemblies/group_module');
  47. // add a assemblies widget
  48. elgg_register_widget_type('assembly', elgg_echo('assemblies'), elgg_echo('assemblies:widget:description'));
  49. // register actions
  50. $action_path = elgg_get_plugins_path() . 'assemblies/actions/assemblies';
  51. elgg_register_action("assemblies/link", "$action_path/link.php");
  52. //elgg_register_action('assemblies/save', "$action_path/save.php");
  53. //elgg_register_action('assemblies/delete', "$action_path/delete.php");
  54. // entity menu
  55. elgg_register_plugin_hook_handler('register', 'menu:entity', 'assemblies_entity_menu_setup');
  56. // ecml
  57. elgg_register_plugin_hook_handler('get_views', 'ecml', 'assemblies_ecml_views_hook');
  58. // specific actions
  59. $action_path = elgg_get_plugins_path() . 'assemblies/actions/assemblies';
  60. elgg_register_action("assemblies/general", "$action_path/general.php");
  61. // data types
  62. $variables = array(
  63. 'title' => array(
  64. 'type' => 'text',
  65. 'default_value' => elgg_echo('assemblies:general_assembly'),
  66. ),
  67. 'category' => array(
  68. 'type' => 'tags',
  69. 'default_value' => 'informativos, debate',
  70. ),
  71. #'description' => 'longtext',
  72. 'date' => 'date',
  73. 'time' => 'time',
  74. 'location' => 'text',
  75. #'tags' => 'tags',
  76. 'access_id' => 'access',
  77. );
  78. $crud = crud_register_type('assembly', $variables, 'ElggAssembly');
  79. $crud->children_type = 'decision';
  80. $crud->children_categories = 'category';
  81. $crud->module = 'assemblies';
  82. $crud->list_order = 'date';
  83. $crud->list_order_direction = 'DESC';
  84. $crud->owner_menu = 'group';
  85. $crud->title_extend = 'date';
  86. $crud->list_tabs = 'date';
  87. $variables = array(
  88. 'title' => 'text',
  89. 'description' => 'longtext',
  90. 'proposal' => array(
  91. 'type' => 'longtext',
  92. 'embedded' => 'description',
  93. ),
  94. #'date' => 'date',
  95. 'status' => array(
  96. 'type' => 'crud/select',
  97. 'default_value' => 'new',
  98. 'options' => array('draft', 'new', 'accepted', 'discarded', 'delayed'),
  99. ),
  100. 'category' => array(
  101. 'type' => 'crud/parentselect',
  102. 'property' => 'category',
  103. ),
  104. 'mode' => array(
  105. 'type' => 'crud/select',
  106. 'default_value' => 'conjunctural',
  107. 'options' => array('permanent', 'conjunctural'),
  108. ),
  109. 'tags' => 'tags',
  110. 'access_id' => 'access',
  111. );
  112. if (elgg_is_active_plugin('crud')) {
  113. $crud = crud_register_type('decision', $variables);
  114. #$crud->children_type = 'agenda_point';
  115. $crud->module = 'assemblies';
  116. $crud->embed = 'firstchild';
  117. $crud->icon_var = 'status';
  118. $crud->list_tabs = 'status';
  119. }
  120. }
  121. /**
  122. * Add particular assembly links/info to entity menu
  123. */
  124. function assemblies_entity_menu_setup($hook, $type, $return, $params) {
  125. if (elgg_in_context('widgets')) {
  126. return $return;
  127. }
  128. $entity = $params['entity'];
  129. $handler = elgg_extract('handler', $params, false);
  130. if ($handler != 'assembly') {
  131. return $return;
  132. }
  133. return $return;
  134. }
  135. /**
  136. * Set the notification message body
  137. *
  138. * @param string $hook Hook name
  139. * @param string $type Hook type
  140. * @param string $message The current message body
  141. * @param array $params Parameters about the assembly posted
  142. * @return string
  143. */
  144. function assembly_notify_message($hook, $type, $message, $params) {
  145. $entity = $params['entity'];
  146. $to_entity = $params['to_entity'];
  147. $method = $params['method'];
  148. if (elgg_instanceof($entity, 'object', 'assembly')) {
  149. $descr = $entity->excerpt;
  150. $title = $entity->title;
  151. $owner = $entity->getOwnerEntity();
  152. return elgg_echo('assembly:notification', array(
  153. $owner->name,
  154. $title,
  155. $descr,
  156. $entity->getURL()
  157. ));
  158. }
  159. return null;
  160. }
  161. /**
  162. * Register assemblies with ECML.
  163. */
  164. function assemblies_ecml_views_hook($hook, $entity_type, $return_value, $params) {
  165. $return_value['object/assembly'] = elgg_echo('assemblies:assemblies');
  166. return $return_value;
  167. }
  168. /**
  169. * Show button to link decision to next assembly
  170. */
  171. function assemblies_decision_view_buttons($hook, $type, $return, $params) {
  172. $entity = $params['entity'];
  173. $group = $entity->getContainerEntity();
  174. if (empty($entity->parent_guid) && $group->assemblies_enable == "yes") {
  175. elgg_register_menu_item('title', array(
  176. 'name' => 'link',
  177. 'href' => "action/assemblies/link?guid=$entity->guid",
  178. 'text' => elgg_echo("assemblies:decision:link"),
  179. 'is_action' => true,
  180. 'link_class' => 'elgg-button elgg-button-action',
  181. ));
  182. }
  183. }