create-forum.php
2 years ago
create-topic.php
2 years ago
post-reply-in-topic.php
2 years ago
subscribeuserinforum.php
2 years ago
create-topic.php
97 lines
| 1 | <?php |
| 2 | /** |
| 3 | * CreateTopic. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category CreateTopic |
| 7 | * @package SureTriggers |
| 8 | * @author BSF <username@example.com> |
| 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 10 | * @link https://www.brainstormforce.com/ |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | |
| 14 | namespace SureTriggers\Integrations\Asgaros\Actions; |
| 15 | |
| 16 | use Exception; |
| 17 | use SureTriggers\Integrations\AutomateAction; |
| 18 | use SureTriggers\Integrations\WordPress\WordPress; |
| 19 | use SureTriggers\Traits\SingletonLoader; |
| 20 | use AsgarosForumAdmin; |
| 21 | use AsgarosForum; |
| 22 | |
| 23 | /** |
| 24 | * CreateTopic |
| 25 | * |
| 26 | * @category CreateTopic |
| 27 | * @package SureTriggers |
| 28 | * @author BSF <username@example.com> |
| 29 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 30 | * @link https://www.brainstormforce.com/ |
| 31 | * @since 1.0.0 |
| 32 | */ |
| 33 | class CreateTopic extends AutomateAction { |
| 34 | |
| 35 | /** |
| 36 | * Integration type. |
| 37 | * |
| 38 | * @var string |
| 39 | */ |
| 40 | public $integration = 'Asgaros'; |
| 41 | |
| 42 | /** |
| 43 | * Action name. |
| 44 | * |
| 45 | * @var string |
| 46 | */ |
| 47 | public $action = 'asgaros_create_topic'; |
| 48 | |
| 49 | use SingletonLoader; |
| 50 | |
| 51 | /** |
| 52 | * Register a action. |
| 53 | * |
| 54 | * @param array $actions actions. |
| 55 | * @return array |
| 56 | */ |
| 57 | public function register( $actions ) { |
| 58 | $actions[ $this->integration ][ $this->action ] = [ |
| 59 | 'label' => __( 'Create a topic', 'suretriggers' ), |
| 60 | 'action' => $this->action, |
| 61 | 'function' => [ $this, 'action_listener' ], |
| 62 | ]; |
| 63 | |
| 64 | return $actions; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Action listener. |
| 69 | * |
| 70 | * @param int $user_id user_id. |
| 71 | * @param int $automation_id automation_id. |
| 72 | * @param array $fields fields. |
| 73 | * @param array $selected_options selectedOptions. |
| 74 | * @throws Exception Exception. |
| 75 | * |
| 76 | * @return bool|array|void |
| 77 | */ |
| 78 | public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) { |
| 79 | if ( ! class_exists( 'AsgarosForum' ) ) { |
| 80 | return false; |
| 81 | } |
| 82 | $asgaros_forum = new AsgarosForum(); |
| 83 | $forum_id = $selected_options['forum_id']; |
| 84 | $topic_title = $selected_options['topic_title']; |
| 85 | $topic_description = $selected_options['topic_description']; |
| 86 | $author_id = $selected_options['author_id']; |
| 87 | |
| 88 | $topic_details = $asgaros_forum->content->insert_topic( $forum_id, $topic_title, $topic_description, $author_id ); |
| 89 | $topic = (array) $asgaros_forum->content->get_topic( $topic_details->topic_id ); |
| 90 | $post = (array) $asgaros_forum->content->get_post( $topic_details->post_id ); |
| 91 | $user = WordPress::get_user_context( $author_id ); |
| 92 | return array_merge( $topic, $post, $user ); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | CreateTopic::get_instance(); |
| 97 |