1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

user_ajax

Discussion in 'Community' started by tanya2015, Oct 8, 2019.

  1. tanya2015

    tanya2015 Member

    Level: Community
    hello, can i use in user ajax.php several function if yes how to call them
    class UserAjax
    {
    public function userExists()
    {}}

    class UserAjax
    {
    public function userExists1()
    {}}

    or

    class UserAjax
    {
    public function userExists()
    {}
    public function userExists1()
    {}
    }

    thank you!
     
  2. startpoint

    startpoint Active Member

    Level: Community
    You must use the second variant.
     
  3. tanya2015

    tanya2015 Member

    Level: Community
    hello I tryed second variant but first function getStartTimes() stop to work. if I delete second function getfioorg() everything is ok again...
    Code (Text):
    <?php
    /**
    * User ajax example
    *
    * @package     Joomla
    * @subpackage  Fabrik
    * @copyright   Copyright (C) 2005-2015 fabrikar.com - All rights reserved.
    * @license     GNU/GPL http://www.gnu.org/copyleft/gpl.html
    */

    // No direct access
    defined('_JEXEC') or die('Restricted access');

    /**
    * Define your userAjax class
    *
    * @package     Joomla
    * @subpackage  Fabrik
    * @since       3.0
    */
    class UserAjax
    {
        /**
        * This is the method that is run. You should echo out the result you which to return to the browser
        *
        * @return  void
        */
        public function getStartTimes()
        { $app = JFactory::getApplication();
                $input = $app->input;
                $hall = $input->get('hall', '');
                $vksdate = $input->get('datavks', '');
                $ind = $input->get('ind', '');
                switch ($hall) {
        case '1':
             $hall1 = 'hall1';
            break;
        case '2':
            $hall1 = 'hall2';
            break;
        }
                    /*Time array hall works from 8 a.m.to 19 p.m.*/
            $starttime = 8;
            $endtime   = 19;
            $stepmin   = 30;
            $lower     = $starttime * 3600;
            $upper     = $endtime * 3600;
            $step      = $stepmin * 60;
            $times     = [];
            foreach (range($lower, $upper, $step) as $increment)
            {
                $increment = gmdate('H:i', $increment);
                list($hour, $minutes) = explode(':', $increment);
                $date    = new DateTime($hour . ':' . $minutes);
                $times[] = (string) $increment;
            }
            /*Date transformation to Y-m-d format */
            $vksdate1 = new DateTime($vksdate);
            $vksdate_fin = $vksdate1->format('Y-m-d');
            /*Count times for date and hall user choose in the database */
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select('COUNT(*)');
            $query->from($db->quoteName('vks'));
            $query->where($db->quoteName('datavks')." = ".$db->quote($vksdate_fin).' AND '.$db->quoteName('hall')." = ".$db->quote($hall1).' AND '.$db->quoteName('status')." = ".$db->quote('ok'));
            $db->setQuery($query);
            $count = $db->loadResult();
           /*if where is no date */
            if ($count == 0)
                {$optionString = '<option value="0">Choose time</option>';
                /* Convert to an array of times */
                foreach ($times as $key => $value)
                  {
                    $key = $key + 1;
                    $id = $key;
                    $optionString .= '<option value="' . $value . '">' . $value . '</option>';
                    }
                echo json_encode($optionString);}
            else
            {$query = $db->getQuery(true);
            $query->select($db->quoteName(array('start','end')))->from($db->quoteName('vks'))->where($db->quoteName('datavks')." = ".$db->quote($vksdate_fin).' AND '.$db->quoteName('hall')." = ".$db->quote($hall1).' AND '.$db->quoteName('status')." = ".$db->quote('ok'));
            $db->setQuery($query);
            $column= $db->loadAssocList();
            $i=0;
            foreach ($column as $raw)
    { $key1 = array_search($raw['start'],$times);
      $key2 = array_search($raw['end'],$times);
      while ($key1 <= $key2)
    {
    $times2[$i] = $times[$key1];
    $key1++;
    $i++;}
    }
    $result = array_unique($times2);
    sort ($result,SORT_STRING);
    $times1 = array_diff($times,$result);
    if (!empty($times1))
    { $optionString = '<option value="0">Choose time</option>';
            /* Convert to an array of times */
            foreach ($times1 as $value)
                  { $optionString .= '<option value="' . $value . '">' . $value . '</option>';
                    }}
                    else
                    { $optionString = '<option value="0">choose other hall!</option>';}
    echo json_encode($optionString);
                }
            }
            public function getfioorg()
            {
                $app = JFactory::getApplication();
                $input = $app->input;
                $org = $input->get('org', '');


    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query->select($db->quoteName(array('fio','phone', 'email')))
    ->from($db->quoteName('orgcontact'))
    ->where($db->quoteName('org1'));
            $db->setQuery($query);
            $list= $db->loadRowList();
            echo json_encode($list;}
        }
    }
           
     
  4. lcollong

    lcollong FabriKant d'applications web

    Level: Community
    you have a mismatch in your parenthesis. It's easy to verify your code using a tool such as https://phpcodechecker.com/
    just copy paste your code in their windows and run the check. You will see the problem and understand how to correct it.
     
  5. startpoint

    startpoint Active Member

    Level: Community
    Change this part:
    PHP:
        public function getfioorg()
        {
            $app = JFactory::getApplication();
            $input = $app->input;
            $org = $input->get('org', '');

            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select($db->quoteName(array('fio','phone', 'email')))
            ->from($db->quoteName('orgcontact'))
            ->where($db->quoteName('org1'));
            $db->setQuery($query);
            $list= $db->loadRowList();
            echo json_encode($list);
        }
     

Share This Page