Example #1
0
 function __construct($bootstrap)
 {
     parent::__construct();
     // autoload ALL packages if no custom bootstrap
     if (count($bootstrap) == 0) {
         foreach (glob(dirname(__FILE__) . '/*') as $dir) {
             $name = _end(array_filter(preg_split('@[/\\\\]@', $dir)));
             if (is_dir($dir) && ctype_alpha(substr($name, 0, 1))) {
                 $rule = new T_Find_ClassInDir($dir, 'T_');
                 $this->addRule($rule);
             }
         }
     } else {
         foreach ($bootstrap as $dir) {
             if (is_dir($dir)) {
                 $rule = new T_Find_ClassInDir($dir, 'T_');
                 $this->addRule($rule);
             }
         }
         // make sure unit package is autoloaded
         $this->addRule(new T_Find_ClassInDir(T_ROOT_DIR . 'unit', 'T_'));
     }
     // setup error handling
     $this->like('T_Exception_Handler')->append(new T_Exception_Handler_Terminal(E_ALL | E_STRICT));
 }
Example #2
0
 function testThatFormHasCorrectAction()
 {
     $form = $this->getTestForm();
     $xml = $this->getXmlFrom($form);
     $forward = $form->getForward();
     $mode = strpos(_end($forward->getPath()), '.') === false ? T_Url::AS_DIR : null;
     $action = $forward->getUrl(null, $mode);
     $this->assertEquals(1, count($comment = $xml->xpath('//form[@action="' . $action . '"]')));
 }
Example #3
0
 function __construct()
 {
     parent::__construct();
     // all classes required (reflection is needed)
     foreach (glob(dirname(__FILE__) . '/../*') as $dir) {
         $name = _end(array_filter(preg_split('@[/\\\\]@', $dir)));
         if (is_dir($dir) && ctype_alpha(substr($name, 0, 1))) {
             $rule = new T_Find_ClassInDir($dir, 'T_');
             $this->addRule($rule);
         }
     }
     // setup error handling
     $this->like('T_Exception_Handler')->append(new T_Exception_Handler_Terminal(E_ALL | E_STRICT));
 }
Example #4
0
 function testGetVersionDependsOnLastModificationTimeOfFile()
 {
     $names = array('test1', 'test2');
     $ext = '.js';
     foreach ($names as $fn) {
         $p = T_CACHE_DIR . $fn . $ext;
         $expect[] = $p;
         touch($p);
     }
     $files = new T_Code_Files(T_CACHE_DIR, $names, $ext);
     $version = $files->getVersion();
     sleep(1);
     touch(_end($expect));
     clearstatcache();
     $this->assertNotEquals($files->getVersion(), $version);
     foreach ($expect as $p) {
         @unlink($p);
     }
 }
Example #5
0
function zayav_spisok($v)
{
    $filter = zayavFilter($v);
    $filter = _filterJs('ZAYAV', $filter);
    define('ZAYAV_PAGE1', $filter['page'] == 1);
    $page = $filter['page'];
    $limit = $filter['limit'];
    $cond = "`ws_id`=" . WS_ID . " AND !`deleted`";
    $nomer = 0;
    if ($filter['find']) {
        $engRus = _engRusChar($filter['find']);
        $cond .= " AND (`find` LIKE '%" . $filter['find'] . "%'" . ($engRus ? " OR `find` LIKE '%" . $engRus . "%'" : '') . ")";
        $reg = '/(' . $filter['find'] . ')/i';
        if ($engRus) {
            $regEngRus = '/(' . $engRus . ')/i';
        }
        if (ZAYAV_PAGE1 && _num($filter['find'])) {
            $nomer = intval($filter['find']);
        }
    } else {
        if ($filter['client_id']) {
            $cond .= " AND `client_id`=" . $filter['client_id'];
        }
        if ($filter['status']) {
            $cond .= " AND `status`=" . $filter['status'];
        }
    }
    $sql = "SELECT COUNT(*) FROM `zayav` WHERE " . $cond;
    $all = query_value($sql);
    $zayav = array();
    if ($nomer) {
        $sql = "SELECT * FROM `zayav` WHERE `ws_id`=" . WS_ID . " AND `nomer`=" . $nomer;
        if ($r = query_assoc($sql)) {
            $all++;
            $limit--;
            $r['nomer_find'] = 1;
            $zayav[$r['id']] = $r;
        }
    }
    if (!$all) {
        return array('all' => 0, 'result' => 'Заявок не найдено' . $filter['clear'], 'spisok' => $filter['js'] . '<div class="_empty">Заявок не найдено</div>', 'filter' => $filter);
    }
    $send = array('all' => $all, 'result' => 'Показан' . _end($all, 'а', 'о') . ' ' . $all . ' заяв' . _end($all, 'ка', 'ки', 'ок') . $filter['clear'], 'spisok' => $filter['js'], 'filter' => $filter);
    $sql = "SELECT\n\t            *,\n\t            '' `note`\n\t\t\tFROM `zayav`\n\t\t\tWHERE " . $cond . "\n\t\t\tORDER BY `" . ($filter['sort'] == 2 ? 'status_dtime' : 'dtime_add') . "` " . ($filter['desc'] ? 'ASC' : 'DESC') . "\n\t\t\tLIMIT " . _startLimit($filter);
    $q = query($sql);
    while ($r = mysql_fetch_assoc($q)) {
        if ($nomer == $r['nomer']) {
            continue;
        }
        $zayav[$r['id']] = $r;
    }
    if (!$filter['client_id']) {
        $zayav = _clientValToList($zayav);
    }
    //Заметки
    $sql = "SELECT\n\t\t\t\t`table_id`,\n\t\t\t\t`txt`\n\t\t\tFROM `vk_comment`\n\t\t\tWHERE `table_name`='zayav'\n\t\t\t  AND `table_id` IN (" . implode(',', array_keys($zayav)) . ")\n\t\t\t  AND `status`\n\t\t\tORDER BY `id` ASC";
    $q = query($sql);
    while ($r = mysql_fetch_assoc($q)) {
        $zayav[$r['table_id']]['note'] = $r['txt'];
    }
    foreach ($zayav as $id => $r) {
        $diff = round($r['accrual_sum'] - $r['income_sum'], 2);
        $send['spisok'] .= '<div class="zayav_unit" id="u' . $id . '"' . _zayavStatus($r['status'], 'bg') . '" val="' . $id . '">' . '<h2' . (isset($r['nomer_find']) ? ' class="finded"' : '') . '>#' . $r['nomer'] . '</h2>' . '<a class="name">' . $r['name'] . '</a>' . '<table class="utab">' . (!$filter['client_id'] ? '<tr><td class="label">Клиент:<td>' . $r['client_go'] : '') . '<tr><td class="label">Дата подачи:' . '<td>' . FullData($r['dtime_add'], 1) . ($r['status'] == 2 ? '<b class="date-ready' . _tooltip('Дата выполнения', -47) . FullData($r['status_dtime'], 1, 1) . '</b>' : '') . (round($r['accrual_sum'], 2) || round($r['income_sum'], 2) ? '<div class="balans' . ($diff ? ' diff' : '') . '">' . '<span class="acc' . _tooltip('Начислено', -39) . round($r['accrual_sum'], 2) . '</span>/' . '<span class="opl' . _tooltip($diff ? ($diff > 0 ? 'Недо' : 'Пере') . 'плата ' . abs($diff) . ' руб.' : 'Оплачено', -17, 'l') . round($r['income_sum'], 2) . '</span>' . '</div>' : '') . '</table>' . '<div class="note">' . @$r['note'] . '</div>' . '</div>';
    }
    $send['spisok'] .= _next($filter + array('type' => 2, 'all' => $all));
    return $send;
}
Example #6
0
 /**
  * Visit a form.
  *
  * @param T_Form_Container $node
  */
 function visitFormContainer(T_Form_Container $node)
 {
     $forward = $node->getForward();
     $mode = strpos(_end($forward->getPath()), '.') === false ? T_Url::AS_DIR : null;
     $action = $this->escape($forward->getUrl(null, $mode));
     $attributes = $node->getAllAttributes();
     $attributes += array('action' => $action, 'id' => $this->getNodeId($node), 'accept-charset' => $node->getCharset(), 'enctype' => $node->getMimeString(), 'method' => $node->getMethod());
     // <form>
     $xhtml = $this->indent . '<form ';
     foreach ($attributes as $key => $value) {
         $xhtml .= $key . '="' . $value . '"' . EOL . $this->indent . '       ';
     }
     $xhtml = rtrim($xhtml) . ' >' . EOL;
     $this->addXhtml($xhtml);
     // <fieldset class="submit">
     $this->changeIndent(1);
     $xhtml = $this->indent . '<fieldset class="submit">' . EOL;
     $actions = $node->getActions();
     $this->changeIndent(1);
     if (count($actions) == 0) {
         $actions[] = new T_Form_Button('submit', $node->getLabel());
     }
     foreach ($actions as $button) {
         $name = explode('_', get_class($button));
         $method = 'render' . array_pop($name);
         $xhtml .= $this->{$method}($button);
     }
     $this->changeIndent(-1);
     // </fieldset></form>
     $xhtml .= $this->indent . '</fieldset>' . EOL;
     $this->changeIndent(-1);
     $xhtml .= $this->indent . '</form>' . EOL;
     $this->addPostXhtml($node, $xhtml);
 }
Example #7
0
 /**
  * Catch any query method calls and proxy to the parsers.
  *
  * @return mixed
  */
 function __call($name, $args)
 {
     // build a list of all the answers from any parsers with this method
     $ans = array();
     foreach ($this->parsers as $p) {
         if (!method_exists($p, $name)) {
             continue;
         }
         $a = call_user_func_array(array($p, $name), $args);
         if (!is_null($a) && $a->getConfidence() >= $this->min) {
             $ans[] = $a;
         }
     }
     // simple cases
     if (count($ans) == 0) {
         return null;
     }
     if (count($ans) == 1) {
         return $ans[0]->getAnswer();
     }
     // multiple answers try to filter on level of certainty...
     $max = null;
     foreach ($ans as $a) {
         if (($c = $a->getConfidence()) > $max) {
             $max = $c;
         }
     }
     foreach (array_keys($ans) as $k) {
         if ($ans[$k]->getConfidence() < $max) {
             unset($ans[$k]);
         }
     }
     if (count($ans) == 1) {
         return _end($ans)->getAnswer();
     }
     // multiple answers of similar certainty, use most popular
     // answer, otherwise fallback to first
     $vals = array();
     $pop = array();
     foreach ($ans as $a) {
         $v = $a->getAnswer();
         $sig = md5(serialize($a));
         if (isset($pop[$sig])) {
             $pop[$sig]++;
         } else {
             $pop[$sig] = 1;
         }
         $vals[$sig] = $v;
     }
     asort($pop, SORT_NUMERIC);
     $pop = array_reverse($pop);
     reset($pop);
     return $vals[key($pop)];
 }
Example #8
0
 function testLastArrayMemberShortcut()
 {
     $this->assertSame(false, _end(array()));
     $this->assertSame('test', _end(array('test')));
     $this->assertSame('test', _end(array('more', 'members', 'test')));
 }