Skip to content

Commit

Permalink
Patterns saved to db instead to file
Browse files Browse the repository at this point in the history
  • Loading branch information
dasistwas committed Oct 19, 2015
2 parents 96f6c9e + ee56be8 commit dbf4c28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
36 changes: 21 additions & 15 deletions view/view_class.php
Expand Up @@ -146,7 +146,7 @@ public function __construct($df = 0, $view = 0, $filteroptions = true) {
protected function set_view($data) {
$this->view->name = $data->name;
$this->view->description = !empty($data->description) ? $data->description : '';

$this->view->patterns = !empty($data->patterns) ? unserialize($data->patterns) : null;
$this->view->visible = !empty($data->visible) ? $data->visible : 7;
$this->view->perpage = !empty($data->perpage) ? $data->perpage : 0;
$this->view->groupby = !empty($data->groupby) ? $data->groupby : '';
Expand Down Expand Up @@ -197,14 +197,18 @@ protected function set__editors($data = null) {

/**
* Checks if patterns are cached. If yes patterns are retrieved from cache set in $this->_tags
* If no cached patterns are found, they are retrieved from the HTML provided in the view settings section field (definition)
* If no cached patterns are found, they are retrieved from the HTML provided in the
* view settings section field (definition)
*/
protected function set__patterns() {
$patterncache = cache::make('mod_datalynx', 'patterns');
$cachedpatterns = $patterncache->get($this->view->id);
global $DB;
$patterns = $this->view->patterns;
if(!is_null($this->view->patterns)){
$patterns = unserialize($this->view->patterns);
}

if (!$cachedpatterns) {
$cachedpatterns = array('view' => array(), 'field' => array()
if (!$patterns) {
$patterns = array('view' => array(), 'field' => array()
);
$text = '';
foreach ($this->_editors as $editor) {
Expand All @@ -213,20 +217,19 @@ protected function set__patterns() {

if (trim($text)) {
// This view patterns
$cachedpatterns['view'] = $this->patterns()->search($text);
$patterns['view'] = $this->patterns()->search($text);

// Field patterns
if ($fields = $this->_df->get_fields()) {
foreach ($fields as $fieldid => $field) {
$cachedpatterns['field'][$fieldid] = $field->renderer()->search($text);
$patterns['field'][$fieldid] = $field->renderer()->search($text);
}
}

$patterncache->set($this->view->id, $cachedpatterns);
$serializedpatterns = serialize($patterns);
$DB->set_field('datalynx_views', 'patterns', $serializedpatterns, array( 'id' => $this->view->id));
}
}

$this->_tags = $cachedpatterns;
$this->_tags = $patterns;
}

/**
Expand Down Expand Up @@ -329,10 +332,9 @@ public function add($data) {
*/
public function update($data = null) {
global $DB, $OUTPUT;

// invalidate patterns in the view
$DB->set_field('datalynx_views', 'patterns', null, array('id' => $this->view->id));
if ($data) {
$patterncache = cache::make('mod_datalynx', 'patterns');
$patterncache->delete($this->view->id, true);
$data = $this->from_form($data);
$this->set_view($data);
}
Expand Down Expand Up @@ -779,6 +781,10 @@ public function patterns() {
}

/**
* Get either all tags ($set = null) or field tags ($set = field) as an array
*
* @param string $set current: field or view
* @return Ambigous <multitype:, multitype:multitype: multitype:unknown >|multitype:|boolean
*/
public function get__patterns($set = null) {
if (is_null($set)) {
Expand Down
1 change: 0 additions & 1 deletion view/view_patterns.php
Expand Up @@ -656,7 +656,6 @@ protected function info_patterns() {
$cat = get_string('entries', 'datalynx');
$patterns = array('##numentriestotal##' => array(true, $cat
), '##numentriesdisplayed##' => array(true, $cat
), '##entries##' => array(true, $cat
)
);
return $patterns;
Expand Down

0 comments on commit dbf4c28

Please sign in to comment.