Tuesday, 31 January 2017

Error: can not find module ‘underscore’

Error: can not find module ‘underscore’

Windows

npm install rimraf -g
rimraf node_modules
sudo npm install 

Friday, 8 May 2015

Conflict with stitch and sass newer releases

Lately we are having issue with compass, exactly with sass > 3.2.9 compatibility with stitch, so one of solution is to install olders versions that work. This iis what I needed:

> gem install sass  --version 3.2.9
> gem install compass  --version 0.12.0
> gem install stitch  --version 0.1.6
>gem install bootstrap-sass --version 3.3.1.0

Monday, 8 September 2014

First steps for already exisitngs projects in Laravel

I often have problems to remember what to do when I get to work on existing Laravel project.


Frist error I get is:

"../vendor/autoload.php): failed to open stream: No such file or directory in .."

To fix this, just run in Terminal
composer install
Then setup .htaccess.

Next thing, in config folder to setup local configuration (database and other settings), I usually do like here: http://laravel.com/docs/configuration#environment-configuration.

After setting up the conf next id database. Create database and then run
php artisan migrate
to create tables in your database.

And

php artisan db:seed

to seed data.

And now should be all running.

To set up mail work on localhost and not to send real mails  ...app\config\local\mail.php


return array(
 'driver' => 'mail',);

Friday, 25 January 2013

Create task using symfony and run it form action

Create MyTask.class.php in /lib/Task folder. It should look like this:
/**
 * MyTask class.
 *
 * @author ...
 */
class MyTask extends sfPropelBaseTask
{

  /**
   * Execute configure method.
   * 
   */
  protected function configure()
  {
    $this->addOptions(array(
      new sfCommandOption('application', NULL, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', 'front'),
      new sfCommandOption('env', NULL, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', NULL, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
    ));

    $this->namespace = 'namespace';
    $this->name = 'myTask';
    $this->briefDescription = 'Do Task';
    $this->detailedDescription = 'Do Task desc';
  }

  /**
   * Execute execute method.
   * 
   * @param array $arguments
   * @param array $options
   * 
   */
  protected function execute($arguments = array(), $options = array())
  {
    sfContext::createInstance($this->configuration);
    
    //Do Task

  }

}
And now, run it from action that you need:
    $dispatcher = sfContext::getInstance()->getEventDispatcher();
    $formatter = new sfFormatter();
    $task = new ReminderToWriteReviewTask($dispatcher, $formatter);
    chdir(sfConfig::get('sf_root_dir'));
    $task->run(array(), array('connection' =>  sfConfig::get('connection')));
You can also call the task, as it should be called, from command line
    php symfony namespace:myTask

Friday, 9 November 2012

symfony guard group permissions from database


Sometimes we need to have permission from database.
Suppose that uor tables look like this:

guard_permission:
    _attributes:                            { phpName: GuardPermission }
    code:                                   { type: char,    size: 150, required: true,  primaryKey: true }
    name:                                   { type: varchar, size: 100, required: true   }

  guard_group:
    _attributes:                            { phpName: GuardGroup }
    code:                                   { type: char,    size: 150, required: true,  primaryKey: true }
    name:                                   { type: varchar, size: 100, required: true   }
    description:                            { type: longvarchar,        required: false  }
    is_default:                             { type: boolean,            required: true,  default: false }

  guard_group_permission:
    _attributes:                            { phpName: GuardGroupPermission }
    id:                                     ~
    group_code:                             { type: char,    size: 150, required: true,  foreignTable:  guard_group,       foreignReference: code,   onDelete: cascade }
    permission_code:                        { type: char,    size: 150, required: true,  foreignTable:  guard_permission,  foreignReference: code,   onDelete: cascade }

  guard_user:
    _attributes:                            { phpName: GuardUser }
    id:                                     ~
    is_email_verified:                      { type: boolean,            required: true,  default: false  }

  guard_user_group:
    _attributes:                            { phpName: GuardUserGroup }
    id:                                     ~
    user_id:                                { type: integer,            required: true,  foreignTable: guard_user,       foreignReference: id,   onDelete: cascade }
    group_code:                             { type: char,    size: 150, required: true,  foreignTable: guard_group,      foreignReference: code, onDelete: cascade }


To check permissions from database, we just need to override  hasCredential method in apps/app_name/lib/MyUser.php. My data in database were 'module_name-action_name' e.g (permisssion_code: home-index), so i have overwritten parmission name to look like data from database.


 /**
   * Overridden method to use data from DB
   *
   * @param  string  permission name
   *
   * @return boolean true if the user has credential
   */

  public function hasCredential($permission_name)
  {
    if(!$this->isAuthenticated())

    {
      return false;
    }

    $GuardUser = $this->getGuardUser();

    $c = new Criteria();
    $c->add(GuardUserGroupPeer::USER_ID, $GuardUser->getId());
    $UserGroup = GuardUserGroupPeer::doSelectOne($c);   

    $Group = $UserGroup->getGuardGroup();
    $permissions = $Group->getGuardGroupPermissions();

    $permission_names = array();
    foreach($permissions as $permission)

    {
      $permission_names[] = $permission->getPermissionCode();
    }

   
    $moduleName = sfContext::getInstance()->getModuleName();
    $actionName = sfContext::getInstance()->getActionName();
    $permission_name = $moduleName . '-' . $actionName;

    return (in_array($permission_name, $permission_names)) ? true : false;
  }


Now all we need is to fill out the data in database, and this should work.

Wednesday, 7 November 2012

Create ssl certificate for site

If You allready have configured your apache server for ssl, type in these command lines for new cert for site

openssl req -new -days 365 -nodes -out www.mydomain.com.csr`
openssl x509 -in www.mydomain.com.csr -out www.mydomain.com.cert -req -signkey www.mydomain.com.key -days 365


And add your configuration to thhpd-ssl.conf


<VirtualHost _default_:443> 
    ServerAdmin admin@admin.com 
    DocumentRoot "YOUR_PRROJECT_PATH" 
    ServerName YOUR_PRROJECT_HOST:443 
    ServerAlias YOUR_PRROJECT_ALIAS:443 
    SSLEngine on

    SSLCertificateFile "C:/wamp/bin/apache/Apache2.2.21/conf/www.mydomain.com.cert"

    SSLCertificateKeyFile "C:/wamp/bin/apache/Apache2.2.21/conf/www.mydomain.com.key" 
</VirtualHost>       

Tuesday, 6 November 2012

Symfony propel file form widget editable

This is a simple editable file form widget:

If we have file_path field type varchar(255) in database, our widget will look like:

'file_path'        => new sfWidgetFormInputFileEditable(array('template' => '<div class="row file-editable-input">%input%</div><div class="row file-editable-remove"><ul class="inputs-list"><li><label>%delete%%delete_label%</label></li></ul></div><div class="row file-editable-img">%file%</div>',
        'file_src' =>  UPLOADS_DIR . $this->getObject()->getFilePath(),
        'is_image' => FALSE,
        'edit_mode' => TRUE,
        'delete_label' => __('Check this box if you want to remove current file'),
        'with_delete' => TRUE), array()),
And validator should look like:

'file_path' => new sfValidatorFile(array(
        'max_size' => Utils::getMaxUploadSize() * 1024 * 1024,
        'mime_types' => 'all_documents',
        'path' => UPLOADS_DIR,
        'required' => FALSE)),

And that's it. 'all_documents' is array of file extensions i creted in the validator file, along wit web_images and other. And off course your uploads dir must exist.

Monday, 5 November 2012

symfony admin generator examples from config:

I always loose much time looking for these simple generator.yml config settings:

With edit and new actions:


    config:
      actions:               ~
      fields:
        id:                  { label: "ID" }
        created_at:          { label: "Created At", date_format: "MM/dd/yyyy HH:mm:ss" }
      list:
        title:               Title
        display:             [id, word, created_at]
        max_per_page:        50
        sort:                [id, asc]
      filter:                ~
      form:                  ~
      edit:
        title:               Edit
      new:
        title:               New

Without new action, batch actions...:

    config:
      actions:               ~
      fields:
        id:                  { label: "ID" }
        created_at:          { label: "Created At", date_format: "MM/dd/yyyy HH:mm:ss" }
        
      list:
        title:               Title
        display:             [id, subject, description]
        max_per_page:        50
        sort:                [id, asc]
        actions:             []
        batch_actions:       []
        object_actions:
          _edit:             ~
      filter:                ~
      form:                  ~
      edit:
        title:               Edit
        actions:        
          _list:             ~
          _save:             ~
          _save_and_add:     ~
      new:
        title:               New

Symfony admin generator add custom criteria to filter

If you have in list field that doesn't exist as a database feild to the formFilter class you need to add your custom criteria for that field.
Note: function needs to be called addYourFieldNameColumnCriteria

Example: /lib/filter/User/UserFormFilterClass
public function addYourFilterColumnCriteria(Criteria $criteria, $field, $values)
  {
    $values = trim($values);
    if (!empty($values))
    {
      $criteria->add(YourPeer::FIELD_NAME, $values);
    }
  }


But sometimes $values returns an ampty array (I am not sure when), then you need to register you type of field and then to access it ina a different way:

public function addYOUR_FIELDColumnCriteria(Criteria $c, $field, $values)
  {
    $value = trim($values['text']);
    if (!empty($value))
    {
      // Your ciriteria
    }
  }
  public function getFields()
 {
  $fields = parent::getFields();
  $fields['YOUR_FIELD'] = 'Text';
  return $fields;
 }
Off course YourFilter, YourPeer, FIELD_NAME,YOUR_FIELD and field type you need to adjust to your needs.

Sunday, 28 August 2011

Apache xampp virtual hosts configuration on mac

After installing xampp on mac you need to change permission for /xamppfiles/etc/httpd.conf file. There is simple program for that, called BatChmod.

Next you need to enable it for user thsty you want:

Find:
User nobody
Group nogroup

Change it to:
User YOURUSERNAME
Group admin



If you projects are in another location you will need to change DocumentRoot in httpd.conf to you path, and also need to change line
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
to you path, and "Deny from all" to "Allow from all" to this directory


After that uncomment
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

Here is where you put your virtual hosts. 

It should look like :

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
  ServerName yourdomain.dev
  DocumentRoot "/Users/
username/projects/your_project"
  DirectoryIndex index.php
  <Directory "/Users/
username/projects/your_project">
    Options +Indexes FollowSymLinks +ExecCGI
    AllowOverride AuthConfig FileInfo
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

<VirtualHost 127.0.0.1>
  ServerName localhost
  DocumentRoot "/Users/username/projects/"
  DirectoryIndex index.php
  <Directory "/Users/
username/projects/">
    Options +Indexes FollowSymLinks +ExecCGI
    AllowOverride AuthConfig FileInfo
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>
 
Last thing, add yourdomain to hosts

Open the Terminal and type:
sudo pico /etc/hosts

Now enter your admin password. You'll get a little text editor in the console. Go to the last line and add this line:
127.0.0.1 yourdomain.dev with the correct name for every virtual host you would like to set up. When you're done, type control-o, then enter and then control-x in order to save and close.

Friday, 5 August 2011

simple ajax call

This is part for the view script:

function addAdditional(lnk) {
        jQuery.ajax({
                        type: "POST",
                        url: "<?php echo $this->url(array('controller' => 'content', 'action' => 'vote'), 'default', true); ?>",
                        data: jQuery('#star-form').serialize()+'&content_id=' + <?php echo $this->content_id ?>,
                        success: function(res)
                        {
                            r = jQuery.parseJSON(res);
                            if(r.status == 'success')
                            {
                                if(r.saved == 'success') {
                                    $("#vote-button").next().html('Uspesno ste glasali!');
                                } else {
                                    $("#vote-button").next().html('Niste glasali. Pokusajte ponovo!');
                                }

                            }
                            else
                            {
                                $("#vote-button").next().html('Niste glasali. Pokusajte ponovo!');
                            }
                        }
                    });
        return false;
    }

Here is the controller action

public function voteAction() {
        $result = array(
            "status" => "",
            "saved" => "",
        );

        if ($ok) {
            //do code
            $result = array(
                "status" => "success",
                "saved" => "success",
            );
        } else {
            $result = array(
                "status" => "success",
                "saved" => "error",
            );
        }

        die(json_encode($result));
    }

Thursday, 4 August 2011

Using selenium server with netbeans

Fisst of all you need to have php unit installed. PHPUnit should be installed using the PEAR INSTALLER. I didnt have go-pear.bat in my wamp 2.1, so i copied it from xamp server and ran "php -d phar.require_hash=0 PEAR/go-pear.phar" command, then you nedeed to upgrade pear using "pear install PEAR-1.9.3" command. Now install php Unit http://www.phpunit.de/manual/current/en/installation.html.

Zend send variable to a form

We create variable that we need in controller:

$this->view->random = date('YmdHis').rand(10000, 9999).rand(10000, 9999);


Then we pass it to a form call in controller:

$this->view->form = new Application_Form_ContentGame(array('random'=>$this->view->random));


And in a form, we get it with:

$random = $this->getAttrib('random');

Friday, 29 July 2011

Jquery add another form field

First we need div to clone with remove link:

<div id="floorForClone" style="display: none;">
<div id="floor-plan">
<input type="hidden" name="floor_plan_id[]" value="{$id}" />
<div id="floor-plan-info" class="fleft" style="width: 140px;">
<div class="fleft mt5 w100p ">
<label for="floor_plan_name">Name</label>
<div class="fleft pfid373">
<input id="floor_plan_name" name="floor_plan_name[]" value='{$floor_plan.floor_plan_name}' class="category-profile-form-textbox text" type="text" />
</div>
</div>
</div>
<div id="floor-plan-info" class="fleft" style="width: 110px;">
<div class="fleft mt5 w100p ">
<label for="floor_bedrooms">Bedrooms</label>

<div class="fleft pfid374">
<select name="floor_bedrooms[]">
<option label="1" value="179">Select</option>
<option label="1" value="273">1</option>
<option label="2" value="274">2</option>
</select>

</div>
</div>
</div>
<a onclick="removeAdditionalFloor(jQuery(this)); return false;" href="" class="add">Remove</a>
</div>


Then there are script functions to add remove fields:

function addAdditionalFloor(lnk) {
lnk.before('<div id="floor-plan">' + jQuery('#floorForClone').html() + '</div>');
return false;
}
function removeAdditionalFloor(lnk) {
lnk.closest("#floor-plan").remove();;
return false;
}


And last add the add another link where do we need it:

<a onclick="addAdditionalFloor(jQuery(this)); return false;" href="" class="add">Add floor plan</a>