public function execute($operatorName)
 {
     if ($operatorName == "+") {
         $addobject = new Add();
         $addobject->execute($this->values);
         //$this->add();
     } else {
         if ($operatorName == "-") {
             $subtractobject = new Subtract();
             $subtractobject->execute($this->values);
             //$this->subtract ();
         } else {
             if ($operatorName == "!") {
                 $factorialobject = new Factorial();
                 $factorialobject->execute($this->values);
                 //$this->factorial ();
             } else {
                 try {
                     throw new NoSuchOperator('No such operator!');
                 } catch (NoSuchOperator $e) {
                     echo 'Caught exception: ' . $e->getMessage();
                 }
             }
         }
     }
 }
 /**
  * @dataProvider provider
  */
 public function testAdd($num1, $num2, $expection)
 {
     $add = new Add();
     $add->setNum1($num1);
     $add->setNum2($num2);
     $this->assertEquals($expection, $add->getResult());
 }
Example #3
0
 public function do_add_download($username)
 {
     if (Auth::user() && Auth::user()->role == 'administrator') {
         $did_id = Input::get('download');
         $user_id = Input::get('user_id');
         $fromdate = Input::get('fromdate');
         $todate = Input::get('todate');
         $download = new Add(array('did_id' => $did_id, 'user_id' => $user_id, 'created_at' => $fromdate, 'updated_at' => $todate));
         $download->save();
         return Redirect::to('/add/' . $username);
     }
 }
Example #4
0
 public function actionIndex()
 {
     $title = '';
     $short_content = '';
     $content = '';
     $errors = false;
     if (User::checkLogged()) {
         $id = $_SESSION['user'];
         $author_name = Add::getAuthorname($id);
         echo $author_name;
         print_r($_SESSION);
         if (isset($_REQUEST['submit'])) {
             $title = $_REQUEST['title'];
             $content = $_REQUEST['content'];
             $short_content = Add::shortPost($content);
             $errors = false;
             if (!Add::checkTitle($title)) {
                 $errors[] = 'Заголовок отсутствует или меньше 2-х символов';
             }
             if (!Add::checkContent($content)) {
                 $errors[] = 'Текст слишком короткий';
             }
             if ($errors == false) {
                 $lastId = Add::sendPost($title, $short_content, $content, $author_name);
                 header("Location:/news/{$lastId}");
             }
         }
     }
     require_once ROOT . '/views/addpost/index.php';
     return true;
     //redirect
 }
Example #5
0
         $sync['status'] = 'default';
         if (isset($_POST['d_u']) && isset($_POST['d_p'])) {
             $del_user = fetch_single($_POST['d_u']);
             $del_pass = fetch_single($_POST['d_p']);
             if ($del_user != '' && $del_pass != '') {
                 require_once 'Zend/Service/Delicious.php';
                 $del = new Zend_Service_Delicious($del_user, $del_pass);
                 try {
                     $posts = $del->getAllPosts();
                 } catch (Zend_Service_Delicious_Exception $e) {
                     $posts = false;
                     $sync['status'] = 'error';
                 }
                 if ($posts) {
                     var_dump($posts);
                     $result = Add::vxSync($p->User, $p->db, $posts);
                     var_dump($result);
                 }
             } else {
                 $sync['status'] = 'default';
             }
         } else {
             $sync['status'] = 'default';
         }
         $p->vxHead($msgSiteTitle = '同步');
         $p->vxBodyStart();
         $p->vxTop();
         $p->vxContainer('add_sync', $sync);
         break;
     }
 case 'add_add':
Example #6
0
File: add.php Project: nkdas/ems
<?php

require_once dirname(__DIR__) . '/resources/db_connection.php';
if (isset($_SESSION['pk_admin'])) {
    // recieve ajax post
    $addObject = new Add();
    if (isset($_POST['role'])) {
        $status = $addObject->add('roles', 'role', $_POST['role']);
        echo $status;
    } elseif (isset($_POST['resource'])) {
        $status = $addObject->add('resources', 'resource', $_POST['resource']);
        echo $status;
    }
} else {
    header('Location: index.php');
}
class add
{
    public function add($table, $column, $columnValue)
    {
        global $connection;
        $sql = "INSERT INTO {$table} ({$column}) VALUES ('{$columnValue}')";
        if (mysqli_query($connection, $sql)) {
            $status = 'success';
        } else {
            $status = 'failed';
        }
        return $status;
    }
}
Example #7
0
}
class Add extends Computation
{
    public function apply()
    {
        return $this->_a + $this->_b;
    }
}
class Divide extends Computation
{
    public function apply()
    {
        return $this->_a / $this->_b;
    }
}
$add = new Add(5, 5);
println($add->apply());
//->10
$divide = new Divide(5, 5);
println($divide->apply());
//->1
function apply(callable $operator)
{
    return function ($a, $b) use($operator) {
        return $operator($a, $b);
    };
}
$add = function ($a, $b) {
    return $a + $b;
};
$divide = function ($a, $b) {