Pages

Friday, May 10, 2013

Upload Files to Amazon S3(Simple Storage) using PHP

Recently I was working on a project which required to upload files on Amazon Simple storage service which is S3

The 2 tutorials which worked perfectly for me are mentioned in links as follows

http://www.9lessons.info/2012/08/upload-files-to-amazon-s3-php.html

http://net.tutsplus.com/tutorials/php/how-to-use-amazon-s3-php-to-dynamically-store-and-manage-files-with-ease/


The latest SDK has somefor PHP 2 has some limitations I will point further...

Monday, May 6, 2013

Social Engine 4-Get values from a table

//gets a table called engine4_authorization_permissions

$permissionTable=Engine_Api_()->getDbTable('permissions','authorization');

$permissionSelect=$permissionTable->select()->where('level_id'=?,$userlevel)->where('type'=>'usercommit');

$fetchdata=$permissionTable->fetchrow($permissionSelect);

$fetchdatas=$permissionTable->fetchrows($permissionSelect);
//To get attribute from row

echo $fetchdata->attribute_name

foreach($fetchdatas as $fetchdata)
{
     echo $fetchdata->attribute_name;
}

Social Engine 4-Finding name of widget and Calling/Running a widget by custom code via name

First things first

1. In the backend select layout=>layout editor

Select the page on which your widget is currently placed

Or

If you know the name of your widget find it in concerned module on right hand side

You can use my technique for the same

For example we are looking for the widget "Statistics" Find the plugin text in admin using "find text tool(Ctrl+F)" of your browser and search for the same under "Available Blocks"

2. Once yo know the widget and its module for example for above mentioned  widget we find it under "Core Module"

Moving Back to code

under

/application/modules/core/settings (considering our example for Core Module and Statistics Widget)

open file content.php

find the array of widget Statistics there like


 array(  
 'title'=>'statistics',  
 'description'=>'',  
 'category'=>'core',  
 'type'=>'widget',  
 'name'=>'core.statistics',  
 'defaultParams'=>array(  
 'title'=>'Statistics'  
 ),  
 'requirements'=>array(  
 'no-subject',  
 ),  
 );  

Now we need the name attribute to call our widget in code as


 <?php  
 echo $this->content()->renderWidget('core.statistics';)  
 ?>  

other examples can be

content()->renderWidget('core.ad-campaign') ?>

content()->renderWidget('user.home-photo') ?>

Social Engine 4-Fetching and displaying a menu from backend

1. Create a menu from admin backend by going to Layout->Menu Editor from menu

2. Now go to database and in table "engine4_core_menus" find the entry for your menu and give the same name under "name" field(if already not there)

3. Now in controller to assign the menu to a view variable use

 $this->view->navigation=Engine_Api::_()->getApi('menus','core')->getNavigation('credit_main');  

where 'credit_main' is the 'name' of your menu from table "engine4_core_menus"

To render menu in view use


 echo $this->navigation()->menu()->setContainer($this->navigation)->render();  



Sunday, May 5, 2013

Social Engine 4-Managing a page from Admin Panel or only by widgets

In Social Engine 4 many a times we feel the need to manage our page only from backend i.e. from the widgets we have created only

Here are the steps to perform the same

1. Disable layout from controller's action function you have to create an action for the newly added page see second step on how to add actions for concerned pages in respective controllers

$this->helper->content->setNoRender()->setEnabled();

2. In "Engine4_core_pages" find the corresponding entry to your newly created page(generally this will be the last entery of table if ordered by id).

and set its name as

"credit_index_manage" or "credit_index_network"

Here
"credit" is your module name
"index" is the controller(IndexController) of module
and
"manage/network" are the action names under the controller

that's it now you can manage your page from widgets in backend no need to create a view.....


Social Engine 4 - Adding a Menu Item to a Menu Specified under Module(create a menu plugin)

First things first

1. Create/Add a menu item to respective menu from admin

Layout=>Menu Editor

2. Now in table "engine4_core_menuitems" set the following attributes

name="credit_main_network" //we will use this later in code avoid spaces
module=Credit(your module name)
label=Network(label of your menu item)
plugin=Credit_Plugin_Menus
{"route" : "credit_general","action":network}


3. Next route will be defined in your "modulename/settings/manifest.php"

for example

'credit_general'=>array(
'route'=>'credits/:action/*',
'defaults'=>array(
      'module'=>'credit',
      'controller'=>'index',
      'action'=>'index'
      ),
'menu'=>'credit_main' //(from table engine4_core_menus)
'submenu'=> if any
'enabled'=>1,
'order'=>3
)

4. Now in plugin under your module create a file "Menus.php"(if not there)

and template it as follows

for example for me file was /module/credit/Plugin/menus.php

class Credit_Plugin_Menus
{
     // see name of menu from table we have used after underscore

    public function onMenuInitialize_CreditMainNetwork($row)
   {
           If(!Engine_Api::_()->user()->getViewers()->getIdentity())
           {
               return false;
           }
           return true;
   }
}

That's it you have successfully configured menu for your Module in Social Engine 4

Social Engine 4-Create a module

In Admin Panel

Manage=>Packages & Plugins=>Developer SDK=>Create a Package


This will give you a complete zip package and required directory sturcture for module

Friday, May 3, 2013

Magento-Get information of Items in Cart

Magento-Get Information of Items in Cart

$items=Mage::getSingleton('Checkout/Session')->getQuote()->getAllItems();

foreach($items as $item)
{
    echo $item->getName();
                      ->getQty();
                      ->getPrice();
                      ->getSku();
                      ->getProductid()
}


Magento-get Cart Count

Mage::('checkout/cart')->getItemsCount();

Social Engine 4-Get avtar of user

$user_id=Engine_Api::()_->user->getviewer->getIdentity();

$userinfo=Engine_Api::_()->user()->getUser($user_id);

$photo_id=$user_info['photo_id'];


//Fetches table Engine4_storage_files

$filesTable=Engine_APi::_()->getDbtable('files','storage');

$adapter=Engine_Db_Table::getDefaultAdapter();

$filesTableName=$filesTable->info('name');

$query=Engine_Db_Table::getDefaultAdapter()->select("storage_path")->from($statsTableName)->where("field_id=?",$photo_id)->limit(1);

$result=$query->query()->fetch();

$result['storage_path'] //has the path to your photo