-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIdentity.php
More file actions
69 lines (61 loc) · 2.24 KB
/
Identity.php
File metadata and controls
69 lines (61 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Created by PhpStorm.
* User: davidamackenzie
* Date: 9/29/18
* Time: 2:17 PM
*/
class Identity extends DBObject {
static $tableName = 'identities';
static $columns = [
'id'=>['name'=>'id','primary_key'=>true],
'profile_id'=>['name'=>'profile_id','foreign_key'=>true,'foreign_table'=>Profile::class],
'dimension_id'=>['name'=>'dimension_id','foreign_key'=>true,'foreign_table'=>Dimension::class],
'yesNo'=>['name'=>'yesNo'],
'slider'=>['name'=>'slider'],
'updated'=>['name'=>'updated']
];
static function getColumns() {
return self::$columns;
}
static function getTableName() {
return self::$tableName;
}
static function getAllIdentities($profile_id,$dimensions=false) {
$db = DBConnectionFactory::Instance();
$values = [self::$columns['profile_id']['name']=>$profile_id];
$records = $db->select(Identity::$tableName,$values);
$identities = [];
$identity_lookup = [];
foreach($records as $record) {
$identity = new Identity($record,true);
$identities[] = $identity;
$identity_lookup[$identity->getValue('dimension_id')] = $identity;
}
if (!$dimensions) {
$dimensions = Dimension::getDimensions();
}
foreach ($dimensions as $dimension) {
$dimension_id = $dimension->getValue('id');
if (!array_key_exists($dimension_id,$identity_lookup)) {
$values = ['profile_id'=>$profile_id,
'dimension_id'=>$dimension_id,
'yesNo'=>0,
'slider'=>1];
$identity = new Identity($values,false);
//error_log(json_encode($identity->getValues()));
$identity->saveToDB();
$identities[] = $identity;
$identity_lookup[$dimension_id] = $identity;
}
}
return $identities;
}
public function getDimension() {
$dim = Dimension::getObjectById($this->getValue('dimension_id'),Dimension::class);
return $dim;
}
public function vectorValue() {
return $this->getValue('yesNo')*$this->getValue('slider');
}
}