/** * Set allowed columns based on supplied columns array * * @param array $columns Allowed columns */ protected function set_allowed_columns($columns) { if (!empty($columns)) { foreach ($columns as $column => $show) { $this->allowed_columns |= $show ? $this->portal_columns->string_to_constant($column) : 0; } } else { $this->allowed_columns = 0; } }
/** * Get the horizontal move action (columns to move) * * @param array $module_data Array containing the module data * @param int $direction Direction to move; 1 for right, -1 for left * * @return int|null Move action if module can be moved, calls * handle_after_move() if it can't be moved */ public function get_horizontal_move_action($module_data, $direction) { if ($this->constraints_handler->can_move_horizontally($module_data, $direction)) { if ($this->module->get_allowed_columns() & $this->portal_columns->string_to_constant($this->portal_columns->number_to_string($module_data['module_column'] + $direction))) { return $direction; // we move 1 column } else { if ($this->module->get_allowed_columns() & $this->portal_columns->string_to_constant($this->portal_columns->number_to_string($module_data['module_column'] + $direction * 2)) && $module_data['module_column'] != $this->portal_columns->string_to_number('center')) { return 2 * $direction; // we move 2 columns } } } $this->handle_after_move(false); }
/** * Check if module can be moved to desired column * * @param \board3\portal\modules\module_interface $module * @param string $column Column string * * @return bool True if module can be moved, false if not */ public function can_add_module($module, $column) { return (bool) ($module->get_allowed_columns() & $this->portal_columns->string_to_constant($this->portal_columns->number_to_string($column))); }