Results 1 to 5 of 5

Thread: convert funtion to logic hooks

  1. #1
    hoangbao is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Saigon - Vietnam
    Posts
    76

    Thumbs down convert funtion to logic hooks

    Hi all,

    Please help me put this funtion in logic hooks syntax
    PHP Code:
    <?php

    function diemtrungbinh($mg1,$mg2,$mg3,$test_15p1,$test_15p2,$test_15p3,$test_15p4,$test_45p1,$test_45p2,$test_45p3,$test_45p4,$test_45p5,$thi) {

        
    $mang_diem = array($mg1,$mg2,$mg3,$test_15p1,$test_15p2,$test_15p3,$test_15p4,$test_45p1,$test_45p2,$test_45p3,$test_45p4,$test_45p5,$thi);

        
    $heso_chia 1*1*2*3*1;

        
    $tong_diem = ($mg1+$mg2+$mg3)+ ($test_15p1+$test_15p2+$test_15p3+$test_15p4) + 2*($test_45p1+$test_45p2+$test_45p3+$test_45p4+$test_45p5) + 3*$thi;

        

        for (
    $i=0;$i<7;$i++) {

            if (!
    is_int($mang_diem[$i]) && $mang_diem[$i] == null) {

                
    $heso_chia -= 1;

            }

        }

        for (
    $i=7;$i<12;$i++) {

            if (!
    is_int($mang_diem[$i]) && $mang_diem[$i] == null) {

                
    $heso_chia -= 2;

            }

        }

        if (!
    is_int($mang_diem[12]) && $mang_diem[12] == null) {

            
    $heso_chia -= 3;

        }

        
    $heso_chia;

        
    $trungbinh round($tong_diem/$heso_chia,2);

        return 
    $trungbinh;

    }

    ?>
    and then save $trungbinh to trungbinh customfield.


    thanks
    hoangbao
    Last edited by hoangbao; 2010-01-04 at 02:29 AM.

  2. #2
    akkimca's Avatar
    akkimca is offline Sugar Community Member
    Join Date
    Dec 2008
    Posts
    270

    Thumbs up Re: convert funtion to logic hooks

    Hi,
    just use before or after logic hook and just define ur function in it as normal way in class and call it...

    u can find logic hook information in sugar forums

    all d best
    Regards
    ==========================
    akkimca
    Work as Sugarcrm Freelancer
    Feel free to Find me in skype. Its my pleasure to talk with you.
    ID: akshay.biztech

  3. #3
    hoangbao is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Saigon - Vietnam
    Posts
    76

    Default Re: convert funtion to logic hooks

    Thank you very much

    My code but it doesn't work

    PHP Code:
    <?php

    class average {
    funtion average (&$bean$event$arguments) {

    function 
    diemtrungbinh($mg1,$mg2,$mg3,$test_15p1,$test_15p2 ,$test_15p3,$test_15p4,$test_45p1,$test_45p2,$test _45p3,$test_45p4,$test_45p5,$thi) {

    $mang_diem = array($mg1,$mg2,$mg3,$test_15p1,$test_15p2,$test_1 5p3,$test_15p4,$test_45p1,$test_45p2,$test_45p3,$t est_45p4,$test_45p5,$thi);

    $heso_chia 1*1*2*3*1;

    $tong_diem = ($mg1+$mg2+$mg3)+ ($test_15p1+$test_15p2+$test_15p3+$test_15p4) + 2*($test_45p1+$test_45p2+$test_45p3+$test_45p4+$te st_45p5) + 3*$thi;



    for (
    $i=0;$i<7;$i++) {

    if (!
    is_int($mang_diem[$i]) && $mang_diem[$i] == null) {

    $heso_chia -= 1;

    }

    }

    for (
    $i=7;$i<12;$i++) {

    if (!
    is_int($mang_diem[$i]) && $mang_diem[$i] == null) {

    $heso_chia -= 2;

    }

    }

    if (!
    is_int($mang_diem[12]) && $mang_diem[12] == null) {

    $heso_chia -= 3;

    }

    $heso_chia;

    $trungbinh round($tong_diem/$heso_chia,2);

    return 
    $trungbinh;
    $bean->trungbinh $trungbinh

    }
    }

    ?>
    Last edited by hoangbao; 2010-01-04 at 02:28 AM.

  4. #4
    JVWay is offline Sugar Community Member
    Join Date
    Sep 2007
    Location
    Corvallis, Oregon
    Posts
    452

    Default Re: convert funtion to logic hooks

    well, you did leave out the 'c' in the keyword function on the third line.

    Other than that you'd have to give us more information than 'it doesn't work'

    Setup some debug lines and check them out. What systems are you using to run this? If it's Linux I've posted some details on how to use error_log to output your code issues to a terminal window.
    Jerry Way
    Business Process Administrator

    Sugar 6.1.4 Professional
    (Testing 6.1.2)
    LAMP on Centos 5
    PHP 5
    MySQL 5
    Apache 2.2

  5. #5
    hoangbao is offline Sugar Community Member
    Join Date
    Aug 2007
    Location
    Saigon - Vietnam
    Posts
    76

    Default Re: convert funtion to logic hooks

    My system is linux, and don't have any error messages, but $trungbinh didn't save in trungbinh custom field
    my file /custom/modules/SM_Grade/Average.php

    PHP Code:
    <?php

    class average {
    function 
    add_average (&$bean$event$arguments) {

    function 
    diemtrungbinh($mg1,$mg2,$mg3,$test_15p1,$test_15p2 ,$test_15p3,$test_15p4,$test_45p1,$test_45p2,$test _45p3,$test_45p4,$test_45p5,$thi) {

    $mang_diem = array($mg1,$mg2,$mg3,$test_15p1,$test_15p2,$test_1 5p3,$test_15p4,$test_45p1,$test_45p2,$test_45p3,$t est_45p4,$test_45p5,$thi);

    $heso_chia 1*1*2*3*1;

    $tong_diem = ($mg1+$mg2+$mg3)+ ($test_15p1+$test_15p2+$test_15p3+$test_15p4) + 2*($test_45p1+$test_45p2+$test_45p3+$test_45p4+$te st_45p5) + 3*$thi;

    for (
    $i=0;$i<7;$i++) {

    if (!
    is_int($mang_diem[$i]) && $mang_diem[$i] == null) {

    $heso_chia -= 1;

    }
    }

    for (
    $i=7;$i<12;$i++) {

    if (!
    is_int($mang_diem[$i]) && $mang_diem[$i] == null) {

    $heso_chia -= 2;

    }
    }

    if (!
    is_int($mang_diem[12]) && $mang_diem[12] == null) {

    $heso_chia -= 3;

    }

    $heso_chia;

    $trungbinh round($tong_diem/$heso_chia,2);

    return 
    $trungbinh;
    $bean->trungbinh $trungbinh;
    }
    }
    }

    ?>
    and /custom/modules/SM_Grade/logic_hooks.php

    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die(('Not A Valid Entry Point'));
    /*
    Descrption: Creates the Array for logic hooks to calculate average
    * */
    $hook_array = Array();
    // position, file, function
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1'before_save''custom/modules/SM_Grade/Average.php''average''add_average');

    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. logic hooks and sql
    By mahmoud07 in forum Developer Help
    Replies: 3
    Last Post: 2010-02-25, 04:29 PM
  2. Logic Hooks
    By Rajesh Patel in forum Help
    Replies: 6
    Last Post: 2009-11-18, 05:57 PM
  3. Logic Hooks
    By kalaisugar in forum Developer Help
    Replies: 7
    Last Post: 2009-05-08, 07:55 PM
  4. Logic Hooks
    By highres in forum Italiano
    Replies: 3
    Last Post: 2009-02-01, 05:10 PM
  5. Logic Hooks
    By Delos in forum Developer Help
    Replies: 0
    Last Post: 2008-10-17, 01:01 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •