/** * Submits the selected views to the collection * * @param array values selected views * @return integer count so we know what SESSION message to display */ public function add_views($values) { require_once get_config('libroot') . 'view.php'; $count = 0; // how many views we are adding db_begin(); // each view was marked with a key of view_<id> in order to identify the correct items // from the form values foreach ($values as $key => $value) { if (substr($key, 0, 5) === 'view_' and $value == true) { $cv = array(); $cv['view'] = substr($key, 5); $cv['collection'] = $this->get('id'); // set displayorder value $max = get_field('collection_view', 'MAX(displayorder)', 'collection', $this->get('id')); $cv['displayorder'] = is_numeric($max) ? $max + 1 : 0; insert_record('collection_view', (object) $cv); $count++; } } $viewids = get_column('collection_view', 'view', 'collection', $this->id); // Set the most permissive access records on all views View::combine_access($viewids, true); // Copy the whole view config from the first view to all the others if (count($viewids)) { $firstview = new View($viewids[0]); $viewconfig = array('startdate' => $firstview->get('startdate'), 'stopdate' => $firstview->get('stopdate'), 'template' => $firstview->get('template'), 'retainview' => $firstview->get('retainview'), 'allowcomments' => $firstview->get('allowcomments'), 'approvecomments' => (int) ($firstview->get('allowcomments') && $firstview->get('approvecomments')), 'accesslist' => $firstview->get_access()); View::update_view_access($viewconfig, $viewids); } db_commit(); return $count; }