Distiller Controller Update

Well it’s been about a month since the last time I posted anything on the site. I’ve been extremely busy! I got a new full-time job at eSchool Consultants as a web developer but don’t worry I’m still running and working with my LLC’s clients and doing work as usual. This isn’t an insanely long post it’s just an update to the Distiller Controller for a couple of products that I received today.

Down to business

I have finally got some more funds in order to purchase some tools so that I can go forward with my distiller controller. In order to utilize the heating elements that I purchased I needed to make some modifications to the distiller. I had to purchase some drill step bits as well as a drill. I got these both from Amazon for a decent price. The most expensive was the drill at about $155 bucks. The step bits were only about $31.

Details of products purchase:

Bosch 36618-02 18-Volt 1/2-Inch Compact-Tough Litheon Drill/Driver with 2 Slim Batteries : $153.25
Neiko 5-Piece Step Drill Bit Set with Metal Case – SAE : $30.16

Till next time!

Posted in Distillation Controller | Tagged , , , , , , , , , , | Leave a comment

Installing User Module – Yii Framework

Whenever I discover something new in the web development world I like to dive headfirst into the deep-end. This was the case when I first got into developing with the Yii framework. I did look at a few basics before I went too far. For example, I watched all of the screencasts on the Yii website that basically explains the bare minimum of Yii. Besides that I was off to the races as far as exploring the code and figuring out how it’s constructed.

With that said, the personal project that I’m currently working on needed a strong foundation for user profiles and instead of re-inventing the wheel I searched for a pre-existing solution. I found a Yii module entitled User that has been developed enough to use in a project that needs a user-based profile functionality. Like I first mentioned above, I dove right into this without reading how to properly install extensions/modules and if you follow the directions on on the Yii User documentation page you’ll find that there is more to it than what is given.

The first direction that is given on the module page is “Extract the release file under protected“. This insinuates that all of the files within the downloaded file goes within the corresponding directories within the protected folder. So after doing this and following the rest of the directions I kept getting weird Yii errors namely one that says something to the effect of “user.UserModule is invalid. Make sure it points to an existing PHP file.”. I found somebody in the comments section that was having the same issue but nobody was helping this guy. So after about an hour of trying several different things without any luck I decided to check that I properly installed the module and/or if there was a proper way to install modules.

How to install a module:

Well wouldn’t you know that there is a proper/formal way to install modules within Yii which annoyed me because the directions should of at least hinted towards this. After all this is what documentation is for. So instead of extracting all of the module files directly into the protected directory the files actually need to be put into a directory call “modules”. Once you, yes you, create the “modules” directory then the module files go into this directory within a folder of the same name as the main class (it’s usually the same name of the extensions main class). So when it comes to the User module you should put all of it’s downloaded files within a folder with the following structure: “root->protected->modules->user”.

The rant:

My biggest bitch is that it’s just understood that modules go within a directory called modules within the protected directory. It would make more sense that when you first create a Yii project from the command line that it just automatically makes this directory so it’s a little more clear as to where modules go. If the automated process went ahead and made this directory then I think this could have easily saved me some time and collectively this would have saved thousand of hours across the board for Yii developers. Think about all of those hours that could have been used to further along the Yii framework if they could have created a simple directory.

If you have any questions feel free to leave a comment and I’ll get back to you as soon as possible.

Posted in Web Development, Yii | Tagged , , , , , , | 1 Comment

Returning Database Results Based on User ID – Yii Framework

Since I’m new when it comes to working with the Yii framework it took me a few of hours to figure out how to selectively pull data from the database when loading a model and it’s data. So in order for this to make sense to those of you that have no idea on what I was  trying to achieve I need to give a little background.

For the current Yii project that I’m making I first needed a solid foundation for user management and instead of potentially re-creating the wheel I searched to see if there was an existing solution. I found a Yii module entitled Yii User. Yii User gives a Yii project basic user management functionality. This module also has a few basic class functions that allow to check if a user is an admin, list all admins, various calls to get information on users, and most importantly for us their user id. I will also be doing an entry for installing this module because the directions that are given on that link that I provided aren’t the clearest.

After I got the Yii User module squared away I made a new Model and CRUD operations for this new model via the Gii functionality. For the purposes of this howto we’ll go ahead and call our new model Cars.

When a user creates a new entry using the Cars model their user id is saved along with this data. Now when we go to the index page of this Cars model on the site it lists all entries from the database. This out-of-the-box functionality isn’t realistic to a real world application because when I’m logged into the site and go to the cars index I should be able to only see my list of cars and not the entire site’s list of cars. So we have to somehow tell the system that we only want to list the cars that are associated with the currently logged-in user.

To the point:

When a model’s data is loaded it utilizes a function in it’s controller called actionIndex and within this function we can see that it initializes an object called CActiveDataProvider. When someone views the main index page of a model it loads all of the information from the database via a variable called $dataProvider. You can see this in action if we go to the following file and look at the bottom portion: “protected->views->cars->index.php”. So where does the $dataProvider variable get it’s data? Well the CActiveDataProvider object of course.

When a model and it’s controller are made by the automation process provided by the Gii functionality it fails to fully utilize all of CActiveDataProvider’s functionality which is why it took me forever to figure out that this is indeed where I need to be in order to accomplish what I needed. During my hours long search for an answer I came upon this link that gives an example of how we could use some advanced features of CActiveDataProvider. In Yii there’s an object that works in conjunction with CActiveDataProvider that provides these advanced features called CDbCriteria. This object basically gives the developer the ability to provide some arguments to CActiveDataProvider in order to narrow/filter it’s results. So if we go to Yii’s API documentation for CDbCriteria we can see that there is a function called addSearchCondition.

Putting it all together:

Going back to the actionIndex function within the Cars controller we can see that the original code looks something like the following:

public function actionIndex()
{
    $dataProvider=new CActiveDataProvider('Cars');
    $this->render('index',array(
        'dataProvider'=>$dataProvider,
    ));
}

Combining the Yii User module functionality with CDbCriteria to achieve a more realistic database interaction:

public function actionIndex()
{
    // Get the user object and assign the user id
    $userObject = Yii::app()->getModule('user')->user();
    $userId = $userObject->id;
    // Create a new CDbCriteria object
    $criteria = new CDbCriteria();
    // Assign search criteria
    $criteria->addSearchCondition( 'user_id', $userId, true, 'OR' );
    // If the user is an admin then show all.
    // Otherwise show only cars that belong to the user.
    if(Yii::app()->getModule("user")->isAdmin()){
	$dataProvider=new CActiveDataProvider('Cars');
    }else{
	$dataProvider=new CActiveDataProvider('Cars',array(
                              'criteria'=>$criteria,
                          ));
    }
    // Initialize the $dataProvider variable that will be used
    // on the index.php page
    $this->render('index',array(
	'dataProvider'=>$dataProvider,
    ));
}

Explanation of above code:

First we are initializing the user module and assigning the user object to a variable called $userObject. Remember, this object is for the current user that is logged in. Then we are pulling the user id out of the user object and assigning it to a variable that we’ll use within our criteria filter. After we’re done with getting our user information we need to initialize the CDbCriteria object ($criteria) and add a search parameter via the addSearchCondition function. Then we implement a simple if/else statement basically saying “If the current user is an admin then thay can see all of the data. (Else) If they aren’t an admin then they can only return data that is associated with their user id.”. The last part is essentially assigning the data that has been retrieved from the database to the $dataProvider variable that will be used on the index.php that was mentioned earlier.

For more information on CActiveDataProvider go here and for more information on CDbCriteria go here.

If you have any questions feel free to leave a comment and I’ll get back to you as soon as possible.

Posted in Web Development, Yii | Tagged , , , , , , , , , , , | 4 Comments

Yii – PHP Developer Framework

I just recently discovered Yii and one of the major issues I was having is running the necessary commands within my Windows 7 environment. If your website is in a shared hosting environment you have to run the commands locally and then upload the files that are generated. As a PHP developer I’m not a fan of having to use command prompts in order to generate files. For that reason I was absolutely enamored by Recess but unfortunately it looks as though it has stopped being supported by it’s own developers and I’m guessing because there isn’t a huge demand for it.

Anyways, back to the task at hand.

In order to run the commands you’re going to need to install a LAMP environment such as XAMPP, MAMP, etc. I personally use XAMPP so all of the example commands refer to this LAMP environment.

In the Windows environment you’ll pull up the command prompt by going to Start and then type cmd into the search box and press enter. When you installed XAMPP it is recommended that you install it within the root of the C:\ drive. So I access my XAMPP installation by going to the following C:\xampp\.

So if you watch the screencast on Yii’s website that show you how to install and start working with Yii you’ll first notice that they are working within a Mac environment. Since running commands is a core essential within Yii it’s important that we know exactly how to run the commands within the more widely used Windows environment. If you know anything about the command line(terminal) usage for the Mac then you’ll know that it isn’t even close to the command prompt within Windows so trying to run the commands exactly how they’re run in the screencast will result in failure.

The proper way to install the demo app from the screencast within the Windows environment:
OK, we installed XAMPP and now you need to put the Yii environment within it. To make it easier on yourself make a directory within “C:\xampp\htdocs” called “yii” EX: “C:\xampp\htdocs\yii”. Then extract all of the Yii files to it.

Now on to the nitty gritty.

Location_of_php.exe Location_of_yiic.php webapp Location_of_newly_created_app
For my purposes the following is how I would install the new Yii demo app to the root of my Yii folder:
C:\xampp\php\php.exe C:\xampp\htdocs\yii\framework\yiic.php webapp C:\xampp\htdocs\yii\demo_from_screencast

Just to quell the confusion, the above is suppose to be all on one line.

If you have any questions leave a comment!

Posted in Web Development, Yii | Tagged , , , , , | Leave a comment

Enclosure Mockup – Distillation Controller

I have designed a 3D mockup of the enclosure via some free 3D software from Protocase.com. The enclosure is 12″ x 7″ x 12″ (width x height x depth). As you can see from the screen-shots below the main panel area is at a slight angle (the design is what is referred to as a console). The angle should allow the user a slightly more ergonomic design plus it looks better like this than just a plain old box-like design.

Ordering just one isn’t the cheapest solution but I think I’ll have to bite the bullet once I start parading it around to potential investors. I was thinking about an acrylic enclosure which I still might do for the testing stage. The total for the enclosure as it is in the screen-shots below is $369.06. The plan for when these go to market is to make an initial 100 units. The cost comes down to about $103.71 per enclosure when ordered in groups of 100. If you order more than this there isn’t much of a price difference no matter if it’s 1,000 or 10,000. There’s roughly a $0.70 difference give or take.

Screen-shots from the Mockup (the red arrows are just a point of reference when you’re working within the software so you know which way is up, down, etc. also known as the X Y Z axis):

Posted in Distillation Controller | Tagged , , , , | Leave a comment