From 4c250aa02560dbd7c6d885657860e55420afce67 Mon Sep 17 00:00:00 2001 From: Moiz Sitabkhan Date: Sun, 18 Jan 2015 11:54:09 +0400 Subject: [PATCH 1/4] function to return a MongoId object from string --- libraries/cimongo/Cimongo_extras.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/cimongo/Cimongo_extras.php b/libraries/cimongo/Cimongo_extras.php index 15f4cd7..925523c 100644 --- a/libraries/cimongo/Cimongo_extras.php +++ b/libraries/cimongo/Cimongo_extras.php @@ -199,6 +199,17 @@ public function create_dbref($collection = "", $id = "", $database = FALSE ){ } } + /** + * Utility function that generates a MongoID instance + * + * @param string The string representation of the desired ID object + * @return MongoId + * @access public + */ + public function generate_id($id) { + return new MongoId($id); + } + /** * Get the documents where the value of a $field is greater than $x * @since v1.0.0 @@ -437,4 +448,4 @@ public function rename_field($old, $new){ $this->updates['$rename'][] = array($old => $new); return $this; } -} +} From de199e52380ef347552f4eb1fc9f063f911dce84 Mon Sep 17 00:00:00 2001 From: Moiz Sitabkhan Date: Sun, 18 Jan 2015 11:58:06 +0400 Subject: [PATCH 2/4] function to return a MongoDate object from string You can pass a unix timestamp as an integer of a date format string like yyyy/mm/dd --- libraries/cimongo/Cimongo_extras.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libraries/cimongo/Cimongo_extras.php b/libraries/cimongo/Cimongo_extras.php index 925523c..79ae2e5 100644 --- a/libraries/cimongo/Cimongo_extras.php +++ b/libraries/cimongo/Cimongo_extras.php @@ -200,7 +200,8 @@ public function create_dbref($collection = "", $id = "", $database = FALSE ){ } /** - * Utility function that generates a MongoID instance + * Utility function that generates a MongoID instance. + * Original inspiration from https://github.com/chuckcfs/CodeIgniter-MongoDB * * @param string The string representation of the desired ID object * @return MongoId @@ -210,6 +211,23 @@ public function generate_id($id) { return new MongoId($id); } + /** + * Utility function to generate a 'MongoDate' object + * Original inspiration from https://github.com/chuckcfs/CodeIgniter-MongoDB + * + * @param mixed Either a unix timestamp(int) or a string based date. Suggest format yyyy/mm/dd + * @return MongoDate The date object, access the 'sec' property for the timestamp + * @access public + */ + public function generate_date($param = null) { + if($param) { + is_string($param) ? $date = new MongoDate(strtotime($param)) : $date = new MongoDate($param); + } else { + $date = new MongoDate(); + } + return $date; + } + /** * Get the documents where the value of a $field is greater than $x * @since v1.0.0 From c79adf8b64c843c450223f9c6b70202f95903aae Mon Sep 17 00:00:00 2001 From: Moiz Sitabkhan Date: Sun, 18 Jan 2015 11:59:57 +0400 Subject: [PATCH 3/4] function to return a MongoBinData object for file --- libraries/cimongo/Cimongo_extras.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libraries/cimongo/Cimongo_extras.php b/libraries/cimongo/Cimongo_extras.php index 79ae2e5..15ed058 100644 --- a/libraries/cimongo/Cimongo_extras.php +++ b/libraries/cimongo/Cimongo_extras.php @@ -228,6 +228,21 @@ public function generate_date($param = null) { return $date; } + /** + * Utility function to generate a 'MongoBinData' object to store a file as part of a document. + * You must pass the binary data of the file and not a file path. + * + * @param string The content of the file to store + * @return MongoBinData A ready-to-store representation of the binary data + * @access public + */ + public function generate_bindata( $contents ) { + if(empty($contents)) { + show_error('You must provide the contents a file to this function', 500); + } + return new MongoBinData( $contents ); + } + /** * Get the documents where the value of a $field is greater than $x * @since v1.0.0 From bfe2e993cda9d317229f97a42e708422481b1a38 Mon Sep 17 00:00:00 2001 From: Moiz Sitabkhan Date: Sun, 18 Jan 2015 12:09:26 +0400 Subject: [PATCH 4/4] close connection function. --- libraries/cimongo/Cimongo.php | 18 +++++++++--------- libraries/cimongo/Cimongo_base.php | 8 ++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/libraries/cimongo/Cimongo.php b/libraries/cimongo/Cimongo.php index b5bad76..5fc8072 100644 --- a/libraries/cimongo/Cimongo.php +++ b/libraries/cimongo/Cimongo.php @@ -1,7 +1,6 @@ db=$this->cimongo + * Fake close function so you can bind $this->db=$this->cimongo. + * NO LONGER A FAKE. * */ public function close() { - + return $this->close_db(); } /** diff --git a/libraries/cimongo/Cimongo_base.php b/libraries/cimongo/Cimongo_base.php index bb9999b..c00e50a 100644 --- a/libraries/cimongo/Cimongo_base.php +++ b/libraries/cimongo/Cimongo_base.php @@ -136,6 +136,14 @@ private function connect(){ } } + /** + * + */ + private function close_db() { + $this->db = NULL; + return $this->connection->close(); + } + /** * Create connection string *