Example #1
0
        /// <summary> </summary>
        public static Hashtable make_post_json_table(int iid, String type, Boolean dev)
        {
            //posting post = ActiveRecordBase<posting>.Find(iid);
            List <AbstractCriterion> filtering = new List <AbstractCriterion>();

            //if (!usedev) filtering.Add(Expression.Eq("revision", 0));
            if (iid > 0)
            {
                posting tmp = ActiveRecordBase <posting> .Find(iid);

                if (tmp.children.Count > 0)
                {
                    filtering.Add(Expression.Eq("parent", tmp));
                }
                else
                {
                    filtering.Add(Expression.Eq("baseid", iid));
                }
            }
            else
            {
                filtering.Add(Expression.Eq("is_default", true));
            }
            //parent
            filtering.Add(Expression.Eq("deleted", false));
            if (!String.IsNullOrWhiteSpace(type))
            {
                filtering.Add(Expression.Eq("post_type", ActiveRecordBase <posting_type> .FindFirst(
                                                new List <AbstractCriterion>()
                {
                    Expression.Eq("alias", type)
                }.ToArray())
                                            ));
            }
            posting post = ActiveRecordBase <posting> .FindFirst(new Order[] { Order.Desc("revision"), Order.Desc("version") }, filtering.ToArray());

            Hashtable post_json_obj = new Hashtable();


            Hashtable post_options_object = new Hashtable();

            String        post_type  = post.post_type.alias;
            List <string> properties = objectService.get_type_properties("posting");
            Assembly      assembly   = Assembly.GetExecutingAssembly();
            dynamic       item       = assembly.CreateInstance("stellar.Models." + type);

            foreach (String prop in properties)
            {
                PropertyInfo propInfo  = post.GetType().GetProperty(prop);
                String       prop_type = propInfo.PropertyType.Namespace;
                if (prop_type == "System")  //keep it to the basics to aviod a circular reference while serializing

                {
                    dynamic value = propInfo.GetValue(post, null);

                    if (prop == "static_file")
                    {
                        if (post.post_type.alias == "media")
                        {
                            string   uploads_path          = file_info.relative_site_uploads_path();
                            string[] generalized_file_path = value.Split(new String[] { "uploads/", "images/" }, StringSplitOptions.RemoveEmptyEntries);
                            string   file_path             = file_handler.normalize_path(uploads_path.Trim('/') + "/images/" + generalized_file_path[generalized_file_path.Length - 1].Trim('/'));
                            value = file_path;
                        }
                    }


                    post_options_object.Add(prop, value);
                }
            }


            Hashtable post_content_object = new Hashtable();

            post_content_object.Add("is_Code", post.is_Code);
            post_content_object.Add("useTiny", post.useTiny);

            List <Hashtable> post_partents = new List <Hashtable>();

            foreach (posting par_post in post.postparents)
            {
                Hashtable post_partent = new Hashtable();
                post_partent.Add("id", par_post.baseid);
                post_partent.Add("alias", par_post.alias);
                post_partent.Add("name", par_post.name);
                post_partent.Add("post_type", par_post.post_type.alias);
                post_partents.Add(post_partent);
            }
            post_content_object.Add("post_parents", post_partents);

            List <Hashtable> post_children = new List <Hashtable>();

            foreach (posting par_post in post.postchildren)
            {
                Hashtable post_child = new Hashtable();
                post_child.Add("id", par_post.baseid);
                post_child.Add("alias", par_post.alias);
                post_child.Add("name", par_post.name);
                post_child.Add("post_type", par_post.post_type.alias);
                post_children.Add(post_child);
            }
            post_content_object.Add("post_children", post_children);


            List <Hashtable> post_editors = new List <Hashtable>();

            foreach (appuser par_post in post.editors)
            {
                Hashtable post_editor = new Hashtable();
                post_editor.Add("id", par_post.baseid);
                post_editor.Add("alias", par_post.nid);
                post_editor.Add("name", par_post.display_name);
                post_editors.Add(post_editor);
            }
            post_content_object.Add("editors", post_editors);


            post_content_object.Add("fields", post.fields);

            post_content_object.Add("content", post.content);

            post_content_object.Add("post_type", post.post_type.alias);

            post_json_obj.Add("post_content", post_content_object);



            post_json_obj.Add("post_options", post_options_object);
            post_json_obj.Add("meta_data", post.get_all_meta());
            post_json_obj.Add("post_id", post.baseid);

            return(post_json_obj);
        }