Example #1
0
 public function testIfSessionCanAddEntity()
 {
     $project = new Project();
     $project->setName('My Project');
     $this->session->addEntity($project);
     $this->assertTrue($this->session->isAdded($project));
 }
Example #2
0
 public function testTpConfig()
 {
     $project = new Project();
     $project->setName('name');
     $project->setDescription('description');
     $project->setKeywords(['k1', 'k2']);
     $project->setHomepage('http://homepage.com');
     $project->addAuthor(new Author('author-name <*****@*****.**>'));
     $project->addPackage($this->buildPackage('namespace1', ['path1.1', 'path1.2']));
     $this->assertSame(['name' => 'name', 'description' => 'description', 'keywords' => ['k1', 'k2'], 'homepage' => 'http://homepage.com', 'authors' => [['name' => 'author-name', 'email' => '*****@*****.**']], 'autoload' => ['psr-4' => ['namespace1\\' => ['path1.1', 'path1.2']]]], $project->toConfig());
 }
Example #3
0
 public function executeCreate(sfWebRequest $request)
 {
     $name = $request->getParameter("name");
     if (strlen($name) > 1 && strlen($name) < 45) {
         $p = new Project();
         $p->setName($name);
         $p->save();
     } else {
         $this->forward404("The project name is to long!");
     }
     $this->executeList($request);
     $this->setLayout("list");
 }
Example #4
0
 public function executeUpdate()
 {
     $jira = new sfJiraPlugin($this->getUser()->getProfile()->getJiraLogin(), $this->getUser()->getProfile()->getJiraPassword());
     $aProjects = $jira->getProjects();
     foreach ($aProjects as $project) {
         #var_dump( $project );
         $c = new Criteria();
         $c->add(ProjectPeer::USER_ID, $this->getUser()->getProfile()->getId());
         $c->add(ProjectPeer::KEY, $project->key);
         $p = ProjectPeer::doSelectOne($c);
         $c = new Criteria();
         $c->add(UserPeer::JIRA_LOGIN, $project->lead);
         $u = UserPeer::doSelectOne($c);
         if (empty($p)) {
             $p = new Project();
             $p->setKey($project->key);
             $p->setLeadId(!empty($u) ? $u->getId() : null);
             $p->setUserId($this->getUser()->getProfile()->getId());
             $p->setName($project->name);
             $p->setUpdated(date('r'));
             $p->save();
         }
         $issues = $jira->getIssuesForProject($p->getKey());
         foreach ($issues as $issue) {
             #die($p->getKey());
             if ($issue->assignee == $this->getUser()->getProfile()->getJiraLogin()) {
                 $c = new Criteria();
                 $c->add(TaskPeer::KEY, $issue->key);
                 $t = TaskPeer::doSelectOne($c);
                 if (empty($t)) {
                     $c = new Criteria();
                     $c->add(UserPeer::JIRA_LOGIN, $issue->reporter);
                     $u = UserPeer::doSelectOne($c);
                     $t = new Task();
                     $t->setProjectId($p->getId());
                     $t->setTitle($issue->summary);
                     $t->setDescription($issue->description);
                     $t->setKey($issue->key);
                     $t->setUpdated(date('r'));
                     $t->setStatusId($issue->status);
                     $t->setPriorityId($issue->priority);
                     $t->setLeadId(!empty($u) ? $u->getId() : null);
                     $t->save();
                 }
             }
         }
     }
     $this->redirect('@homepage');
     return sfView::NONE;
 }
 function testMap()
 {
     $outlet = Outlet::getInstance();
     $p = new Project();
     $p->setName('Project 1');
     $outlet->save($p);
     $p_map = $outlet->select('Project', 'where {Project.ProjectID} = ?', array($p->getProjectID()));
     $p_map = $p_map[0];
     $this->assertTrue($p === $p_map, 'Diferent object on identity map');
     $outlet->clearCache();
     $p_map = $outlet->select('Project', 'where {Project.ProjectID} = ?', array($p->getProjectID()));
     $p_map = $p_map[0];
     $this->assertTrue($p !== $p_map, 'Equal object on identity map');
 }
 function testUpdateAfterRelationshipUpdate()
 {
     $outlet = Outlet::getInstance();
     $p = new Project();
     $p->setName('Name 1');
     $b = new Bug();
     $b->Title = 'Test Bug';
     $p->addBug($b);
     $outlet->save($p);
     $projectid = $p->getProjectID();
     $p->setName('Name 2');
     $outlet->save($p);
     $p = $outlet->load('Project', $projectid);
     $this->assertEquals($p->getName(), 'Name 2');
 }
 protected function processCreate(sfWebRequest $request, ProjectFormCustom $form)
 {
     $form->bind($request->getParameter($form->getName()));
     if ($form->isValid()) {
         $values = $form->getValues();
         // Slugify name, and check if slug generated does not already exist and generate a new one if needed
         if (empty($values['name_slug'])) {
             $slug = MiscUtils::slugify($values['name']);
         } else {
             $slug = $values['name_slug'];
         }
         $size = 1;
         while (Doctrine_Core::getTable("Project")->checkSlugForProject(NULL, $slug, true)) {
             $slug = MiscUtils::slugify($values['name']) . substr(microtime(), -$size);
             $size++;
         }
         // Create the project into database
         $projectObject = new Project();
         $projectObject->setName($values['name']);
         $projectObject->setDescription($values['description']);
         $projectObject->setUserId($values['user_id']);
         $projectObject->setCreatedAt($values['created_at']);
         $projectObject->setStatus($values['status']);
         $projectObject->setSecurityLevel($values['security_level']);
         $projectObject->setNameSlug($slug);
         $projectObject->save();
         // Get the project's id
         $projectId = $projectObject->getId();
         // Create a new relationship between projects, products and project groups for each checked form's product
         foreach ($values['product'] as $product) {
             $ptpObject = new ProjectToProduct();
             $ptpObject->setProjectGroupId($values['group']);
             $ptpObject->setProjectId($projectId);
             $ptpObject->setProductId($product);
             $ptpObject->save();
         }
         if ($request->hasParameter('_save_and_add')) {
             $this->getUser()->setFlash('notice', $notice . ' You can add another one below.');
             $this->redirect('@project_new');
         } else {
             $this->getUser()->setFlash('notice', $notice);
             $this->redirect(array('sf_route' => 'project_edit', 'sf_subject' => $projectObject));
         }
     } else {
         $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
     }
 }
Example #8
0
 function addProject()
 {
     $response = new Response();
     try {
         $projectName = $this->input->post("project-name");
         $subdivision = $this->input->post("sub-division");
         $budget = $this->input->post("project-budget");
         $schemeId = $this->input->post("scheme");
         $project = new Project();
         $project->setCreated(new DateTime());
         $project->setName($projectName);
         $project->setStatus(Project::PROJECT_ADMIN_APPROVAL);
         $project->setBudget($budget);
         $project->setScheme($this->findById("Scheme", $schemeId));
         $subdivision = $this->findById("Subdivision", $subdivision);
         $project->setSubDivision($subdivision);
         $this->save($project);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #9
0
function testsperengine()
{
    global $tests;
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "perform generic bean manipulation";
    $ok = 1;
    $bean = RedBean_OODB::dispense("note");
    $bean->message = "hai";
    $bean->color = 3;
    $bean->date = time();
    $bean->special = 'n';
    $bean->state = 90;
    RedBean_OODB::set($bean);
    $bean2 = RedBean_OODB::getById("note", 1);
    if ($bean2->state != 90 || $bean2->special != 'n' || $bean2->message != 'hai') {
        $ok = 0;
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $bean->message = "lorem ipsum";
    RedBean_OODB::set($bean);
    $bean->message = 1;
    $bean->color = "green";
    $bean->date = str_repeat("BLABLA", 100);
    RedBean_OODB::set($bean);
    unset($bean);
    $bean = RedBean_OODB::dispense("note");
    $bean->color = "green";
    //print_r($bean);
    $bean3 = RedBean_OODB::find($bean, array("color" => "="));
    if (count($bean3) !== 1) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
    }
    unset($bean);
    $bean = RedBean_OODB::dispense("note");
    $bean->state = 80;
    $bean3 = RedBean_OODB::find($bean, array("state" => ">"));
    if (count($bean3) !== 1) {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    try {
        $bla = RedBean_OODB::find($bean, array("undefined" => ">"));
    } catch (Exception $e) {
        //dont fail if prop does not exist
        die("<b style='color:red'>Error CANNOT3:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $note = $bean3[1];
    $person = RedBean_OODB::dispense("person");
    $person->age = 50;
    $person->name = "Bob";
    $person->gender = "m";
    RedBean_OODB::set($person);
    RedBean_OODB::associate($person, $note);
    $memo = RedBean_OODB::getById("note", 1);
    $authors = RedBean_OODB::getAssoc($memo, "person");
    if (count($authors) !== 1) {
        die("<b style='color:red'>Error CANNOT4:" . SmartTest::instance()->canwe);
    }
    RedBean_OODB::trash($authors[1]);
    //$ok=false;
    //try{
    $authors = RedBean_OODB::getAssoc($memo, "person");
    if (count($authors) > 0) {
        $ok = 0;
    }
    //}
    //catch(Exception $e){
    //	$ok=1;
    //}
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //unit tests
    //drop the note table
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "dispense an RedBean_OODB Bean";
    $oBean = RedBean_OODB::dispense();
    if (!$oBean instanceof OODBBean) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "put a bean in the database";
    $person = RedBean_OODB::dispense("person");
    $person->name = "John";
    $person->age = 35;
    $person->gender = "m";
    $person->hasJob = true;
    $id = RedBean_OODB::set($person);
    $johnid = $id;
    //echo "--->$id";
    $person2 = RedBean_OODB::getById("person", $id);
    if ($person2->age != $person->age) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    $person2->anotherprop = 2;
    RedBean_OODB::set($person2);
    $person = RedBean_OODB::dispense("person");
    $person->name = "Bob";
    $person->age = 50;
    $person->gender = "m";
    $person->hasJob = false;
    $bobid = RedBean_OODB::set($person);
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "find records on basis of similarity";
    //RedBean_OODB::closeAllBeansOfType("person");
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->gender = "m";
    $persons = RedBean_OODB::find($searchBean, array("gender" => "="));
    if (count($persons) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //RedBean_OODB::closeAllBeansOfType("person");
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->name = "John";
    $persons = RedBean_OODB::find($searchBean, array("name" => "LIKE"));
    if (count($persons) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    $searchBean2 = RedBean_OODB::dispense("person");
    $searchBean2->name = "John";
    $searchBean2->gender = "m";
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="));
    if (count($persons2) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //test limits (start end etc..)
    $searchBean2 = RedBean_OODB::dispense("person");
    $searchBean2->name = "John";
    $searchBean2->gender = "m";
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="), 1);
    if (count($persons2) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="), 0, 1);
    if (count($persons2) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="), 0, 1, "age ASC");
    if (count($persons2) == 1) {
        $who = array_pop($persons2);
        if ($who->name != "John") {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="), 0, 1, "age DESC");
    if (count($persons2) == 1) {
        $who = array_pop($persons2);
        if ($who->name != "Bob") {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    //test extra sql
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="), 0, 1, "age DESC", "order by age ASC limit 1");
    if (count($persons2) == 1) {
        $who = array_pop($persons2);
        if ($who->name != "John") {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->age = "20";
    $searchBean->gender = "m";
    $persons = RedBean_OODB::find($searchBean, array("age" => ">"));
    if (count($persons) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->age = "20";
    $searchBean->gender = "v";
    $persons = RedBean_OODB::find($searchBean, array("age" => ">", "gender" => "="));
    if (count($persons) != 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->age = "50";
    $searchBean->name = "Bob";
    $searchBean->gender = "m";
    $persons = RedBean_OODB::find($searchBean, array("age" => "=", "name" => "LIKE", "gender" => "="));
    if (count($persons) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    $whisky = RedBean_OODB::dispense("whisky");
    $whisky->name = "Glen Old";
    $whisky->age = 50;
    RedBean_OODB::set($whisky);
    $searchBean = RedBean_OODB::dispense("whisky");
    $searchBean->age = "12";
    $drinks = RedBean_OODB::find($searchBean, array("age" => ">"));
    if (count($drinks) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "associate beans with eachother?";
    $app = RedBean_OODB::dispense("appointment");
    $app->kind = "dentist";
    RedBean_OODB::set($app);
    RedBean_OODB::associate($person2, $app);
    $appforbob = array_shift(RedBean_OODB::getAssoc($person2, "appointment"));
    if (!$appforbob || $appforbob->kind != "dentist") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "delete a bean?";
    $person = RedBean_OODB::getById("person", $bobid);
    RedBean_OODB::trash($person);
    try {
        $person = RedBean_OODB::getById("person", $bobid);
        $ok = 0;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = true;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "unassociate two beans?";
    $john = RedBean_OODB::getById("person", $johnid);
    //hmmmmmm gaat mis bij innodb
    /*
    	SELECT * FROM `person` WHERE id = 2
    	Fatal error: Uncaught exception 'ExceptionFailedAccessBean' with message 'bean not found' in /Applications/xampp/xamppfiles/htdocs/cms/oodb.php:1161 Stack trace: #0 /Applications/xampp/xamppfiles/htdocs/cms/test.php(275): RedBean_OODB::getById('person', 2) #1 {main} thrown in /Applications/xampp/xamppfiles/htdocs/cms/oodb.php on line 1161
    */
    $app = RedBean_OODB::getById("appointment", 1);
    RedBean_OODB::unassociate($john, $app);
    $john2 = RedBean_OODB::getById("person", $johnid);
    $appsforjohn = RedBean_OODB::getAssoc($john2, "appointment");
    if (count($appsforjohn) > 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "unassociate by deleting a bean?";
    $anotherdrink = RedBean_OODB::dispense("whisky");
    $anotherdrink->name = "bowmore";
    $anotherdrink->age = 18;
    $anotherdrink->singlemalt = 'y';
    RedBean_OODB::set($anotherdrink);
    RedBean_OODB::associate($anotherdrink, $john);
    $hisdrinks = RedBean_OODB::getAssoc($john, "whisky");
    if (count($hisdrinks) !== 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    RedBean_OODB::trash($anotherdrink);
    $hisdrinks = RedBean_OODB::getAssoc($john, "whisky");
    if (count($hisdrinks) !== 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "create parent child relationships?";
    $pete = RedBean_OODB::dispense("person");
    $pete->age = 48;
    $pete->gender = "m";
    $pete->name = "Pete";
    $peteid = RedBean_OODB::set($pete);
    $rob = RedBean_OODB::dispense("person");
    $rob->age = 19;
    $rob->name = "Rob";
    $rob->gender = "m";
    $saskia = RedBean_OODB::dispense("person");
    $saskia->age = 20;
    $saskia->name = "Saskia";
    $saskia->gender = "f";
    RedBean_OODB::set($saskia);
    RedBean_OODB::set($rob);
    RedBean_OODB::addChild($pete, $rob);
    RedBean_OODB::addChild($pete, $saskia);
    $children = RedBean_OODB::getChildren($pete);
    $names = 0;
    if (is_array($children) && count($children) === 2) {
        foreach ($children as $child) {
            if ($child->name === "Rob") {
                $names++;
            }
            if ($child->name === "Saskia") {
                $names++;
            }
        }
    }
    if (!$names) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
    }
    $daddies = RedBean_OODB::getParent($saskia);
    $daddy = array_pop($daddies);
    if ($daddy->name === "Pete") {
        $ok = 1;
    } else {
        $ok = 0;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "remove a child from a parent-child tree?";
    RedBean_OODB::removeChild($daddy, $saskia);
    $children = RedBean_OODB::getChildren($pete);
    $ok = 0;
    if (count($children) === 1) {
        $only = array_pop($children);
        if ($only->name === "Rob") {
            $ok = 1;
        }
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //test exceptions
    $ok = 0;
    try {
        RedBean_OODB::addChild($daddy, $whisky);
    } catch (ExceptionInvalidParentChildCombination $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    $ok = 0;
    try {
        RedBean_OODB::removeChild($daddy, $whisky);
    } catch (ExceptionInvalidParentChildCombination $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "save on the fly while associating?";
    $food = RedBean_OODB::dispense("dish");
    $food->name = "pizza";
    RedBean_OODB::associate($food, $pete);
    $petesfood = RedBean_OODB::getAssoc($pete, "food");
    if (is_array($petesfood) && count($petesfood) === 1) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //some extra tests... quick without further notice.
    $food = RedBean_OODB::dispense("dish");
    $food->name = "spaghetti";
    RedBean_OODB::trash($food);
    //test aggregation functions
    //insert stat table
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 1;
    RedBean_OODB::set($s);
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 2;
    RedBean_OODB::set($s);
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 3;
    RedBean_OODB::set($s);
    SmartTest::instance()->canwe = "can we use aggr functions using Redbean?";
    if (RedBean_OODB::numberof("stattest") != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::maxof("stattest", "amount") != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::minof("stattest", "amount") != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::avgof("stattest", "amount") != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::sumof("stattest", "amount") != 6) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::distinct("stattest", "amount")) != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    //test list function
    SmartTest::instance()->canwe = "can we use list functions using Redbean?";
    if (count(RedBean_OODB::listAll("stattest")) != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::listAll("stattest", 1)) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::listAll("stattest", 1, 1)) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::listAll("stattest", 1, 2)) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::listAll("stattest", 1, 1, "", " limit 100 ")) != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    //now test with decorator =======================================
    RedBean_OODB::setLocking(true);
    $i = 3;
    SmartTest::instance()->canwe = "generate only valid classes?";
    try {
        $i += RedBean_OODB::gen("");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //nothing
    try {
        $i += RedBean_OODB::gen(".");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //illegal chars
    try {
        $i += RedBean_OODB::gen(",");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //illegal chars
    try {
        $i += RedBean_OODB::gen("null");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //keywords
    try {
        $i += RedBean_OODB::gen("Exception");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //reserved
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "generate classes using Redbean?";
    if (!class_exists("Bug")) {
        $i += RedBean_OODB::gen("Bug");
        if ($i !== 4) {
            die("<b style='color:red'>Error CANNOT {$i}:" . SmartTest::instance()->canwe);
        }
    } else {
        if ($i !== 3) {
            die("<b style='color:red'>Error CANNOT {$i}:" . SmartTest::instance()->canwe);
        }
    }
    if (!class_exists("Bug")) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "use getters and setters";
    $bug = new Bug();
    $bug->setSomething(sha1("abc"));
    if ($bug->getSomething() != sha1("abc")) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //can we use non existing props? --triggers fatal..
    $bug->getHappy();
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "use oget and oset?";
    RedBean_OODB::gen("Project");
    $proj = new Project();
    $proj->setName("zomaar");
    $bug->osetProject($proj);
    $bug->save();
    $oldbug = new Bug(1);
    $oldproj = $oldbug->ogetProject();
    if ($oldproj->getName() != "zomaar") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "Use boolean values and retrieve them with is()?";
    if ($bug->isHappy()) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $bug->setHappy(true);
    $bug->save();
    $bug = new Bug(1);
    if (!$bug->isHappy()) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $bug->setHappy(false);
    if ($bug->isHappy()) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "break oget/oset assoc?";
    $bug->osetProject(null);
    $bug->save();
    $bug = null;
    $bug = new Bug(1);
    $proj = $bug->ogetProject();
    if ($proj->getID() > 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "Use the decorator to associate items?";
    $bug = null;
    $bug1 = new Bug();
    $bug2 = new Bug();
    $bug1->setName("b1");
    $bug2->setName("b2");
    $p = new Project();
    $p->setProjectNum(42);
    $p->add($bug1);
    $p->add($bug2);
    $p = null;
    $b = new Project();
    $b->setProjectNum(42);
    //also fck up case...
    $arr = RedBean_Decorator::find($b, array("PRoJECTnuM" => "="));
    $proj = array_pop($arr);
    $bugs = $proj->getRelatedBug();
    if (count($bugs) !== 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "use hierarchies?";
    $sub1 = new Project();
    $sub2 = new Project();
    $sub3 = new Project();
    $sub1->setName("a");
    $sub2->setName("b");
    $sub2->setDate(time());
    $sub3->setName("c");
    $sub2->attach($sub3);
    $proj->attach($sub1)->attach($sub2);
    $arr = RedBean_Decorator::find($b, array("PRoJECTnuM" => "="));
    $proj = array_pop($arr);
    $c = $proj->children();
    foreach ($c as $c1) {
        if ($c1->getName() == "b") {
            break;
        }
    }
    $c2 = $c1->children();
    $sub3 = array_pop($c2);
    if ($sub3->getName() != "c") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "make our own models";
    if (!class_exists("Customer")) {
        class Customer extends RedBean_Decorator
        {
            public function __construct($id = 0)
            {
                parent::__construct("Customer", $id);
            }
            //each customer may only have one project
            public function setProject(Project $project)
            {
                $this->clearRelatedProject();
                $this->command("add", array($project));
            }
            public function add($what)
            {
                if ($what instanceof Project) {
                    return false;
                }
                $this->command("add", array($what));
            }
        }
    }
    $p2 = new Project();
    $p2->setName("hihi");
    $cust = new Customer();
    $cust->setProject($p2);
    $cust->add($p2);
    $cust->setProject($proj);
    $ps = $cust->getRelatedProject();
    if (count($ps) > 1) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $p = array_pop($ps);
    if ($p->getName() == "hihi") {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "delete all assoc";
    $cust->clearAllRelations();
    $ps = $cust->getRelatedProject();
    if (count($ps) > 0) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "not mess with redbean";
    $bla = new Customer();
    Redbean_Decorator::find($bla, array());
    $ok = 0;
    try {
        Redbean_Decorator::find($bla, array("bkaa" => "q="));
    } catch (ExceptionInvalidFindOperator $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "manipulate hierarchies";
    $cust2 = new Customer();
    $cust->attach($cust2);
    $c = $cust->children();
    if (count($c) !== 1) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $cust->remove($cust2);
    $c = $cust->children();
    if (count($c) !== 0) {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    $cust->attach($cust2);
    Customer::delete($cust2);
    $c = $cust->children();
    if (count($c) !== 0) {
        die("<b style='color:red'>Error CANNOT3:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "remove associations";
    $cust3 = new Customer();
    $cust4 = new Customer();
    $cust3->add($cust4);
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 1) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    $cust3->remove($cust4);
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 0) {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    $cust3 = new Customer();
    $cust4 = new Customer();
    $cust3->add($cust4);
    $cust3->add($cust4);
    //also test multiple assoc
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 1) {
        die("<b style='color:red'>Error CANNOT3:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    $cust4->remove($cust3);
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 0) {
        die("<b style='color:red'>Error CANNOT4:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    $cust3 = new Customer();
    $cust4 = new Customer();
    $cust3->add($cust4);
    $cust3->add($cust4);
    //also test multiple assoc
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 1) {
        die("<b style='color:red'>Error CANNOT5:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    Customer::delete($cust4);
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 0) {
        die("<b style='color:red'>Error CANNOT6:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "import from post";
    $_POST["hallo"] = 123;
    $_POST["there"] = 456;
    $_POST["nope"] = 789;
    $cust = new Customer();
    $cust->importFromPost(array("hallo", "there"));
    if ($cust->getHallo() == 123 && $cust->getThere() == 456 && !$cust->getNope()) {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        exit;
    }
    foreach ($cust->problems() as $p) {
        if ($p) {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
    }
    SmartTest::instance()->progress();
    $_POST["hallo"] = 123;
    $_POST["there"] = 456;
    $_POST["nope"] = 789;
    $cust = new Customer();
    $cust->importFromPost("hallo,there");
    if ($cust->getHallo() == 123 && $cust->getThere() == 456 && !$cust->getNope()) {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
        exit;
    }
    foreach ($cust->problems() as $p) {
        if ($p) {
            die("<b style='color:red'>Error CANNOT3:" . SmartTest::instance()->canwe);
        }
    }
    SmartTest::instance()->progress();
    $_POST["hallo"] = 123;
    $_POST["there"] = 456;
    $_POST["nope"] = 789;
    $cust = new Customer();
    $cust->importFromPost();
    if ($cust->getHallo() == 123 && $cust->getThere() == 456 && $cust->getNope()) {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        exit;
    }
    foreach ($cust->problems() as $p) {
        if ($p) {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
    }
    SmartTest::instance()->progress();
    if (!class_exists("Trick")) {
        class Trick extends RedBean_Decorator
        {
            public function __construct($id = 0)
            {
                parent::__construct("Customer", $id);
            }
            public function setHallo()
            {
                return "hallodaar";
            }
        }
    }
    $trick = new Trick();
    $trick->importFromPost(array("hallo", "there"));
    $message = array_shift($trick->problems());
    if ($message === "hallodaar") {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "avoid race-conditions by locking?";
    RedBean_OODB::gen("Cheese,Wine");
    $cheese = new Cheese();
    $cheese->setName('Brie');
    $cheese->save();
    $cheese = new Cheese(1);
    //try to mess with the locking system...
    $oldkey = RedBean_OODB::$pkey;
    RedBean_OODB::$pkey = 1234;
    $cheese = new Cheese(1);
    $cheese->setName("Camembert");
    $ok = 0;
    try {
        $cheese->save();
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $bordeaux = new Wine();
    $bordeaux->setRegion("Bordeaux");
    try {
        $bordeaux->add($cheese);
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    try {
        $bordeaux->attach($cheese);
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    try {
        $bordeaux->add(new Wine());
        $ok = 1;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 0;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    RedBean_OODB::$pkey = $oldkey;
    $cheese = new Cheese(1);
    $cheese->setName("Camembert");
    $ok = 0;
    try {
        $cheese->save();
        $ok = 1;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 0;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    try {
        RedBean_OODB::$pkey = 999;
        RedBean_OODB::setLockingTime(0);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    try {
        RedBean_OODB::$pkey = 123;
        RedBean_OODB::setLockingTime(100);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar2");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        die("<b style='color:red'>Error CANNOT-C:" . SmartTest::instance()->canwe);
    } catch (Exception $e) {
        SmartTest::instance()->progress();
    }
    try {
        RedBean_OODB::$pkey = 42;
        RedBean_OODB::setLockingTime(0);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar3");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //test value ranges
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(-1);
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(1.5);
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime("aaa");
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(null);
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    //can we reset logs
    SmartTest::instance()->canwe = "reset the logs?";
    $logs = RedBean_DBAdapter::getLogs();
    //are the logs working?
    if (is_array($logs) && count($logs) > 0) {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    RedBean_DBAdapter::resetLogs();
    $logs = RedBean_DBAdapter::getLogs();
    if (is_array($logs) && count($logs) === 0) {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "freeze the database?";
    RedBean_OODB::freeze();
    $joop = new Project();
    $joop->setName("Joop");
    $joopid = $joop->save();
    if (!is_numeric($joopid) || $joopid < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $joop->setBlaaataap("toppiedoe");
    $joop->save();
    $joop2 = new Project($joopid);
    $name = $joop2->getName();
    $blaataap = $joop2->getBlaataap();
    if ($name !== "Joop") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (!is_null($blaataap)) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    try {
        RedBean_OODB::gen("haas");
        $haas = new Haas();
        $haas->setHat("redhat");
        $id = $haas->save();
        if ($id !== 0) {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $cheese = new Cheese();
    $cheese->setName("bluecheese");
    $cheeseid = $cheese->save();
    if (!$cheeseid) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    $anothercheese = new Cheese();
    $cheese->add($anothercheese);
    $cheese->attach($anothercheese);
    $a1 = $cheese->getRelatedCheese();
    $a2 = $cheese->children();
    if (!is_array($a1) || is_array($a1) && count($a1) !== 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (!is_array($a2) || is_array($a2) && count($a2) !== 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    //now scan the logs for database modifications
    $logs = strtolower(implode(",", RedBean_DBAdapter::getLogs()));
    if (strpos("alter", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("truncate", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("drop", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("change", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("show", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("describe", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("drop database", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    //should be unable to do gc() and optimize() and clean() and resetAll()
    RedBean_DBAdapter::resetLogs();
    if (RedBean_OODB::gc() && count(RedBean_DBAdapter::getLogs()) > 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::optimizeIndexes() && count(RedBean_DBAdapter::getLogs()) > 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::clean() && count(RedBean_DBAdapter::getLogs()) > 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::registerUpdate("cheese") && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::registerSearch("cheese") && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->canwe = "can we unfreeze the database";
    try {
        RedBean_OODB::unfreeze();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    //should be ABLE to do gc() and optimize() and clean() and resetAll()
    RedBean_DBAdapter::resetLogs();
    if (!RedBean_OODB::gc() && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (!RedBean_OODB::optimizeIndexes() && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (!RedBean_OODB::clean() && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (!RedBean_OODB::registerUpdate("cheese") && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (!RedBean_OODB::registerSearch("cheese") && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    //test convenient tree functions
    SmartTest::instance()->canwe = "convient tree functions";
    if (!class_exists("Person")) {
        RedBean_OODB::gen("person");
    }
    $donald = new Person();
    $donald->setName("Donald");
    $donald->save();
    $kwik = new Person();
    $kwik->setName("Kwik");
    $kwik->save();
    $kwek = new Person();
    $kwek->setName("Kwek");
    $kwek->save();
    $kwak = new Person();
    $kwak->setName("Kwak");
    $kwak->save();
    $donald->attach($kwik);
    $donald->attach($kwek);
    $donald->attach($kwak);
    if (count($donald->children()) != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count($kwik->siblings()) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    //todo
    if ($kwik->hasParent($donald) != true) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasParent($kwak) != false) {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasChild($kwak) != true) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasChild($donald) != false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasChild($kwik) != false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($kwek) != true) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($kwak) != false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($donald) != false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    //copy
    SmartTest::instance()->canwe = "copy functions";
    $kwak2 = $kwak->copy();
    $id = $kwak2->save();
    $kwak2 = new Person($id);
    if ($kwak->getName() != $kwak2->getName()) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->canwe = "countRelated";
    R::gen("Blog,Comment");
    $blog = new Blog();
    $blog2 = new Blog();
    $blog->setTitle("blog1");
    $blog2->setTitle("blog2");
    for ($i = 0; $i < 5; $i++) {
        $comment = new Comment();
        $comment->setText("comment no.  {$i} ");
        $blog->add($comment);
    }
    for ($i = 0; $i < 3; $i++) {
        $comment = new Comment();
        $comment->setText("comment no.  {$i} ");
        $blog2->add($comment);
    }
    if ($blog->numofComment() !== 5) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($blog2->numofComment() !== 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->canwe = "associate tables of the same name";
    $blog = new Blog();
    $blogb = new Blog();
    $blog->title = 'blog a';
    $blogb->title = 'blog b';
    $blog->add($blogb);
    $b = $blog->getRelatedBlog();
    if (count($b) !== 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    $b = array_pop($b);
    if ($b->title != 'blog b') {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->canwe = "inferTypeII patch";
    $blog->rating = 4294967295.0;
    $blog->save();
    $id = $blog->getID();
    $blog2->rating = -1;
    $blog2->save();
    $blog = new Blog($id);
    if ($blog->getRating() != 4294967295.0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->canwe = "Longtext column type";
    $blog->message = str_repeat("x", 65535);
    $blog->save();
    $blog = new Blog($id);
    if (strlen($blog->message) != 65535) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    $rows = RedBean_OODB::$db->get("describe blog");
    if ($rows[3]["Type"] != "text") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    $blog->message = str_repeat("x", 65536);
    $blog->save();
    $blog = new Blog($id);
    if (strlen($blog->message) != 65536) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    $rows = RedBean_OODB::$db->get("describe blog");
    if ($rows[3]["Type"] != "longtext") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    Redbean_OODB::clean();
}
 function testDbFunctions()
 {
     $outlet = Outlet::getInstance();
     $p1 = new Project();
     $p1->setName('AAAA');
     $outlet->save($p1);
     $p2 = new Project();
     $p2->setName('BBBB');
     $outlet->save($p2);
     $stmt = $outlet->query('SELECT MAX({p.Name}) as max_project FROM {Project p}');
     $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $this->assertEquals($data[0]['max_project'], 'BBBB');
 }
Example #11
0
 /**
  * Save Customer
  * @param sfWebRequest $request
  * @return unknown_type
  */
 public function executeSaveProject(sfWebRequest $request)
 {
     $projectService = new ProjectService();
     if ($request->isMethod('post')) {
         $project = new Project();
         $project->setCustomerId($request->getParameter('cmbCustomerId'));
         $project->setName($request->getParameter('txtName'));
         $project->setDescription($request->getParameter('txtDescription'));
         $projectService->saveProject($project);
         $this->setMessage('SUCCESS', array(TopLevelMessages::SAVE_SUCCESS));
         $this->redirect('admin/listProject');
     }
     $customerService = new CustomerService();
     $this->listCustomer = $customerService->getCustomerList();
 }
Example #12
0
 function find($criteria = null, $order = null, $limit = 1000, $from = 0)
 {
     $result = $this->database->query($this->buildFindQuery($criteria, $order, $limit, $from));
     if (!is_null($result->getError())) {
         return $result->getError();
     }
     $projects = array();
     while ($row = $result->fetchRow()) {
         $project = new Project();
         $value = $row[0];
         $project->setId($value);
         $value = $row[1];
         $project->setName($value);
         $value = $row[2];
         $project->setDescription($value);
         $value = $row[3];
         $value = $this->database->toBoolean($value);
         $project->setMove_more($value);
         $value = $row[4];
         $project->setCampaign($value);
         $value = $row[5];
         $project->setSuspending($value);
         $value = $row[6];
         $project->setEnding($value);
         $value = $row[7];
         $project->setOwner($value);
         $value = $row[8];
         $project->setCruid($value);
         $value = $row[9];
         $project->setPkey($value);
         $value = $row[10];
         $project->setRsskey($value);
         $value = $row[11];
         $project->setR_date($value);
         $value = $row[12];
         $project->setR_user($value);
         if ($order != null) {
             array_push($projects, $project);
         } else {
             $projects[$project->getId()] = $project;
         }
     }
     return $projects;
 }
Example #13
0
 public function setName($name)
 {
     $this->__load();
     return parent::setName($name);
 }
Example #14
0
 public function add($name)
 {
     $this->view = null;
     try {
         $user = User::find(Session::uid());
         if (!$user->getId() || !$user->getIs_admin()) {
             throw new Exception('Action not allowed.');
         }
         if (!preg_match('/^\\d*[-a-zA-Z][-a-zA-Z0-9]*$/', $name)) {
             throw new Exception('The name of the project can only contain alphanumeric characters plus dashes and must have 1 alpha character at least');
         }
         try {
             $project = Project::find($name);
         } catch (Exception $e) {
         }
         if (is_object($project) && $project->getProjectId($name)) {
             throw new Exception('Project with the same name already exists!');
         }
         $file = new File();
         $logo = '';
         if (!empty($_POST['logo'])) {
             $file->findFileById($_POST['logo']);
             $logo = basename($file->getUrl());
         }
         $project = new Project();
         $project->setName($name);
         $project->setDescription($_POST['description']);
         $project->setWebsite($_POST['website']);
         $project->setContactInfo($user->getUsername());
         $project->setOwnerId($user->getId());
         $project->setActive(true);
         $project->setInternal(true);
         $project->setRequireSandbox(true);
         $project->setLogo($logo);
         $project->setRepo_type('git');
         $project->setRepository($_POST['github_repo_url']);
         $project->setGithubId($_POST['github_client_id']);
         $project->setGithubSecret($_POST['github_client_secret']);
         $project->save();
         if ($file->getId()) {
             $file->setProjectId($project->getProjectId());
             $file->save();
         }
         $journal_message = '@' . $user->getNickname() . ' added project *' . $name . '*';
         Utils::systemNotification($journal_message);
         echo json_encode(array('success' => true, 'message' => $journal_message));
     } catch (Exception $e) {
         $error = $e->getMessage();
         echo json_encode(array('success' => false, 'message' => $error));
     }
 }
 /**
  * Init active project, if we have active_project $_GET var
  *
  * @access public
  * @param void
  * @return null
  * @throws Error
  */
 private function initActiveProject()
 {
     trace(__FILE__, 'initActiveProject()');
     $project_id = array_var($_GET, 'active_project');
     if (!empty($project_id)) {
         $project = Projects::findById($project_id);
         if ($project instanceof Project) {
             $this->setProject($project);
         } else {
             $project = new Project();
             $project->setId($project_id);
             $project->setName(lang('deleted or unknown'));
             //flash_error(lang('failed to load project'));
             $this->setProject($project);
             //throw new Error(lang('failed to load project'));
         }
         // if
     }
     // if
 }
 /**
  * Copy project
  *
  * @param void
  * @return null
  */
 function copy()
 {
     trace(__FILE__, "copy():begin");
     if (!Project::canAdd(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $this->setTemplate('copy_project');
     $this->setLayout('administration');
     $project_data = array_var($_POST, 'project');
     tpl_assign('project_data', $project_data);
     // Submitted...
     if (is_array($project_data)) {
         $source = Projects::findById($project_data['source']);
         if (!$source instanceof Project) {
             flash_error(lang('project dnx'));
             $this->redirectTo('administration', 'projects');
         }
         // if
         try {
             $shift_dates = isset($project_data['shift_dates']) ? $project_data['shift_dates'] == 'checked' : false;
             $copy_details = isset($project_data['copy_details']) ? $project_data['copy_details'] == 'checked' : false;
             $copy_tasks = isset($project_data['copy_tasks']) ? $project_data['copy_tasks'] == 'checked' : false;
             $copy_milestones = isset($project_data['copy_milestones']) ? $project_data['copy_milestones'] == 'checked' : false;
             $copy_messages = isset($project_data['copy_messages']) ? $project_data['copy_messages'] == 'checked' : false;
             $copy_links = isset($project_data['copy_links']) ? $project_data['copy_links'] == 'checked' : false;
             $copy_files = isset($project_data['copy_files']) ? $project_data['copy_files'] == 'checked' : false;
             $copy_users = isset($project_data['copy_users']) ? $project_data['copy_users'] == 'checked' : false;
             $copy_pages = isset($project_data['copy_pages']) ? $project_data['copy_pages'] == 'checked' : false;
             DB::beginWork();
             $project = new Project();
             $new_name = lang('projects copy new name', $source->getName());
             $new_name .= date(' z H:i:s');
             $project->setName($new_name);
             if ($copy_details) {
                 $project->setDescription($source->getDescription());
                 $project->setPriority($source->getPriority());
                 $project->setShowDescriptionInOverview($source->getShowDescriptionInOverview());
             }
             $project->save();
             $project_id = $project->getId();
             $add_seconds = 0;
             if (isset($project_data['add_days'])) {
                 $add_days = 0 + trim($project_data['add_days']);
                 $add_seconds = $add_days * 24 * 60 * 60;
             }
             $source_created_on = $source->getCreatedOn();
             //var_dump($source_created_on);
             $milestone_map = array(0 => 0);
             // project milestones
             if ($copy_milestones) {
                 $source_milestones = $source->getAllMilestones();
                 if (is_array($source_milestones)) {
                     foreach ($source_milestones as $source_milestone) {
                         $milestone = new ProjectMilestone();
                         //$milestone->copy($source_milestone);
                         $milestone->setName($source_milestone->getName());
                         $milestone->setDescription($source_milestone->getDescription());
                         if ($shift_dates) {
                             trace(__FILE__, "copy():shift dates");
                             $milestone->setDueDate(DateTimeValueLib::now());
                             $seconds = $source_milestone->getDueDate()->difference($source_created_on);
                             $milestone->getDueDate()->advance($seconds);
                         } else {
                             $milestone->setDueDate($source_milestone->getDueDate());
                         }
                         $milestone->getDueDate()->advance($add_seconds);
                         $milestone->setIsPrivate($source_milestone->getIsPrivate());
                         $milestone->setAssignedToUserId($source_milestone->getAssignedToUserId());
                         $milestone->setAssignedToCompanyId($source_milestone->getAssignedToCompanyId());
                         $milestone->setProjectId($project_id);
                         $milestone->save();
                         $milestone_map[$source_milestone->getId()] = $milestone->getId();
                     }
                     // foreach
                 }
                 // if
             }
             // if
             // project tasks
             if ($copy_tasks) {
                 $source_task_lists = $source->getAllTaskLists();
                 if (is_array($source_task_lists)) {
                     foreach ($source_task_lists as $source_task_list) {
                         $task_list = new ProjectTaskList();
                         //$task_list->copy($source_milestone);
                         $task_list->setName($source_task_list->getName());
                         $task_list->setPriority($source_task_list->getPriority());
                         $task_list->setDescription($source_task_list->getDescription());
                         if ($copy_milestones) {
                             $task_list->setMilestoneId($milestone_map[$source_task_list->getMilestoneId()]);
                         }
                         $task_list->setDueDate($source_task_list->getDueDate());
                         if ($task_list->getDueDate() instanceof DateTimeValue) {
                             if ($shift_dates) {
                                 trace(__FILE__, "copy():task list shift dates");
                                 $task_list->setDueDate(DateTimeValueLib::now());
                                 $seconds = $source_task_list->getDueDate()->difference($source_created_on);
                                 $task_list->getDueDate()->advance($seconds);
                             }
                             $task_list->getDueDate()->advance($add_seconds);
                         }
                         $task_list->setIsPrivate($source_task_list->getIsPrivate());
                         $task_list->setOrder($source_task_list->getOrder());
                         $task_list->setProjectId($project_id);
                         $task_list->save();
                         $source_tasks = $source_task_list->getTasks();
                         if (is_array($source_tasks)) {
                             foreach ($source_tasks as $source_task) {
                                 $task = new ProjectTask();
                                 $task->setOrder($source_task->getOrder());
                                 $task->setDueDate($source_task->getDueDate());
                                 if ($task->getDueDate() instanceof DateTimeValue) {
                                     if ($shift_dates) {
                                         trace(__FILE__, "copy():task shift dates");
                                         $task->setDueDate(DateTimeValueLib::now());
                                         $seconds = $source_task->getDueDate()->difference($source_created_on);
                                         $task->getDueDate()->advance($seconds);
                                     }
                                     $task->getDueDate()->advance($add_seconds);
                                 }
                                 $task->setText($source_task->getText());
                                 $task->getAssignedToUserId($source_task->getAssignedToUserId());
                                 $task->getAssignedToCompanyId($source_task->getAssignedToCompanyId());
                                 $task_list->attachTask($task);
                             }
                         }
                     }
                     // foreach
                 }
                 // if
             }
             // if
             // project messages
             if ($copy_messages) {
                 $source_messages = $source->getAllMessages();
                 if (is_array($source_messages)) {
                     foreach ($source_messages as $source_message) {
                         $message = new ProjectMessage();
                         //$message->copy($source_message);
                         $message->setTitle($source_message->getTitle());
                         $message->setText($source_message->getText());
                         $message->setAdditionalText($source_message->getAdditionalText());
                         if ($copy_milestones) {
                             $message->setMilestoneId($milestone_map[$source_message->getMilestoneId()]);
                         }
                         $message->setIsImportant($source_message->getIsImportant());
                         $message->setIsPrivate($source_message->getIsPrivate());
                         $message->setCommentsEnabled($source_message->getCommentsEnabled());
                         $message->setAnonymousCommentsEnabled($source_message->getAnonymousCommentsEnabled());
                         $message->setProjectId($project_id);
                         $message->save();
                     }
                     // foreach
                 }
                 // if
             }
             // if
             // project links
             if ($copy_links) {
                 $source_links = ProjectLinks::getAllProjectLinks($source);
                 if (is_array($source_links)) {
                     foreach ($source_links as $source_link) {
                         $link = new ProjectLink();
                         //$folder->copy($source_link);
                         $link->setTitle($source_link->getTitle());
                         $link->setUrl($source_link->getUrl());
                         $link->setProjectId($project_id);
                         $link->save();
                     }
                     // foreach
                 }
                 // if
             }
             // if
             // project folders & files
             if ($copy_files) {
                 $folder_map = array(0 => 0);
                 $source_folders = $source->getFolders();
                 if (is_array($source_folders)) {
                     foreach ($source_folders as $source_folder) {
                         $folder = new ProjectFolder();
                         //$folder->copy($source_folder);
                         $folder->setName($source_folder->getName());
                         $folder->setProjectId($project_id);
                         $folder->save();
                         $folder_map[$source_folder->getId()] = $folder->getId();
                     }
                     // foreach
                 }
                 // if
                 $source_files = ProjectFiles::getAllFilesByProject($source);
                 if (is_array($source_files)) {
                     foreach ($source_files as $source_file) {
                         $file = new ProjectFile();
                         $file->setProjectId($project_id);
                         $file->setFolderId($folder_map[$source_file->getFolderId()]);
                         $file->setFileName($source_file->getFileName());
                         $file->setDescription($source_file->getDescription());
                         $file->setIsPrivate($source_file->getIsPrivate());
                         $file->setIsImportant($source_file->getIsImportant());
                         $file->setIsLocked($source_file->getIsLocked());
                         $file->setIsVisible($source_file->getIsVisible());
                         $file->setExpirationTime($source_file->getExpirationTime());
                         $file->setCommentsEnabled($source_file->getCommentsEnabled());
                         $file->setAnonymousCommentsEnabled($source_file->getAnonymousCommentsEnabled());
                         $file->save();
                         $source_revision = $source_file->getLastRevision();
                         if ($source_revision instanceof ProjectFileRevision) {
                             $revision = new ProjectFileRevision();
                             $revision->setFileId($file->getId());
                             $revision->setRevisionNumber($source_revision->getRevisionNumber());
                             $revision->setRepositoryId($source_revision->getRepositoryId());
                             $revision->setFilesize($source_revision->getFilesize());
                             $revision->setFilename($source_revision->getFileName());
                             $revision->setTypeString($source_revision->getTypeString());
                             $revision->setThumbFilename($source_revision->getThumbFilename());
                             $revision->setFileTypeId($source_revision->getFileTypeId());
                             $revision->setComment($source_revision->getComment());
                             $revision->save();
                         }
                     }
                     // foreach
                 }
                 // if
             }
             // if
             if ($copy_pages) {
                 $source_pages = Wiki::getAllProjectPages($source);
                 if (is_array($source_pages)) {
                     foreach ($source_pages as $source_page) {
                         $page = new WikiPage();
                         $page->setProjectId($project_id);
                         $page->setProjectIndex($source_page->getProjectIndex());
                         $page->setProjectSidebar($source_page->getProjectSidebar());
                         if (plugin_active('tags')) {
                             //$page->setTags($source_page->getTagNames());
                         }
                         //Make a new revision of this page
                         $revision = $page->makeRevision();
                         $source_revision = $source_page->getLatestRevision();
                         //Set attributes
                         $revision->setName($source_revision->getName());
                         $revision->setContent($source_revision->getContent());
                         $revision->setLogMessage($source_revision->getLogMessage());
                         //Save the page
                         $page->save();
                     }
                     // foreach
                 }
                 // if
             }
             // if
             if ($copy_users) {
                 $source_companies = ProjectCompanies::instance()->getCompaniesByProject($source);
                 if (is_array($source_companies)) {
                     foreach ($source_companies as $source_company) {
                         $project_company = new ProjectCompany();
                         $project_company->setCompanyId($source_company->getId());
                         $project_company->setProjectId($project_id);
                         $project_company->save();
                     }
                     // foreach
                 }
                 $source_users = ProjectUsers::instance()->getUsersByProject($source);
                 if (is_array($source_users)) {
                     foreach ($source_users as $source_user) {
                         $project_user = new ProjectUser();
                         $project_user->setUserId($source_user->getId());
                         $project_user->setProjectId($project_id);
                         $project_user->save();
                     }
                     // foreach
                 }
             }
             /*
                       $permissions = array_keys(PermissionManager::getPermissionsText());
                       $auto_assign_users = owner_company()->getAutoAssignUsers();
                       
                       // We are getting the list of auto assign users. If current user is not in the list
                       // add it. He's creating the project after all...
                       if (is_array($auto_assign_users)) {
                         $auto_assign_logged_user = false;
                         foreach ($auto_assign_users as $user) {
                           if ($user->getId() == logged_user()->getId()) {
                             $auto_assign_logged_user = true;
                           }
                         } // if
                         if (!$auto_assign_logged_user) {
                           $auto_assign_users[] = logged_user();
                         }
                       } else {
                         $auto_assign_users[] = logged_user();
                       } // if
                       
                       foreach ($auto_assign_users as $user) {
                         $project_user = new ProjectUser();
                         $project_user->setProjectId($project->getId());
                         $project_user->setUserId($user->getId());
                         if (is_array($permissions)) {
                           foreach ($permissions as $permission) {
                             $user = Users::findById($project_user->getUserId());
                             $user->setProjectPermission($project,$permission,true);
                           }
                         } // if
                         $project_user->save();
                       } // foreach
             */
             ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_ADD, false, true);
             DB::commit();
             flash_success(lang('success copy project', $source->getName(), $project->getName()));
             $this->redirectToUrl($project->getPermissionsUrl());
         } catch (Exception $e) {
             echo $e->getMessage();
             tpl_assign('error', $e);
             DB::rollback();
         }
         // try
     }
     // if (submitted)
 }
Example #17
0
 function actionSave($currentUser)
 {
     $backUrl = $this->context->getFlowScopeAttr("backUrl");
     $oldRssKey = null;
     $project = new Project();
     $projectErrs = array();
     $project->setId($this->context->getRequestAttr("id"));
     if (!is_null($project->getId())) {
         $oldProject = $this->projectDao->get($project->getId());
         if (is_null($oldProject) || is_string($oldProject)) {
             $this->context->setRequestScopeAttr("error", "error.dberror");
             if (!is_null($backUrl)) {
                 header("Location: " . $backUrl);
                 return true;
             }
             return false;
         }
     }
     $project->setName($this->context->getRequestAttr("name"));
     if (!is_null($project->getName())) {
         $project->setName(trim($project->getName()));
         if (strlen($project->getName()) < 1) {
             $project->setName(null);
         }
     }
     if (is_null($project->getName())) {
         $projectErrs["name"] = "field.error.empty";
     }
     $project->setDescription($this->context->getRequestAttr("description"));
     if (!is_null($project->getDescription())) {
         $project->setDescription(trim($project->getDescription()));
         if (strlen($project->getDescription()) < 1) {
             $project->setDescription(null);
         }
     }
     $project->setCampaign($this->context->getRequestAttr("campaign"));
     if (!is_null($project->getCampaign())) {
         $project->setCampaign(trim($project->getCampaign()));
         if (strlen($project->getCampaign()) < 1) {
             $project->setCampaign(null);
         }
     }
     $project->setSuspending($this->context->getRequestAttr("suspending"));
     if (!is_null($project->getSuspending())) {
         $project->setSuspending(trim($project->getSuspending()));
         if (strlen($project->getSuspending()) < 1) {
             $project->setSuspending(null);
         }
     }
     $project->setEnding($this->context->getRequestAttr("ending"));
     if (!is_null($project->getEnding())) {
         $project->setEnding(trim($project->getEnding()));
         if (strlen($project->getEnding()) < 1) {
             $project->setEnding(null);
         }
     }
     $move_more = $this->context->getRequestAttr("move_more");
     $project->setMove_more($move_more == 1 ? true : false);
     $timeZone = new DateTimeZone("Europe/Vilnius");
     $time = new DateTime("now", $timeZone);
     $project->setR_date($time->format("Y-m-d H:i:s"));
     $project->setR_user($currentUser->getId());
     if (is_null($project->getId())) {
         $project->setOwner($currentUser->getId());
         $project->setCruid($this->generateCode());
         $project->setPkey($this->generateCode());
         $project->setRsskey($this->generateCode());
     } else {
         $project->setCruid($oldProject->getCruid());
         $project->setRsskey($oldProject->getRssKey());
     }
     $this->context->setFlashScopeAttr("project", $project);
     $this->context->setFlashScopeAttr("projectErrs", $projectErrs);
     if (count($projectErrs) >= 1) {
         if (!is_null($backUrl)) {
             header("Location: " . $backUrl);
             return true;
         }
         return false;
     }
     $store = $this->storeProject($project);
     if (!$store) {
         if (!is_null($backUrl)) {
             header("Location: " . $backUrl);
             return true;
         }
         return false;
     }
     $rss = new Rss($project->getRsskey());
     if (!$rss->storeProjectRssFile($project)) {
         $this->context->setRequestScopeAttr("errortxt", "Nepavyko sukurti/atnaujinti RSS failo!");
     }
     /* Issaugom pasirinktas grupes */
     $groups = $this->context->getRequestAttr("groups");
     $selectedProjects = $this->context->getRequestAttr("selectedProjects");
     if (is_null($selectedProjects) && !is_null($groups)) {
         $this->saveProjectGroups($project->getId(), $groups);
     }
     if (!is_null($selectedProjects) && is_null($groups)) {
         $this->removeProjectFromGroups($currentUser->getId(), $project->getId());
     }
     if (!is_null($selectedProjects) && !is_null($groups)) {
         $toRemove = array_diff(json_decode($selectedProjects), $groups);
         if (count($toRemove) > 0) {
             foreach ($toRemove as $gp) {
                 $this->removeFromGroup($gp, $project->getId());
             }
         }
         $toAdd = array_diff($groups, json_decode($selectedProjects));
         if (count($toAdd) > 0) {
             $this->saveProjectGroups($project->getId(), $toAdd);
         }
     }
     $this->cancelEdit();
     if (!is_null($backUrl)) {
         header("Location: " . $backUrl);
         return true;
     }
     return false;
 }
Example #18
0
function create_user($user_data, $permissionsString)
{
    $user = new User();
    $user->setUsername(array_var($user_data, 'username'));
    $user->setDisplayName(array_var($user_data, 'display_name'));
    $user->setEmail(array_var($user_data, 'email'));
    $user->setCompanyId(array_var($user_data, 'company_id'));
    $user->setType(array_var($user_data, 'type'));
    $user->setTimezone(array_var($user_data, 'timezone'));
    if (!logged_user() instanceof User || can_manage_security(logged_user())) {
        $user->setCanEditCompanyData(array_var($user_data, 'can_edit_company_data'));
        $user->setCanManageSecurity(array_var($user_data, 'can_manage_security'));
        $user->setCanManageWorkspaces(array_var($user_data, 'can_manage_workspaces'));
        $user->setCanManageConfiguration(array_var($user_data, 'can_manage_configuration'));
        $user->setCanManageContacts(array_var($user_data, 'can_manage_contacts'));
        $user->setCanManageTemplates(array_var($user_data, 'can_manage_templates'));
        $user->setCanManageReports(array_var($user_data, 'can_manage_reports'));
        $user->setCanManageTime(array_var($user_data, 'can_manage_time'));
        $user->setCanAddMailAccounts(array_var($user_data, 'can_add_mail_accounts'));
        $other_permissions = array();
        Hook::fire('add_user_permissions', $user, $other_permissions);
        foreach ($other_permissions as $k => $v) {
            $user->setColumnValue($k, array_var($user_data, $k));
        }
    }
    if (array_var($user_data, 'password_generator', 'random') == 'random') {
        // Generate random password
        $password = UserPasswords::generateRandomPassword();
    } else {
        // Validate input
        $password = array_var($user_data, 'password');
        if (trim($password) == '') {
            throw new Error(lang('password value required'));
        }
        // if
        if ($password != array_var($user_data, 'password_a')) {
            throw new Error(lang('passwords dont match'));
        }
        // if
    }
    // if
    $user->setPassword($password);
    $user->save();
    $user_password = new UserPassword();
    $user_password->setUserId($user->getId());
    $user_password->setPasswordDate(DateTimeValueLib::now());
    $user_password->setPassword(cp_encrypt($password, $user_password->getPasswordDate()->getTimestamp()));
    $user_password->password_temp = $password;
    $user_password->save();
    if (array_var($user_data, 'autodetect_time_zone', 1) == 1) {
        set_user_config_option('autodetect_time_zone', 1, $user->getId());
    }
    if ($user->getType() == 'admin') {
        if ($user->getCompanyId() != owner_company()->getId() || logged_user() instanceof User && !can_manage_security(logged_user())) {
            // external users can't be admins or logged user has no rights to create admins => set as Normal
            $user->setType('normal');
        } else {
            $user->setAsAdministrator(true);
        }
    }
    /* create contact for this user*/
    if (array_var($user_data, 'create_contact', 1)) {
        // if contact with same email exists take it, else create new
        $contact = Contacts::getByEmail($user->getEmail(), true);
        if (!$contact instanceof Contact) {
            $contact = new Contact();
            $contact->setEmail($user->getEmail());
        } else {
            if ($contact->isTrashed()) {
                $contact->untrash();
            }
        }
        $contact->setFirstname($user->getDisplayName());
        $contact->setUserId($user->getId());
        $contact->setTimezone($user->getTimezone());
        $contact->setCompanyId($user->getCompanyId());
        $contact->save();
    } else {
        $contact_id = array_var($user_data, 'contact_id');
        $contact = Contacts::findById($contact_id);
        if ($contact instanceof Contact) {
            // user created from a contact
            $contact->setUserId($user->getId());
            $contact->save();
        } else {
            // if contact with same email exists use it as user's contact, without changing it
            $contact = Contacts::getByEmail($user->getEmail(), true);
            if ($contact instanceof Contact) {
                $contact->setUserId($user->getId());
                if ($contact->isTrashed()) {
                    $contact->untrash();
                }
                $contact->save();
            }
        }
    }
    $contact = $user->getContact();
    if ($contact instanceof Contact) {
        // update contact data with data entered for this user
        $contact->setCompanyId($user->getCompanyId());
        if ($contact->getEmail() != $user->getEmail()) {
            // make user's email the contact's main email address
            if ($contact->getEmail2() == $user->getEmail()) {
                $contact->setEmail2($contact->getEmail());
            } else {
                if ($contact->getEmail3() == $user->getEmail()) {
                    $contact->setEmail3($contact->getEmail());
                } else {
                    if ($contact->getEmail2() == "") {
                        $contact->setEmail2($contact->getEmail());
                    } else {
                        $contact->setEmail3($contact->getEmail());
                    }
                }
            }
        }
        $contact->setEmail($user->getEmail());
        $contact->save();
    }
    if (!$user->isGuest()) {
        /* create personal project or assing the selected*/
        //if recived a personal project assing this
        //project as personal project for this user
        $new_project = null;
        $personalProjectId = array_var($user_data, 'personal_project', 0);
        $project = Projects::findById($personalProjectId);
        if (!$project instanceof Project) {
            $project = new Project();
            $wname = new_personal_project_name($user->getUsername());
            $project->setName($wname);
            $wdesc = Localization::instance()->lang(lang('personal workspace description'));
            if (!is_null($wdesc)) {
                $project->setDescription($wdesc);
            }
            $project->setCreatedById($user->getId());
            $project->save();
            //Save to set an ID number
            $project->setP1($project->getId());
            //Set ID number to the first project
            $project->save();
            $new_project = $project;
        }
        $user->setPersonalProjectId($project->getId());
        $project_user = new ProjectUser();
        $project_user->setProjectId($project->getId());
        $project_user->setUserId($user->getId());
        $project_user->setCreatedById($user->getId());
        $project_user->setAllPermissions(true);
        $project_user->save();
        /* end personal project */
    }
    $user->save();
    ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_ADD);
    //TODO - Make batch update of these permissions
    if ($permissionsString && $permissionsString != '') {
        $permissions = json_decode($permissionsString);
    } else {
        $permissions = null;
    }
    if (is_array($permissions) && (!logged_user() instanceof User || can_manage_security(logged_user()))) {
        foreach ($permissions as $perm) {
            if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) {
                if (!$personalProjectId || $personalProjectId != $perm->wsid) {
                    $relation = new ProjectUser();
                    $relation->setProjectId($perm->wsid);
                    $relation->setUserId($user->getId());
                    $relation->setCheckboxPermissions($perm->pc, $user->isGuest() ? false : true);
                    $relation->setRadioPermissions($perm->pr, $user->isGuest() ? false : true);
                    $relation->save();
                }
            }
        }
    }
    // if
    if ($new_project instanceof Project && logged_user() instanceof User && logged_user()->isProjectUser($new_project)) {
        evt_add("workspace added", array("id" => $new_project->getId(), "name" => $new_project->getName(), "color" => $new_project->getColor()));
    }
    // Send notification...
    try {
        if (array_var($user_data, 'send_email_notification')) {
            Notifier::newUserAccount($user, $password);
        }
        // if
    } catch (Exception $e) {
    }
    // try
    return $user;
}
Example #19
0
 public function transformProjects()
 {
     $this->projectKeys = array();
     $dom = DOMDocument::load("tuftsph_jm2db.xml");
     $projects = $dom->getElementsByTagName("projects");
     $total = $projects->length;
     $count = 1;
     echo "Converting Projects \n";
     foreach ($projects as $pr) {
         echo $count . "/" . $total . "\n";
         $count += 1;
         $childNodes = $pr->childNodes;
         $i = array();
         foreach ($childNodes as $child) {
             $i[$child->nodeName] = $child->textContent;
         }
         $p = new Project();
         $p->setName($i["desc"]);
         if ($i["active"]) {
             $p->setStatusId(2);
         } else {
             $p->setStatusId(7);
         }
         $p->save();
         $this->projectKeys[$i["id"]] = $p->getId();
     }
 }
 function testPagination()
 {
     $outlet = Outlet::getInstance();
     $totalRecords = 25;
     for ($i = 0; $i < $totalRecords; $i++) {
         $project = new Project();
         $project->setName('Test Project ' . $i);
         $outlet->save($project);
     }
     $this->assertEquals(10, count($outlet->from('Project')->limit(10)->find()));
     $this->assertEquals(5, count($outlet->from('Project')->limit(10)->offset(20)->find()));
 }
Example #21
0
 public function executeAddProject(sfWebRequest $request)
 {
     $obj = json_decode($request->getParameter("obj"), true);
     $jobs = $obj["jobs"];
     $addProjectId = $obj["addProjectId"];
     $projectName = $obj["projectName"];
     $createNew = $obj["createNew"];
     $removeFromProject = $obj["removeFromProject"];
     if (!$removeFromProject) {
         if ($createNew) {
             $project = new Project();
             $project->setName($projectName);
             $project->save();
         } else {
             $project = ProjectPeer::retrieveByPK($addProjectId);
         }
         $projectId = $project->getId();
     } else {
         $projectId = null;
     }
     if ($removeFromProject || !is_null($projectId)) {
         JobPeer::setJobProjectIds($jobs, $projectId);
     }
     $this->setTemplate("reload");
     if ($this->createCriteria() == sfView::NONE) {
         return sfView::NONE;
     }
 }
 if (strtotime($_POST['from_date']) < strtotime(date('Y-m-d'))) {
     throw new fValidationException('Arrival date must be no earlier than today.');
 }
 // from < max
 if (strtotime($_POST['from_date']) > strtotime("+{$maxStorageMonths} months")) {
     throw new fValidationException('Arrival date must be in the next 6 months.');
 }
 // to > from
 if (strtotime($_POST['to_date']) < strtotime($_POST['from_date'])) {
     throw new fValidationException('Removal date must come after arrival date.');
 }
 // to < max
 if (strtotime($_POST['to_date']) > strtotime("+{$maxStorageMonths} months", strtotime($_POST['from_date']))) {
     throw new fValidationException('Removal date must be 6 months after arrival.');
 }
 $project->setName(filter_var($_POST['name'], FILTER_SANITIZE_STRING));
 $project->setDescription(filter_var($_POST['description'], FILTER_SANITIZE_STRING));
 if ($_POST['contact'] && $_POST['contact'] != '') {
     $project->setContact(filter_var($_POST['contact'], FILTER_SANITIZE_EMAIL));
 } else {
     $project->setContact(null);
 }
 $project->setLocationId(filter_var($_POST['location_id'], FILTER_SANITIZE_STRING));
 $project->setLocation(filter_var($_POST['location'], FILTER_SANITIZE_STRING));
 $project->setFromDate(filter_var($_POST['from_date'], FILTER_SANITIZE_STRING));
 $project->setToDate(filter_var($_POST['to_date'], FILTER_SANITIZE_STRING));
 if (!$project->getId()) {
     $auto = true;
     $logDetails = "Request created";
     $project->setState('Pending Approval');
     $initial = true;
 /**
  * Finish the installation - create owner company and administrator
  *
  * @param void
  * @return null
  */
 function complete_installation()
 {
     if (Companies::getOwnerCompany() instanceof Company) {
         die('Owner company already exists');
         // Somebody is trying to access this method even if the user already exists
     }
     // if
     $form_data = array_var($_POST, 'form');
     tpl_assign('form_data', $form_data);
     if (array_var($form_data, 'submited') == 'submited') {
         try {
             $admin_password = trim(array_var($form_data, 'admin_password'));
             $admin_password_a = trim(array_var($form_data, 'admin_password_a'));
             if (trim($admin_password) == '') {
                 throw new Error(lang('password value required'));
             }
             // if
             if ($admin_password != $admin_password_a) {
                 throw new Error(lang('passwords dont match'));
             }
             // if
             DB::beginWork();
             Users::delete();
             // clear users table
             Companies::delete();
             // clear companies table
             // Create the administrator user
             $administrator = new User();
             $administrator->setId(1);
             $administrator->setCompanyId(1);
             $administrator->setUsername(array_var($form_data, 'admin_username'));
             $administrator->setEmail(array_var($form_data, 'admin_email'));
             $administrator->setPassword($admin_password);
             $administrator->setCanEditCompanyData(true);
             $administrator->setCanManageConfiguration(true);
             $administrator->setCanManageSecurity(true);
             $administrator->setCanManageWorkspaces(true);
             $administrator->setCanManageContacts(true);
             $administrator->setCanManageTemplates(true);
             $administrator->setCanManageReports(true);
             $administrator->setCanManageTime(true);
             $administrator->setCanAddMailAccounts(true);
             $administrator->setAutoAssign(false);
             $administrator->setPersonalProjectId(1);
             $administrator->setType('admin');
             $administrator->save();
             $group = new Group();
             $group->setName('administrators');
             $group->setAllPermissions(true);
             $group->setId(Group::CONST_ADMIN_GROUP_ID);
             $group->save();
             $group_user = new GroupUser();
             $group_user->setGroupId(Group::CONST_ADMIN_GROUP_ID);
             $group_user->setUserId($administrator->getId());
             $group_user->save();
             $project = new Project();
             $project->setId(1);
             $project->setP1(1);
             $project->setName(new_personal_project_name($administrator->getUsername()));
             $project->setDescription(lang('files'));
             $project->setCreatedById($administrator->getId());
             $project->save();
             $project_user = new ProjectUser();
             $project_user->setProjectId($project->getId());
             $project_user->setUserId($administrator->getId());
             $project_user->setCreatedById($administrator->getId());
             $project_user->setAllPermissions(true);
             $project_user->save();
             // Create a company
             $company = new Company();
             $company->setId(1);
             $company->setClientOfId(0);
             $company->setName(array_var($form_data, 'company_name'));
             $company->setCreatedById(1);
             $company->save();
             DB::commit();
             $this->redirectTo('access', 'login');
         } catch (Exception $e) {
             tpl_assign('error', $e);
             DB::rollback();
         }
         // try
     }
     // if
 }