Ejemplo n.º 1
0
 public function actionIndex()
 {
     $type = Type::model()->findAll();
     $skill = Skill::model()->findAll();
     $usr = User::model()->findbyPk(1);
     $criteria = new CDbCriteria();
     $criteria->select = '*';
     $criteria->order = 'rand()';
     $total = Portfolio::model()->count();
     $pages = new CPagination($total);
     $pages->pageSize = 10;
     $pages->applyLimit($criteria);
     $port = Portfolio::model()->findAll($criteria);
     $this->render('index', array('type' => $type, 'port' => $port, 'pages' => $pages, 'skill' => $skill, 'usr' => $usr));
 }
Ejemplo n.º 2
0
 function setUpRelationalModel()
 {
     $parentDocs = array(array('username' => 'sam', 'job_title' => 'awesome guy'), array('username' => 'john', 'job_title' => 'co-awesome guy'), array('username' => 'dan', 'job_title' => 'programmer'), array('username' => 'lewis', 'job_title' => 'programmer'), array('username' => 'ant', 'job_title' => 'programmer'));
     $childDocs = array(array('name' => 'jogging'), array('name' => 'computers'), array('name' => 'biking'), array('name' => 'drinking'), array('name' => 'partying'), array('name' => 'cars'));
     $docsLinkedByDBRef = array(array('name' => 'python'), array('name' => 'java'), array('name' => 'php'), array('name' => 'lisp'), array('name' => 'C'), array('name' => 'Objective C'), array('name' => 'C++'), array('name' => 'ruby'));
     foreach (array(array('class' => 'Interest', 'data' => $childDocs), array('class' => 'Skill', 'data' => $docsLinkedByDBRef)) as $subgroup) {
         foreach ($subgroup['data'] as $doc) {
             $i = new $subgroup['class']();
             foreach ($doc as $k => $v) {
                 $i->{$k} = $v;
             }
             $this->assertTrue($i->save());
         }
     }
     // Lets make sure those child docs actually went in
     $skills = iterator_to_array(Skill::model()->find());
     $this->assertTrue(count($skills) > 0);
     $c = Interest::model()->find();
     $this->assertTrue($c->count() > 0);
     // Let's build an array of the all the _ids of the child docs
     $interest_ids = array();
     foreach ($c as $row) {
         $interest_ids[] = $row->_id;
     }
     // Create the users with each doc having the value of the interest ids
     $user_ids = array();
     foreach ($parentDocs as $doc) {
         $u = new User();
         foreach ($doc as $k => $v) {
             $u->{$k} = $v;
         }
         $u->interests = $interest_ids;
         //Let`s take random skill as primary for this user
         $primarySkill = $skills[array_rand($skills)]->_id;
         $u->mainSkill = MongoDBRef::create(Skill::model()->collectionName(), $primarySkill);
         //Now, lets pick array of secondary skills
         $allSecondarySkills = array();
         foreach (array_rand($skills, rand(3, 5)) as $secondarySkill) {
             if ($secondarySkill == $primarySkill) {
                 continue;
             }
             array_push($allSecondarySkills, MongoDBRef::create(Skill::model()->collectionName(), $skills[$secondarySkill]->_id));
         }
         $u->otherSkills = $allSecondarySkills;
         $this->assertTrue($u->save());
         $user_ids[] = $u->_id;
     }
     $interests = array_values(iterator_to_array($c));
     // Now 50^6 times re-insert each interest with a parnt user _id
     // So we have two forms of the document in interests, one without the parent user and one with
     for ($i = 0; $i < 50; $i++) {
         $randInt = rand(0, sizeof($interests) - 1);
         $row = $interests[$randInt];
         $randPos = rand(0, sizeof($user_ids) - 1);
         $row->i_id = $user_ids[$randPos];
         $row->setIsNewRecord(true);
         $row->_id = null;
         $row->setScenario('insert');
         $this->assertTrue($row->save());
     }
     // we will assume the set up was successful and we will leave it to further testing to see
     // whether it really was.
 }
Ejemplo n.º 3
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Skill the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Skill::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }