Code that Suits Us


Hello! I had quite a small dilemma this month. As fact I am working on a small CMS that I create by myself. Not being arrogant or self prided, it was just for exercise so that I could keep myself away from games (especially DoTA 2 that had taken so many of my Internet quota). I also wish that it will help people one day. As note, Framework Method here means methods that you can use from the framework that can ease your work. Plain Codes here means methods that the language give, using plain language, or method from existing library that the language use. Wrapped Codes are similar like framework method, but it is not always from the framework.

As you people know, I was working on websites using Sitecore, Orchard, and YAF lately. The first story is when I was working with Orchard CMS. The CMS itself has so many interfaces and classes that implements it. If you have ever read Head First OOAD, you encounter a phrase, “You may extend, but may not modify.” Well it is not really like that, but quite similar. For real, I get in touch with that phrase when I worked with Orchard. Somehow, there is a problem. The moment I wanted to add a field on a specific table, I had to add the reference in many files, and created another method related to the module that handles it. Meanwhile, I thought using simple SQL stored procedure could do the same job.

The second story, when I was on Sitecore, I wanted to add simple cookie to my web. It should be as simple as in MSDN, I am sure. At first, of course, I tried plain codes first. I got stressed somehow because my cookie is exist in the response header, but not injected to the browser. Later on, then I learned that Sitecore have their own method on adding cookie to the website. The method simplify our task in creating cookie, but it is such a pain in the ass because the limitation that it gives. While in the plain codes I mention earlier, I can modify much as I want. I am not saying that Sitecore is little evil because of that. I ever tried to send email using plain code and it works just the same like using Sitecore sending email method.

The third story, this is related to the second story. I created the cookie using jQuery cookie this time. Somehow, there is only one method, but, the parameters give the plugin user more flexibility in creating the cookie. Also from the file, I can extend the method easily (follows the OOAD rule, eh?).

The fourth and the last (finally!) story, when I was using Code Igniter (PHP). They have their own methods, they create it as flexible as possible, and also, when I use the plain methods, what I wish is what I got (with some trial-error of course).

Finally I come to this part, meditation. As I am going to create my small CMS, I come to conclusion, I better let the future developer able to use plain methods, more extensible methods, and provide flexible-as-possible framework methods. Letting the developer using plain codes is somehow letting their more expressive. But also, if I want to create a framework method for my CMS, I better make it as flexible as possible.

Again, I am not trying to judge every single CMS/platform/Framework that I use. I just use it as my daily experience. Everything is great and good, but of course everything has a flaw. Maybe for me I don’t like it, then I consider it as flaw, for others is good. Feel free to comment 😀

Advertisements

Sitecore – When You Are Not The Super User


Again I interact with Sitecore. This time because the project (still the same as before) is published in other server (not our server) and we have so limited access to it, I took liberty to create a small “Admin Panel”-like place for my client to get the data they need.

The basic requirement is simple. Our client just want to see the list of users that have been registered in their web. Before this page is exist, we tried to look on the after registration page through google analytics. Then it will cause us a lot of time and a lot of effort with a minimal result. Then the requirement come and as I have written earlier, they want to see the list of users.

The main thing in list of users must be email address, username, and registration date. The hardest yet still easy part to get is the registration date of every user. Basically, sitecore CMS automatically saved the registration date of every user. But, only those who are allowed that can see it in the back end. Since I am not the super admin, I made some modification on the way my users register. Using the code below, I can record the date of register.

newUser.Profile.SetCustomProperty("registerDate", DateTime.Now.ToString());

On the “Admin Panel” then use the code below.

List<User> listUser = Sitecore.Security.Accounts.UserManager.GetUsers().Where(o => o.Name.ToLowerInvariant().StartsWith("YourDomainName\\") && !o.Name.ToLowerInvariant().Contains("anonymous")).ToList();

aRepeater.DataSource = listUser;
aRepeater.DataBind();

Well, It is quite easy. But it bug me quite a short time to figure that up. The bad thing is that the custom property can only contains string. Means we can really use the date time easily. If you encounter the same requirement, please create the custom property from the start. Why? Because it is needed for the user custom property data to be recorded from the start. If you have already create a registration and encounter the same problem as me, doing the same method, then handle your exceptions well.

This custom property on user is quite useful too. One can store some things inside, as long as it is a string. Well, if you have other way to access it, then please share it 🙂