include __DIR__ . '/vendor/autoload.php';
class Another extends \Illuminate\Database\Eloquent\Model
{
    public $attributes = ['name' => 'John Smith'];
}
class Sample extends \Illuminate\Database\Eloquent\Model
{
    use \SilvertipSoftware\LaravelTraitPack\HasDynamicAttributes;
    protected $metaSample;
    public function getTraditionalAttribute($value)
    {
        return "ABC";
    }
}
Sample::addDynamicAttribute('sample', function () {
    // simple retrieval for sample. real world attrs would do much more
    return isset($this->metaSample) ? $this->metaSample : null;
}, function ($value) {
    // simple setting for sample. real world attrs would do much more
    $this->metaSample = $value . '_dynamic';
});
Sample::addDynamicMethod('tags', function () {
    return $this->belongsTo('Another');
});
$obj = new Sample();
$obj->name = "Bob";
$obj->sample = '1234';
$obj->setRelation('tags', new \Illuminate\Database\Eloquent\Collection([new Another()]));
echo $obj->sample . "\n";
echo $obj->toJSON() . "\n";
echo implode(', ', $obj->getMutatedAttributes()) . "\n";
Exemplo n.º 2
0
 /**
  * @see SampleSecurityInterface::is_access()
  * @param integer $intention 1 = Read, 2 = Write
  * @param bool $ignore_admin_status
  * @return bool
  */
 public function is_access($intention, $ignore_admin_status = false)
 {
     global $user;
     if ($this->sample_id) {
         if ($user->is_admin() and $ignore_admin_status == false) {
             return true;
         } else {
             $sample = new Sample($this->sample_id);
             $sample_folder_id = SampleFolder::get_folder_by_sample_id($this->sample_id);
             $sample_folder_data_entity = new DataEntity(Folder::get_data_entity_id_by_folder_id($sample_folder_id));
             if ($sample->get_owner_id() == $user->get_user_id()) {
                 return true;
             } else {
                 $pk = SampleHasUser_Access::get_entry_by_sample_id_and_user_id($this->sample_id, $user->get_user_id());
                 $sample_has_user = new SampleHasUser_Access($pk);
                 if ($intention == 1) {
                     if ($sample_has_user->get_read() == true) {
                         return true;
                     } else {
                         $organisation_unit_array = OrganisationUnit::list_entries_by_user_id($user->get_user_id());
                         if (is_array($organisation_unit_array) and count($organisation_unit_array) >= 1) {
                             foreach ($organisation_unit_array as $key => $value) {
                                 $pk = SampleHasOrganisationUnit_Access::get_entry_by_sample_id_and_organisation_unit_id($this->sample_id, $value);
                                 if (is_numeric($pk)) {
                                     return true;
                                 }
                             }
                         }
                         /*
                         	    					$parent_virtual_folder_array = $sample_folder_data_entity->get_parent_virtual_folder_ids();
                         	    					
                         	    					if (is_array($parent_virtual_folder_array) and count($parent_virtual_folder_array) >= 1)
                         	    					{
                         	    						foreach($parent_virtual_folder_array as $key => $value)
                         	    						{
                         	    							$virtual_folder = new VirtualFolder($value);
                         	    							$parent_folder_id = $virtual_folder->get_parent_folder_id();
                         	    							$folder = Folder::get_instance($parent_folder_id);
                         	    							if ($folder->is_read_access() == true)
                         	    							{
                         	    								return true;
                         	    							}
                         	    						}
                         	    					} */
                         return false;
                     }
                 } else {
                     if ($sample_has_user->get_write() == true) {
                         return true;
                     } else {
                         return false;
                     }
                 }
             }
         }
     } else {
         return null;
     }
 }
Exemplo n.º 3
0
 public function insert(Sample $sample)
 {
     if ($this->length) {
         $sample->setDiff($this->samples[$this->length - 1]);
     }
     $this->samples[] = $sample;
     $this->length++;
 }
Exemplo n.º 4
0
 public function getSavesample()
 {
     // DB::table('sample')->insert(array('name'=>"jeth"));
     $sample = new Sample();
     $sample->name = "jimbo";
     $sample->save();
     return "inserted";
 }
Exemplo n.º 5
0
 public function testSayHello()
 {
     $sample = new Sample();
     $name = 'Chris';
     $replace = 'Goodbye, Chris!';
     SomeclassMock::expects($name, $replace);
     $this->assertEquals("Goodbye, Chris!", $sample->sayHello($name));
     SomeclassMock::cleanup();
 }
Exemplo n.º 6
0
 public function __construct()
 {
     $sample = new Sample('id', 'name');
     $id = $sample->getId();
     if ($id = 'id') {
         echo 'if';
     } else {
         echo 'else';
     }
 }
Exemplo n.º 7
0
  public function testNewArrayIsEmpty()
  {
    // 配列を作成します。
    $fixture = array();

    // 配列のサイズは 0 です。
    $this->assertEquals(0, sizeof($fixture));

    $hoge = new Sample();
    $user = $hoge->first_user();
    $this->assertEquals(1, $user["id"]);
  }
Exemplo n.º 8
0
 /**
  * @Then name of id :arg1 should be :arg2
  */
 public function nameOfIdShouldBe($arg1, $arg2)
 {
     $data = new Sample();
     $rows = $data->get_name($arg1);
     //      print_r( $rows);
     if (sizeof($rows) != 1) {
         throw new Exception("Name is not present.\n");
     } else {
         if ($rows[0]['name'] != $arg2) {
             throw new Exception("Name did not match.\n");
         }
     }
 }
Exemplo n.º 9
0
 public function postStore()
 {
     $postData = Input::all();
     $rules = array('userName' => 'required|min:5', 'userEmail' => 'required|email', 'userMobile' => 'required|min:10|numeric', 'userAddress1' => 'required', 'userAddress2' => 'required', 'userPincode' => 'required|min:6|numeric', 'userCity' => 'required', 'userState' => 'required', 'userId' => 'required|alphanum');
     $validator = Validator::make($postData, $rules);
     if ($validator->fails()) {
         return Redirect::to('admin/profile')->withInput()->withErrors($validator);
     } else {
         if (Input::has('userKey')) {
             $rulespass = array('userKey' => 'required|min:6|alphanum', 'cpass' => 'required|min:6|same:userKey');
             $validator1 = Validator::make($postData, $rulespass);
             if ($validator1->fails()) {
                 return Redirect::to('admin/profile')->withInput()->withErrors($validator1);
             } else {
                 $input = json_encode(Input::except('_token', 'cpass'));
                 $update = Sample::update($input);
                 //print_r($update);exit;
                 if ($update && $update->status == "success") {
                     return Redirect::to('admin/profile')->with('success', $update->message);
                 } else {
                     return Redirect::to('admin/profile')->with('failure', "something went wrong");
                 }
             }
         } else {
             $input = json_encode(Input::except('_token', 'userKey', 'cpass'));
             $update = Sample::update($input);
             //print_r($update);exit;
             if ($update && $update->status == "success") {
                 return Redirect::to('admin/profile')->with('success', $update->message);
             } else {
                 return Redirect::to('admin/profile')->with('failure', "something went wrong");
             }
         }
     }
 }
Exemplo n.º 10
0
 /**
  * 
  * @param \Sooh\Base\Rpc\Broker $rpcOnNew
  * @return CheckinBook
  */
 public static function getInstance($rpcOnNew = null)
 {
     if (self::$_instance === null) {
         self::$_instance = new CheckinBook();
         self::$_instance->rpc = $rpcOnNew;
     }
     return self::$_instance;
 }
 public static function getProfile()
 {
     $userdata = Sample::user(Session::get('user_id'));
     if ($userdata && $userdata->status == "success") {
         //return View::make('superadmin.editview')->with('userdata',$userdata);
     } else {
         return View::make('superadmin.service');
     }
 }
 private function renderSample(MetricFamilySamples $metric, Sample $sample)
 {
     $escapedLabels = array();
     $labelNames = $metric->getLabelNames();
     if ($metric->hasLabelNames() || $sample->hasLabelNames()) {
         $labels = array_combine(array_merge($labelNames, $sample->getLabelNames()), $sample->getLabelValues());
         foreach ($labels as $labelName => $labelValue) {
             $escapedLabels[] = $labelName . '="' . $this->escapeLabelValue($labelValue) . '"';
         }
         return $sample->getName() . '{' . implode(',', $escapedLabels) . '} ' . $sample->getValue();
     }
     return $sample->getName() . ' ' . $sample->getValue();
 }
Exemplo n.º 13
0
 public function run()
 {
     echo 'Massive Run for samples';
     $biobanks = Biobank::model()->findAll();
     foreach ($biobanks as $biobank) {
         $modifier = new EMongoModifier();
         $modifier->addModifier('biobank_id', 'set', (string) $biobank->_id);
         $criteria = new EMongoCriteria();
         $criteria->biobank_id = $biobank->id;
         $status = Sample::model()->updateAll($modifier, $criteria);
         $criteriaAfter = new EMongoCriteria();
         $criteriaAfter->biobank_id = (string) $biobank->_id;
         $count = Sample::model()->count($criteriaAfter);
         echo "Done for biobank {$biobank->_id} - {$biobank->name} : {$count}\n";
     }
 }
 public function postCreate()
 {
     $input = json_encode(Input::except('_token'));
     //print_r($input); exit;
     $op = Sample::creditdebit($input);
     $output = json_decode($op);
     if (isset($output->status)) {
         if ($output->status == 'failure') {
             return Redirect::to('admin/creditdebit/add')->with('failure', $output->message);
         } else {
             return Redirect::to('admin/creditdebit')->with('sucess', $output->message);
         }
     } else {
         return Redirect::to('admin/creditdebit/add')->with('failure', 'sorry., Please try again later');
     }
 }
Exemplo n.º 15
0
 public function run()
 {
     /*$faker = Faker::create();
     
     		foreach(range(1, 10) as $index)
     		{
     			Sample::create([
     
     			]);
     		}*/
     Sample::create(['code' => '158-52C-A', 'stock' => 5]);
     Sample::create(['code' => '158-52C-B', 'stock' => 5]);
     Sample::create(['code' => '158-52C-C', 'stock' => 5]);
     Sample::create(['code' => '158-52C-D', 'stock' => 5]);
     Sample::create(['code' => '158-52C-E', 'stock' => 5]);
 }
 public static function getRetailerprod($admin)
 {
     $userdata = Sample::category($admin);
     //$userdata=json_decode($senddata);
     //print_r($userdata);exit;
     $category = $userdata->categories;
     $products = $userdata->products;
     foreach ($category as $categories) {
         echo "<li class='parent-list'><input type='checkbox' name=''  class='canine parent' />" . $categories->fullName . " <i class='fa fa-arrow-down'></i><ul>";
         foreach ($products as $product) {
             if ($product->catgCode == $categories->catgCode) {
                 echo "<li><input type='checkbox' name='prodCode[]' class='canine' id='' value='" . $product->prodCode . "'/>" . $product->fullName . "</li>";
             }
         }
         echo "</ul></li>";
     }
 }
Exemplo n.º 17
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     $model = $this->loadModel($id);
     $name = $model->name;
     $sampleCount = Sample::model()->countByAttributes(array('biobank_id' => (string) $model->id));
     $adminCount = User::model()->countByAttributes(array('biobank_id' => (string) $model->_id));
     if ($adminCount == 0 && $sampleCount == 0) {
         try {
             $model->delete();
             Yii::app()->user->setFlash('success', 'La biobanque a bien été supprimée.');
         } catch (Exception $ex) {
             Yii::app()->user->setFlash('error', 'La biobanque n\'a pas pu être supprimée : ' . $ex->getMessage());
         }
     } else {
         $message = "Suppression de la biobanque \"{$name}\" impossible : ";
         if ($adminCount > 0) {
             $message .= "<br> - Il reste {$adminCount} administrateur(s) lié(s) à la biobanque.";
         }
         if ($sampleCount > 0) {
             $message .= "<br> reste {$sampleCount} échantillon(s) lié(s) à la biobanque.";
         }
         Yii::app()->user->setFlash('error', $message);
     }
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax'])) {
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
     } else {
         $flashMessages = Yii::app()->user->getFlashes();
         $flashMessagesHtml = '';
         if ($flashMessages) {
             foreach ($flashMessages as $key => $message) {
                 $flashMessagesHtml .= '<br><div class="flash-' . $key . '">' . $message . "</div>";
             }
         }
         echo $flashMessagesHtml;
     }
 }
Exemplo n.º 18
0
 /**
  * Creates a new Sample Folder including Folder
  * @param integer $sample_id
  * @return integer
  */
 public function create($sample_id)
 {
     if (is_numeric($sample_id)) {
         $sample = new Sample($sample_id);
         // Folder
         $sample_folder_id = constant("SAMPLE_FOLDER_ID");
         $folder = new Folder($sample_folder_id);
         $path = new Path($folder->get_path());
         $path->add_element($sample_id);
         $name = $sample->get_name() . " (" . $sample->get_formatted_id() . ")";
         if (($folder_id = parent::create($name, $sample_folder_id, $path->get_path_string(), $sample->get_owner_id(), null)) != null) {
             $sample_has_folder_access = new SampleHasFolder_Access(null);
             if ($sample_has_folder_access->create($sample_id, $folder_id) == null) {
                 return null;
             }
             // Virtual Folders (Event)
             $sample_folder_create_event = new SampleFolderCreateEvent($folder_id);
             $event_handler = new EventHandler($sample_folder_create_event);
             if ($event_handler->get_success() == false) {
                 $this->delete();
                 return false;
             } else {
                 return $folder_id;
             }
         } else {
             return null;
         }
     } else {
         return null;
     }
 }
Exemplo n.º 19
0
<?php

/*------------------------------------------------------------------------
# com_citruscart
# ------------------------------------------------------------------------
# author   Citruscart Team  - Citruscart http://www.citruscart.com
# copyright Copyright (C) 2014 Citruscart.com All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://citruscart.com
# Technical Support:  Forum - http://citruscart.com/forum/index.html
# Fork of Tienda
# @license GNU/GPL  Based on Tienda by Dioscouri Design http://www.dioscouri.com.
-------------------------------------------------------------------------*/
/** ensure this file is being included by a parent file */
defined('_JEXEC') or die('Restricted access');
Sample::load('SampleTable', 'tables._base');
class SampleTableConfig extends SampleTable
{
    function SampleTableConfig(&$db)
    {
        $tbl_key = 'config_name';
        $tbl_suffix = 'config';
        $this->set('_suffix', $tbl_suffix);
        $name = "sample";
        parent::__construct("#__{$name}_{$tbl_suffix}", $tbl_key, $db);
    }
    function store($updateNulls = true)
    {
        $k = 'config_id';
        if (intval($this->{$k}) > 0) {
            $ret = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key);
Exemplo n.º 20
0
        <?php 
echo CHtml::activeDropDownList($model, 'dataset_id', CHtml::listData(Util::getDois(), 'id', 'identifier'));
?>
		<?php 
echo $form->error($model, 'dataset_id');
?>
				</div>
	</div>

	<div class="control-group">
		<?php 
echo $form->labelEx($model, 'sample_id', array('class' => 'control-label'));
?>
				<div class="controls">
        <?php 
echo CHtml::activeDropDownList($model, 'sample_id', CHtml::listData(Sample::model()->findAll(), 'id', 'id'));
?>
		<?php 
echo $form->error($model, 'sample_id');
?>
				</div>
	</div>

	<div class="row buttons">
        <a href="/adminDatasetSample/admin" class="btn">Cancel</a>
		<?php 
echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class' => 'btn'));
?>
	</div>

<?php 
Exemplo n.º 21
0
 public function getData()
 {
     $data = parent::getData();
     return $data->number;
 }
Exemplo n.º 22
0
     }

     #logo {
       width: 268px;
       height: 55px;
     }
    </style>
  </head>
  <body>
    <div id="container">
      <img src="reinvent.png" id="logo" alt="AWS re:Invent">
      <h1>Application Lifecycle Management Bootcamp</h1>
      <p>
	<?php 
require_once 'src/Sample.php';
$obj = new Sample();
echo $obj->helloWorld();
?>
      </p>
      <?php 
$instance_id = file_get_contents("http://169.254.169.254/latest/meta-data/instance-id");
$local_ipv4 = file_get_contents("http://169.254.169.254/latest/meta-data/local-ipv4");
$instance_type = file_get_contents("http://169.254.169.254/latest/meta-data/instance-type");
$article = "a";
switch (substr($instance_type, 0, 1)) {
    case "m":
    case "r":
    case "i":
    case "h":
        $article = "an";
        break;
Exemplo n.º 23
0
 /**
  * testBehaviorSaveCallbacks method
  *
  * @access public
  * @return void
  */
 function testBehaviorSaveCallbacks()
 {
     $Sample = new Sample();
     $record = array('Sample' => array('apple_id' => 6, 'name' => 'sample99'));
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'on'));
     $Sample->create();
     $this->assertIdentical($Sample->save($record), false);
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'off'));
     $Sample->create();
     $this->assertIdentical($Sample->save($record), $record);
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'test'));
     $Sample->create();
     $this->assertIdentical($Sample->save($record), $record);
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'modify'));
     $expected = Set::insert($record, 'Sample.name', 'sample99 modified before');
     $Sample->create();
     $this->assertIdentical($Sample->save($record), $expected);
     $Sample->Behaviors->disable('Test');
     $this->assertIdentical($Sample->save($record), $record);
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'on'));
     $expected = Set::merge($record, array('Sample' => array('aftersave' => 'modified after on create')));
     $Sample->create();
     $this->assertIdentical($Sample->save($record), $expected);
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify'));
     $expected = Set::merge($record, array('Sample' => array('name' => 'sample99 modified before modified after on create')));
     $Sample->create();
     $this->assertIdentical($Sample->save($record), $expected);
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'test'));
     $Sample->create();
     $this->assertIdentical($Sample->save($record), $record);
     $Sample->Behaviors->attach('Test', array('afterSave' => 'test2'));
     $Sample->create();
     $this->assertIdentical($Sample->save($record), $record);
     $Sample->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'off'));
     $Sample->recursive = -1;
     $record2 = $Sample->read(null, 1);
     $Sample->Behaviors->attach('Test', array('afterSave' => 'on'));
     $expected = Set::merge($record2, array('Sample' => array('aftersave' => 'modified after')));
     $Sample->create();
     $this->assertIdentical($Sample->save($record2), $expected);
     $Sample->Behaviors->attach('Test', array('afterSave' => 'modify'));
     $expected = Set::merge($record2, array('Sample' => array('name' => 'sample1 modified after')));
     $Sample->create();
     $this->assertIdentical($Sample->save($record2), $expected);
 }
Exemplo n.º 24
0
//自定义致命错误处理
function shutdownHandler()
{
    if (is_null($e = error_get_last()) === false) {
        errorHandler($e['type'], $e['message'], $e['file'], $e['line']);
    }
}
//$a['bbb'];
echo $a;
echo 100 / 0;
//$a + $b;
class Sample
{
    public function method()
    {
        //not static method
    }
}
Sample::method();
new Dummy();
throw new Exception('Uncaught Exception');
echo "Not Executed\n";
exit;
$arr1 = [1, 2, 3];
$arr2 = [3, 4];
$diff = array_diff($arr2, $arr1);
//if(empty(array_diff($arr2, $arr1))) {
//    echo '为空!';
//} else {
//    echo '不为空!';
//}
Exemplo n.º 25
0
if ($stats != null) {
    $complete = $stats->globalRate;
} else {
    $complete = 0;
}
$roundcomplete = round($complete);
$uncomplete = 100 - $roundcomplete;
$data = array(array('Complet : ' . $roundcomplete . '%', $roundcomplete), array('Incomplet : ' . $uncomplete . "%", $uncomplete));
$this->beginWidget('zii.widgets.CPortlet', array('title' => "<i class = 'icon-adjust'></i> " . Yii::t('myBiobank', 'samplesCompletionRate') . " -  {$model->identifier}"));
// affichage du graphe de completude des echantillons
$this->widget('application.widgets.charting.CPieChartWidget', array('id' => 'piechart-collab', 'theme' => 'WatersEdge', 'width' => 380, 'height' => 250, 'data' => $data, 'title' => '<a class="detail-button" href="#">détails</a>'));
$this->endWidget();
?>
    </div>

    <!-- affichage du tableau de stats detaillées -->
    <div style="float: left; width: 330px; padding-left: 10px; padding-top: 10px; display: none" class="detail_tab">
        <h4><b>Détails des taux de complétude.</b></h4>
        <?php 
if ($stats != null) {
    foreach ($stats->values as $valueName => $value) {
        $attributes[] = array('label' => Sample::model()->getAttributeLabel($valueName), 'value' => $value . '%');
    }
    $this->widget('zii.widgets.CDetailView', array('data' => $stats->values, 'attributes' => $attributes));
    ?>
        </div>
    </div>
    <div style="clear: both;" />

    <?php 
}
Exemplo n.º 26
0
 function __construct()
 {
     $this->field = 'time';
     $this->table = 'plugin_docman_log';
     parent::Sample();
 }
Exemplo n.º 27
0
 /**
  * testBehaviorSaveCallbacks method
  *
  * @return void
  */
 public function testBehaviorSaveCallbacks()
 {
     $Sample = new Sample();
     $record = array('Sample' => array('apple_id' => 6, 'name' => 'sample99'));
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'on'));
     $Sample->create();
     $this->assertSame(false, $Sample->save($record));
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'off'));
     $Sample->create();
     $result = $Sample->save($record);
     $expected = $record;
     $expected['Sample']['id'] = $Sample->id;
     $this->assertSame($expected, $result);
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'test'));
     $Sample->create();
     $result = $Sample->save($record);
     $expected = $record;
     $expected['Sample']['id'] = $Sample->id;
     $this->assertSame($expected, $result);
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'modify'));
     $expected = Hash::insert($record, 'Sample.name', 'sample99 modified before');
     $Sample->create();
     $result = $Sample->save($record);
     $expected['Sample']['id'] = $Sample->id;
     $this->assertSame($expected, $result);
     $Sample->Behaviors->disable('Test');
     $this->assertSame($record, $Sample->save($record));
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'on'));
     $expected = Hash::merge($record, array('Sample' => array('aftersave' => 'modified after on create')));
     $Sample->create();
     $result = $Sample->save($record);
     $expected['Sample']['id'] = $Sample->id;
     $this->assertEquals($expected, $result);
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify'));
     $expected = Hash::merge($record, array('Sample' => array('name' => 'sample99 modified before modified after on create')));
     $Sample->create();
     $result = $Sample->save($record);
     $expected['Sample']['id'] = $Sample->id;
     $this->assertSame($expected, $result);
     $Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'test'));
     $Sample->create();
     $expected = $record;
     unset($expected['Sample']['name']);
     $result = $Sample->save($record);
     $expected['Sample']['id'] = $Sample->id;
     $this->assertSame($expected, $result);
     $Sample->Behaviors->attach('Test', array('afterSave' => 'test2'));
     $Sample->create();
     $expected = $record;
     $result = $Sample->save($record);
     $expected['Sample']['id'] = $Sample->id;
     $this->assertSame($expected, $result);
     $Sample->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'off'));
     $Sample->recursive = -1;
     $record2 = $Sample->read(null, 1);
     $Sample->Behaviors->attach('Test', array('afterSave' => 'on'));
     $expected = Hash::merge($record2, array('Sample' => array('aftersave' => 'modified after')));
     $Sample->create();
     $this->assertSame($expected, $Sample->save($record2));
     $Sample->Behaviors->attach('Test', array('afterSave' => 'modify'));
     $expected = Hash::merge($record2, array('Sample' => array('name' => 'sample1 modified after')));
     $Sample->create();
     $this->assertSame($expected, $Sample->save($record2));
 }
Exemplo n.º 28
0
 public function testHelloWorld()
 {
     $obj = new Sample();
     $this->assertTrue($obj->helloWorld() == "Hello! Je m'eclate encore plus...");
 }
Exemplo n.º 29
0
 protected static function analyzeCsv($bytes, $biobank_id, $fileImportedId, $add)
 {
     $import = fopen(CommonTools::data_uri($bytes, 'text/csv'), 'r');
     $row = 1;
     $keysArray = array();
     $listBadSamples = array();
     $newSamples = array();
     //        $tempSaveList = new MongoInsertBatch(Sample::model()->getCollection());
     $tempSaveList = array();
     /**
      * Version 1 : Les champs non repertorés sont ajoutés en notes
      */
     while (($data = fgetcsv($import, 1000, ",")) !== FALSE) {
         /*
          * Traitement de la ligne d'entete
          */
         if ($row == 1) {
             foreach ($data as $key => $value) {
                 if ($value != null && $value != "") {
                     $keysArray[$key] = $value;
                 }
             }
         } else {
             $model = new Sample();
             $model->disableBehavior('LoggableBehavior');
             $model->_id = new MongoId();
             while (!$model->validate(array('_id'))) {
                 $model->_id = new MongoId();
             }
             $model->biobank_id = $biobank_id;
             $model->file_imported_id = $fileImportedId;
             foreach ($keysArray as $key2 => $value2) {
                 if ($value2 != "biobank_id" && $value2 != "file_imported_id") {
                     if (in_array($value2, Sample::model()->attributeNames())) {
                         $model->{$value2} = $data[$key2];
                         if (!$model->validate(array($value2))) {
                             //   Yii::log("Problem with item" . $model->getAttributeLabel($value2) . ",set to null.\n " . implode(", ", $model->errors[$value2]), CLogger::LEVEL_ERROR);
                             $model->{$value2} = null;
                         }
                     } else {
                         $note = new Note();
                         $note->key = $value2;
                         $note->value = $data[$key2];
                         $model->notes[] = $note->attributes;
                     }
                 }
             }
             if (!$model->validate()) {
                 Yii::log("Problem with sample validation " . print_R($model->errors, true), CLogger::LEVEL_ERROR);
                 $listBadSamples[] = $row;
             } else {
                 $tempSaveList[] = $model->attributes;
                 //                        $tempSaveList->add($model->attributes);
                 $newSamples[] = $model->_id;
             }
         }
         $row++;
         if ($row != 2 && $row % 400 == 2) {
             Yii::log("Nb treated : " . $row, 'error');
             Sample::model()->getCollection()->batchInsert($tempSaveList, array());
             $tempSaveList = array();
             //$tempSaveList->execute(array());
             //$tempSaveList = new MongoInsertBatch(Sample::model()->getCollection());
         }
     }
     Sample::model()->getCollection()->batchInsert($tempSaveList, array("w" => 1));
     /*
      * Version 2 : seuls nes champs dont la colonne est annotée avec le préfixe 'notes' sont pris en note
      */
     //        while (($data = fgetcsv($import, 1000, ",")) !== FALSE) {
     //
     //            /*
     //             * Traitement de la ligne d'entete
     //             */
     //
     //
     //
     //            if ($row == 1) {
     //                foreach ($data as $key => $value) {
     //                    if (in_array($value, Sample::model()->attributeNames())) {
     //                        $keysArray[$key] = $value;
     //                    } elseif (substr($value, 0, 5) == 'notes') {
     //                        $keysArray[$key] = $value;
     //                    }
     //                }
     //                /*
     //                 * Traitement des lignes de données
     //                 */
     //            } else {
     //                $model = new Sample();
     //                $model->disableBehavior('LoggableBehavior');
     //                $model->biobank_id = $biobank_id;
     //                $model->file_imported_id = $fileImportedId;
     //                foreach ($keysArray as $key2 => $value2) {
     //                    if (substr($value2, 0, 5) != 'notes') {
     //
     //                        $model->$value2 = $data[$key2];
     //                        if (!$model->validate($value2)) {
     //
     //                            Yii::log("Problem with item" . $model->getAttributeLabel($value2) . ",set to null.", CLogger::LEVEL_ERROR);
     //                            $model->$value2 = null;
     //                        }
     //                    } else {
     //
     //                        $noteKey = end(explode(':', $value2));
     //                        $note = new Note();
     //                        $note->key = $noteKey;
     //                        $note->value = $data[$key2];
     //                        $model->notes[] = $note;
     //                    }
     //                }
     //
     //                if (!$model->save()) {
     //                    $listBadSamples[] = $row;
     //                } else {
     //                    $newSamples[] = $model->_id;
     //                }
     //            }
     //            $row++;
     //        }
     fclose($import);
     if (!$add && count($newSamples) > 0) {
         $deleteCriteria = new EMongoCriteria();
         $deleteCriteria->biobank_id('==', $biobank_id);
         $deleteCriteria->_id('notIn', $newSamples);
         Sample::model()->deleteAll($deleteCriteria);
     }
     if (count($listBadSamples) != 0) {
         $log = '';
         foreach ($listBadSamples as $badSample) {
             $log = 'Error with manual import. File id : ' . $fileImportedId . ' - line : ' . $badSample;
             Yii::log($log, CLogger::LEVEL_ERROR);
         }
     }
     return count($listBadSamples);
 }
Exemplo n.º 30
0
 public function loadEchModel($id)
 {
     $model = Sample::model()->findByPk(new MongoID($id));
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }