Tuesday, 29 August 2017

96.How to add backend sub menus in social engine?

eg:
$sql['1.1.4.45']    = "INSERT INTO `engine4_core_menuitems` (`id`, `name`, `module`, `label`, `plugin`, `params`, `menu`, `submenu`, `enabled`, `custom`, `order`) VALUES (NULL, 'core_admin_main_manage_advertisement', 'user', 'Manage Advertisement', '', '{\"route\":\"admin_default\",\"module\":\"user\",
                   \"controller\":\"manage\",\"action\":\"advertisements\"}', 'core_admin_main_manage', NULL, '1', '0', '999');";

user/views/scripts/admin-manage/advertisements.tpl
public function advertisementsAction(){

}

95.php file deletion(image deletion)

unlink(path);
 unlink($advertisement->image);

94.social engine smooth box deletion

user/views/scripts/admin-manage/tipdelete.tpl  
<?php echo $this->form->setAttrib('class', 'global_form_popup')->render($this) ?>
 
listpage
 <td> <a class='smoothbox'  href='<?php echo $this->url(array('action' => 'tipdelete', 'id' => $item['id']));?>'>
                  <?php echo $this->translate("delete") ?>
                </a></td>
   controller
 
         public function tipdeleteAction()
    {
    $id = $this->_getParam('id', null);
    $this->view->form = $form = new User_Form_Admin_Manage_Deleteitem();
    if( $this->getRequest()->isPost() ) {
   
      try {
       
         Engine_Db_Table::getDefaultAdapter()->delete('engine4_tips', array('id = ?'=>$id) );
       
     
      } catch( Exception $e ) {
        throw $e;
      }
     
      return $this->_forward('success', 'utility', 'core', array(
        'smoothboxClose' => true,
        'parentRefresh' => true,
        'format'=> 'smoothbox',
        'messages' => array('Tip has been successfully deleted.')
      ));
     
     }

    }    

93.image uplaod

tpl script

<button class="upload_file_btn">Add new Advertisement</button>



<div id="light1" class="white_content">
<div class="popup_title">Upload new file</div><div class="div_attachment_cancel"><img src="/application/modules/User/externals/images/GREYcancel.png"></div>

<div class="error_msg" style="color:red"></div>
            <form method="POST" enctype="multipart/form-data" action="<?php echo $this->baseUrl().'/user/admin-manage/saveadvertisementphoto' ?>" class="photo_upload_frm">
                <div class="folder_name_input">
                    <div>Title</div>
                    <div style="margin-bottom: 12px;margin-top: 2px;">
                    <input type="text" class="upload_image_title" name="upload_image_title" maxlength="30">
                    </div>
                    <input type="file" class="upload_image" name="upload_image">
                    <div>only JPG, JPEG, and PNG  files are allowed.</div>
                    <div class="confirm_btns" style="text-align: left;">
                    <input type="submit" value="Save" class="image_upload_submit_btn" style="width: 134px;">
                   </div>
                   </div>
            </form>
<div class="loader" style="display:none;"></div>
 </div>
<div id="fade" class="black_overlay"></div>



jQuery('body').on('click', '.upload_file_btn', function(event){
document.getElementById('light1').style.display='block';
document.getElementById('fade').style.display='block';
});


jQuery('body').on('click', '.div_attachment_cancel', function(event){
   jQuery('#light1').css('display','none');
jQuery('#fade').css('display','none');
});

jQuery(".photo_upload_frm").submit(function (event) {
 event.preventDefault();

 jQuery('.image_upload_submit_btn').prop('disabled', true);
 jQuery('.image_upload_submit_btn').css('display', 'none');
 jQuery('.loader').css('display', 'block');

 var upload_image_title = jQuery('.upload_image_title').val();
 var photopath = jQuery('.upload_image').val();
 var ext = jQuery('.upload_image').val().split('.').pop().toLowerCase();

 if(upload_image_title !='' && photopath != ''){

 if(ext != "jpg" && ext != "JPG" && ext != "png" && ext != "jpeg" && ext != "JPEG" &&  ext != "PNG") {
jQuery('.error_msg').text('');
jQuery('.error_msg').text('Sorry, only JPG, JPEG, & PNG  files are allowed');
jQuery('.image_upload_submit_btn').prop('disabled', false);
jQuery('.image_upload_submit_btn').css('display', 'block');
        jQuery('.loader').css('display', 'none');

 }
 else{

 var url =  '<?php echo $this->baseUrl().'/user/admin-manage/saveadvertisementphoto' ?>';

 jQuery.ajax({
url: url,
type: "POST",
data:  new FormData(this),
contentType: false,
cache: false,
processData:false,
dataType: 'json',
success: function(data){
var oData             = new Object();
var upload_image_title= oData.upload_image_title=upload_image_title;
jQuery('#light1').css('display','none');
jQuery('#fade').css('display','none');
         location.reload();

},

error: function(){}      
});

}

  }
 
  else{
 jQuery('.error_msg').text('');
 jQuery('.error_msg').text('Please fill all fields');
 jQuery('.image_upload_submit_btn').prop('disabled', false);
 jQuery('.image_upload_submit_btn').css('display', 'block');
      jQuery('.loader').css('display', 'none');
  }


});


/*contoller*/

 public function saveadvertisementphotoAction(){
        $viewer     = Engine_Api::_()->user()->getViewer();
        date_default_timezone_set($viewer->timezone);
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout();
        if( $this->getRequest()->isPost()){
            $aData           = $this->_request->getPost();
            $photo_title     = $aData['upload_image_title'];

            $random_filename = $this->random_string(8);
            $dir             = dirname($_SERVER['SCRIPT_FILENAME']).'/public/images/advertisement/';
                            if(!is_dir($dir)){
                                mkdir($dir,0777,true);
                            }
            $target_file     = $dir .'/'. basename($_FILES["upload_image"]["name"]);
           
            $imageFileType   = pathinfo($target_file,PATHINFO_EXTENSION);
            $random_filename =  $random_filename.'.'.$imageFileType;

            if($imageFileType != "JPG" && $imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" &&  $imageFileType != "JPEG" &&  $imageFileType != "PNG") {

                $aResult['msg']    = "Sorry, only JPG, JPEG, & PNG  files are allowed.";
                $aResult['status'] = false;
            }
            else{

                $target_file   = $dir .'/'. $random_filename;
                if (move_uploaded_file($_FILES["upload_image"]["tmp_name"], $target_file)) {
                    $AdvertisementTable     = Engine_Api::_()->getDbtable('advertisement', 'user');
                    $AdvertisementTableId   = $AdvertisementTable->insert(array(
                      'user_id'         => $viewer->getIdentity(),
                      'title'     => $photo_title,
                      'image'            => 'public/images/advertisement/'.$random_filename,
                      'created_at'      => date('Y-m-d H:i:s'),
                      'updated_at'      => date('Y-m-d H:i:s'),

                    ));


           $aResult['status']                      = true;
           }
           else {
                 $aResult['status'] = false;
                }
            }
            echo json_encode($aResult);
         }

       
     }

92.How to hide widget in social engine?

write this in the wiget controller

 return $this->setNoRender();

91.How to access social engine default table?

$settings = Engine_Api::_()->getApi('settings', 'core');
<?php echo '$' . $settings->user_videoPrice ; ?>

90.social engine model

<?php

class User_Model_DbTable_Userpackages extends Engine_Db_Table
{
  protected $_name = 'user_packages'; //whrer db name is engine4_user_packages

}


in controller(user/model/db table)

$userPackagesTable             =  Engine_Api::_()->getDbtable('Userpackages', 'user');

89.How to select date from datetime column?

WHERE datetime LIKE '2009-10-20%'
WHERE DATE(datetime) = '2009-10-20'

Monday, 21 August 2017

88.to reduce image size online

http://compressjpeg.com/
http://www.simpleimageresizer.com/upload#.WZZrp9_I48o

87. div align middle

<div id="outer">
  <div id="inner">Foo foo</div>
</div>

#inner {
  width: 50%;
  margin: 0 auto;
}


other method

<div style="text-align:center"></div>

86.center align button in the middle


<div class="wrapper">
    <button class="button">Hello</button>
</div>

.wrapper {
    text-align: center;
}

.button {
    position: absolute;
    top: 50%;
}

85. css scroller

#preferenceModal .modal-body{
    overflow-y: auto;
    max-height: 445px;
}

84.git comments

git status          -to check the status of changed files
git add filepath    -inorder to add file to git
git rm              -inorder to remove file from git
git commit -m ""    -this command prepares added files to be pushed
git pull origin ....
git push origin ....
git diff            - Show changes between commits

83.string to integer conversion

(int)$matching_array['price_to']
(int)$price_to

82.new page in social engine


/*controller*/

     public function workingAction(){
        $this->_helper->viewRenderer->setNoRender(false);
        $this->_helper->layout->setLayout('landing_page');
     
}

/* manifest */

'working' => array(
      'route' => '/working',
      'defaults' => array(
        'module' => 'user',
        'controller' => 'index',
        'action' => 'working'
      )
    ),
/*view section(tpl page) */
 
    working.tpl
    user/views/scripts/index/working.tpl

81.social engine data base details

application/settings/database.php

80.social engine where clause array with IN operator

 $resourceids=array();
   foreach($secondlevelData as $row){
array_push($resourceids,$row->resource_id);
   }

 
    $thirdlevel_friends_select = $membershipTable->select()
                      ->setIntegrityCheck(false)
                      ->from(array('membership'=>'engine4_user_membership',))
                      ->where('membership.resource_id IN (?)',$resourceids )
                               ->where('membership.active = ?',1 )
                      ->group('membership.user_id');