@@ -1781,6 +1781,131 @@ public function login_remembered_user()
1781
1781
return FALSE ;
1782
1782
}
1783
1783
1784
+
1785
+ /**
1786
+ * create_group
1787
+ *
1788
+ * @author Ben Edmunds
1789
+ */
1790
+ public function create_group ($ group_name = FALSE , $ group_description = '' , $ additional_data = array ())
1791
+ {
1792
+ // bail if the group name was not passed
1793
+ if (!$ group_name )
1794
+ {
1795
+ $ this ->set_error ('group_name_required ' );
1796
+ return FALSE ;
1797
+ }
1798
+
1799
+ // bail if the group name already exists
1800
+ $ existing_group = $ this ->where ('name ' , $ group_name )->group ()->document ();
1801
+ if (isset ($ existing_group ) && !empty ($ existing_group ))
1802
+ {
1803
+ $ this ->set_error ('group_already_exists ' );
1804
+ return FALSE ;
1805
+ }
1806
+
1807
+ $ data = array ('name ' =>$ group_name ,'description ' =>$ group_description );
1808
+
1809
+ //filter out any data passed that doesnt have a matching column in the groups table
1810
+ //and merge the set group data and the additional data
1811
+ if (!empty ($ additional_data )) $ data = array_merge ($ this ->_filter_data ($ this ->collections ['groups ' ], $ additional_data ), $ data );
1812
+
1813
+ $ this ->trigger_events ('extra_group_set ' );
1814
+
1815
+ // insert the new group
1816
+ $ group_id = $ this ->mongo_db ->insert ($ this ->collections ['groups ' ], $ data );
1817
+
1818
+ // report success
1819
+ $ this ->set_message ('group_creation_successful ' );
1820
+
1821
+ // return the brand new group id
1822
+ return $ group_id ;
1823
+ }
1824
+
1825
+ /**
1826
+ * update_group
1827
+ *
1828
+ * @return bool
1829
+ * @author Ben Edmunds
1830
+ **/
1831
+ public function update_group ($ group_id = FALSE , $ group_name = FALSE , $ additional_data = array ())
1832
+ {
1833
+ if (empty ($ group_id )) return FALSE ;
1834
+
1835
+ $ data = array ();
1836
+
1837
+ if (!empty ($ group_name ))
1838
+ {
1839
+ // we are changing the name, so do some checks
1840
+
1841
+ // bail if the group name already exists
1842
+ $ existing_group = $ this ->where ('name ' , $ group_name )->group ()->document ();
1843
+ if (isset ($ existing_group ->id ) && $ existing_group ->id != $ group_id )
1844
+ {
1845
+ $ this ->set_error ('group_already_exists ' );
1846
+ return FALSE ;
1847
+ }
1848
+
1849
+ $ data ['name ' ] = $ group_name ;
1850
+ }
1851
+
1852
+
1853
+ // IMPORTANT!! Third parameter was string type $description; this following code is to maintain backward compatibility
1854
+ // New projects should work with 3rd param as array
1855
+ if (is_string ($ additional_data )) $ additional_data = array ('description ' => $ additional_data );
1856
+
1857
+
1858
+ //filter out any data passed that doesnt have a matching column in the groups table
1859
+ //and merge the set group data and the additional data
1860
+ if (!empty ($ additional_data )) $ data = array_merge ($ this ->_filter_data ($ this ->collections ['groups ' ], $ additional_data ), $ data );
1861
+
1862
+
1863
+ $ updated = $ this ->mongo_db
1864
+ ->where ('_id ' , new MongoId ($ group_id ))
1865
+ ->set ($ data )
1866
+ ->update ($ this ->collections ['groups ' ]);
1867
+
1868
+ $ this ->set_message ('group_update_successful ' );
1869
+
1870
+ return TRUE ;
1871
+ }
1872
+
1873
+ /**
1874
+ * delete_group
1875
+ *
1876
+ * @return bool
1877
+ * @author Ben Edmunds
1878
+ **/
1879
+ public function delete_group ($ group_id = FALSE )
1880
+ {
1881
+ // bail if mandatory param not set
1882
+ if (!$ group_id || empty ($ group_id ))
1883
+ {
1884
+ return FALSE ;
1885
+ }
1886
+
1887
+ $ this ->trigger_events ('pre_delete_group ' );
1888
+
1889
+
1890
+ // delete this group
1891
+ $ deleted = $ this ->mongo_db
1892
+ ->where ('_id ' , new MongoId ($ group_id ))
1893
+ ->delete ($ this ->collections ['groups ' ]);
1894
+
1895
+ if (!$ deleted )
1896
+ {
1897
+ $ this ->trigger_events (array ('post_delete_group ' , 'post_delete_group_unsuccessful ' ));
1898
+ $ this ->set_error ('group_delete_unsuccessful ' );
1899
+ return FALSE ;
1900
+ }
1901
+
1902
+
1903
+ $ this ->trigger_events (array ('post_delete_group ' , 'post_delete_group_successful ' ));
1904
+ $ this ->set_message ('group_delete_successful ' );
1905
+ return TRUE ;
1906
+ }
1907
+
1908
+
1784
1909
// ------------------------------------------------------------------------
1785
1910
1786
1911
/**
0 commit comments