Skip to content

Commit

Permalink
Bug SAFeSEA#31, move 5 X Model classes to separate files [iet:10299536]
Browse files Browse the repository at this point in the history
  • Loading branch information
nfreear committed Feb 5, 2018
1 parent f94cfeb commit 59ec269
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 119 deletions.
21 changes: 21 additions & 0 deletions app/models/Feedback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Feedback model.
*
* @package OpenEssayist-slim
* @copyright © 2013-2018 The Open University. (Institute of Educational Technology)
*/

class Feedback extends Model
{
/**
*
* @key Feedback/users_id
* @return User
* @see ORMWrapper
*/
public function user() {
return $this->belongs_to('Users');
}

}
27 changes: 27 additions & 0 deletions app/models/Group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Group model.
*
* @package OpenEssayist-slim
* @copyright © 2013-2018 The Open University. (Institute of Educational Technology)
*/

class Group extends Model {
/**
*
* @key Users/group_id
* @return ORMWrapper
*/
public function users() {
return $this->has_many('Users');
}

/**
* @key Task/group_id
* @return ORMWrapper
*/
public function tasks() {
return $this->has_many('Task');
}

}
27 changes: 27 additions & 0 deletions app/models/KWCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* KWCategory model.
*
* @package OpenEssayist-slim
* @copyright © 2013-2018 The Open University. (Institute of Educational Technology)
*/

class KWCategory extends Model {

/**
*
* @key KWCategory/draft_id
* @return Task
* @see ORMWrapper
*/
public function task() {
return $this->belongs_to('Draft');
}

public function getGroups($assoc = true)
{
$json = $this->category;
$rr = json_decode($json, $assoc);
return $rr;
}
}
21 changes: 21 additions & 0 deletions app/models/Note.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Note model.
*
* @package OpenEssayist-slim
* @copyright © 2013-2018 The Open University. (Institute of Educational Technology)
*/

class Note extends Model
{
/**
*
* @key Note/users_id
* @return User
* @see ORMWrapper
*/
public function user() {
return $this->belongs_to('Users');
}

}
53 changes: 53 additions & 0 deletions app/models/Task.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Task / assignment model.
*
* @package OpenEssayist-slim
* @copyright © 2013-2018 The Open University. (Institute of Educational Technology)
*/

/**
* Default data model for the assignemnt (task)
* @author Nicolas Van Labeke (https://github.com/vanch3d)
*
*/
class Task extends Model {

/**
* @key Draft/task_id
* @return ORMWrapper
*/
public function drafts() {
return $this->has_many('Draft');
}

/**
* @key Task/group_id
* @return ORMWrapper
* @see Group
*/
public function group() {
return $this->belongs_to('Group');
}

/**
* Return the short version (first sentence) of the assignment question
* @return string
*/
public function short()
{
$tt = preg_split('/(?<=[.?!;:])\s+/', $this->assignment);
return "" . $tt[0];
}

/**
* Return the long version (all but first sentence) of the assignment question
* @return string
*/
public function long()
{
$tt = preg_split('/(?<=[.?!;:])\s+/', $this->assignment);
array_shift($tt);
return "".join(" ", $tt);
}
}
38 changes: 14 additions & 24 deletions app/models/draft.model.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<?php
/**
* Draft model.
*
* @package OpenEssayist-slim
* @copyright © 2013-2018 The Open University. (Institute of Educational Technology)
*/

/**
*
* @author Nicolas Van Labeke (https://github.com/vanch3d)
*
*/
class Draft extends Model {

/**
*
* @key Draft/task_id
Expand All @@ -24,7 +31,7 @@ public function task() {
public function user() {
return $this->belongs_to('Users');
}

/**
*
* @key KWCategory/draft_id
Expand All @@ -35,40 +42,23 @@ public function kwCategories() {
}

/**
*
*
* @return array
*/
public function getParasenttok()
{
$data = array();
$json = $this->analysis;
$rr = json_decode($json,true);
$rr = json_decode($json, true);
return $rr['se_data']['se_parasenttok'];
}
public function getAnalysis($assoc=false)

public function getAnalysis($assoc = false)
{
$json = $this->analysis;
$rr = json_decode($json,$assoc);
$rr = json_decode($json, $assoc);
return $rr;
}
}

class KWCategory extends Model {
/**
*
* @key KWCategory/draft_id
* @return Task
* @see ORMWrapper
*/
public function task() {
return $this->belongs_to('Draft');
}

public function getGroups($assoc=true)
{
$json = $this->category;
$rr = json_decode($json,$assoc);
return $rr;
}
}
// Moved: class KWCategory extends Model.
107 changes: 14 additions & 93 deletions app/models/users.model.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<?php
/**
* Default model for users.
*
* @package OpenEssayist-slim
* @copyright © 2013-2018 The Open University. (Institute of Educational Technology)
*/

/**
* Default model for users
*
* @author Nicolas Van Labeke (https://github.com/vanch3d)
*
*/
Expand All @@ -13,15 +19,15 @@ class Users extends Model {
public function group() {
return $this->belongs_to('Group');
}

/**
* @key Draft/users_id
* @return ORMWrapper
*/
public function drafts() {
return $this->has_many('Draft');
}

/**
*
* @key Note/users_id
Expand All @@ -39,100 +45,15 @@ public function Notes() {
public function reports() {
return $this->has_many('Feedback');
}

}

class Group extends Model {
/**
*
* @key Users/group_id
* @return ORMWrapper
*/
public function users() {
return $this->has_many('Users');
}

/**
* @key Task/group_id
* @return ORMWrapper
*/
public function tasks() {
return $this->has_many('Task');
}

}

/**
* Default data model for the assignemnt (task)
* @author Nicolas Van Labeke (https://github.com/vanch3d)
*
*/
class Task extends Model {
/**
* @key Draft/task_id
* @return ORMWrapper
*/
public function drafts() {
return $this->has_many('Draft');
}

/**
* @key Task/group_id
* @return ORMWrapper
* @see Group
*/
public function group() {
return $this->belongs_to('Group');
}


/**
* Return the short version (first sentence) of the assignment question
* @return string
*/
public function short()
{
$tt = preg_split('/(?<=[.?!;:])\s+/',$this->assignment);
return "" . $tt[0];
}
// Moved: 'class Group extends Model'.

/**
* Return the long version (all but first sentence) of the assignment question
* @return string
*/
public function long()
{
$tt = preg_split('/(?<=[.?!;:])\s+/',$this->assignment);
array_shift($tt);
return "".join(" ", $tt);
}

}
// Moved: 'class Task extends Model'.

class Note extends Model
{
/**
*
* @key Note/users_id
* @return User
* @see ORMWrapper
*/
public function user() {
return $this->belongs_to('Users');
}

}
// Moved: 'class Note extends Model'.

class Feedback extends Model
{
/**
*
* @key Feedback/users_id
* @return User
* @see ORMWrapper
*/
public function user() {
return $this->belongs_to('Users');
}
// Moved: 'class Feedback extends Model'.

}
// End.
9 changes: 7 additions & 2 deletions app/utils/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@
require_once __DIR__ . '/../controllers/group.controller.php';
require_once __DIR__ . '/../controllers/uptime.controller.php';

// Models (X 7) - multiple models per file :(!
require_once __DIR__ . '/../models/users.model.php';
// Models (X 7).
require_once __DIR__ . '/../models/draft.model.php';
require_once __DIR__ . '/../models/Feedback.php';
require_once __DIR__ . '/../models/Group.php';
require_once __DIR__ . '/../models/KWCategory.php';
require_once __DIR__ . '/../models/Note.php';
require_once __DIR__ . '/../models/Task.php';
require_once __DIR__ . '/../models/users.model.php';

// System's constants
define('APPLICATION', 'openEssayist');
Expand Down

0 comments on commit 59ec269

Please sign in to comment.