From: moodler
Date: Mon, 15 Sep 2008 07:56:26 +0000 (+0000)
Subject: Just tidying as I read it. Main problem with it now is that huge block of JS
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7a3b93c18a652432781f4b9e7a027f89b630f101;p=moodle.git
Just tidying as I read it. Main problem with it now is that huge block of JS
---
diff --git a/repository/lib.php b/repository/lib.php
index 900471dfa5..aa5621faee 100644
--- a/repository/lib.php
+++ b/repository/lib.php
@@ -98,7 +98,7 @@ class repository_type {
* These options are saved in config_plugin table
* @var array
*/
- private $_options;
+ private $_options;
/**
@@ -106,7 +106,7 @@ class repository_type {
* If false (hidden): no instances can be created, edited, deleted, showned , used...
* @var boolean
*/
- private $_visible;
+ private $_visible;
/**
@@ -124,7 +124,7 @@ class repository_type {
* @param boolean $visible
* @param integer $sortorder (don't really need set, it will be during create() call)
*/
- public function __construct($typename = '', $typeoptions = array(), $visible = false, $sortorder = 0){
+ public function __construct($typename = '', $typeoptions = array(), $visible = false, $sortorder = 0) {
global $CFG;
//set type attributs
@@ -135,12 +135,12 @@ class repository_type {
//set options attribut
$this->_options = array();
//check that the type can be setup
- if (repository_static_function($typename,"has_admin_config")){
+ if (repository_static_function($typename,"has_admin_config")) {
$options = repository_static_function($typename,'get_admin_option_names');
//set the type options
foreach ($options as $config) {
- if (array_key_exists($config,$typeoptions)){
- $this->_options[$config] = $typeoptions[$config];
+ if (array_key_exists($config,$typeoptions)) {
+ $this->_options[$config] = $typeoptions[$config];
}
}
}
@@ -151,7 +151,7 @@ class repository_type {
* For a human readable name, use get_readablename()
* @return String the type name
*/
- public function get_typename(){
+ public function get_typename() {
return $this->_typename;
}
@@ -159,7 +159,7 @@ class repository_type {
* Return a human readable and user-friendly type name
* @return string user-friendly type name
*/
- public function get_readablename(){
+ public function get_readablename() {
return get_string('repositoryname','repository_'.$this->_typename);
}
@@ -167,7 +167,7 @@ class repository_type {
* Return general options
* @return array the general options
*/
- public function get_options(){
+ public function get_options() {
return $this->_options;
}
@@ -175,7 +175,7 @@ class repository_type {
* Return visibility
* @return boolean
*/
- public function get_visible(){
+ public function get_visible() {
return $this->_visible;
}
@@ -183,7 +183,7 @@ class repository_type {
* Return order / position of display in the file picker
* @return integer
*/
- public function get_sortorder(){
+ public function get_sortorder() {
return $this->_sortorder;
}
@@ -191,45 +191,44 @@ class repository_type {
* Create a repository type (the type name must not already exist)
* @global object $DB
*/
- public function create(){
+ public function create() {
global $DB;
//check that $type has been set
$timmedtype = trim($this->_typename);
if (empty($timmedtype)) {
- throw new repository_exception('emptytype', 'repository');
+ throw new repository_exception('emptytype', 'repository');
}
//set sortorder as the last position in the list
- if (!isset($this->_sortorder) || $this->_sortorder == 0 ){
+ if (!isset($this->_sortorder) || $this->_sortorder == 0 ) {
$sql = "SELECT MAX(sortorder) FROM {repository}";
$this->_sortorder = 1 + $DB->get_field_sql($sql);
}
//only create a new type if it doesn't already exist
$existingtype = $DB->get_record('repository', array('type'=>$this->_typename));
- if(!$existingtype){
- //create the type
- $newtype = new stdclass;
- $newtype->type = $this->_typename;
- $newtype->visible = $this->_visible;
- $newtype->sortorder = $this->_sortorder;
- $DB->insert_record('repository', $newtype);
-
- //save the options in DB
- $this->update_options();
-
- //if the plugin type has no multiple and no instance config so it wont
- //be possible for the administrator to create a instance
- //in this case we need to create an instance
- if (!repository_static_function($this->_typename,"has_instance_config")
- && !repository_static_function($this->_typename,"has_multiple_instances")){
- $instanceoptions = array();
- $instanceoptions['name'] = $this->_typename;
- repository_static_function($this->_typename, 'create', $this->_typename, 0, get_system_context(), $instanceoptions);
- }
- }
- else {
+ if (!$existingtype) {
+ //create the type
+ $newtype = new stdclass;
+ $newtype->type = $this->_typename;
+ $newtype->visible = $this->_visible;
+ $newtype->sortorder = $this->_sortorder;
+ $DB->insert_record('repository', $newtype);
+
+ //save the options in DB
+ $this->update_options();
+
+ //if the plugin type has no multiple and no instance config so it wont
+ //be possible for the administrator to create a instance
+ //in this case we need to create an instance
+ if (!repository_static_function($this->_typename,"has_instance_config")
+ && !repository_static_function($this->_typename,"has_multiple_instances")) {
+ $instanceoptions = array();
+ $instanceoptions['name'] = $this->_typename;
+ repository_static_function($this->_typename, 'create', $this->_typename, 0, get_system_context(), $instanceoptions);
+ }
+ } else {
throw new repository_exception('existingrepository', 'repository');
}
}
@@ -240,8 +239,8 @@ class repository_type {
* @param array $options
* @return boolean
*/
- public function update_options($options = null){
- if (!empty($options)){
+ public function update_options($options = null) {
+ if (!empty($options)) {
$this->_options = $options;
}
@@ -261,13 +260,13 @@ class repository_type {
* @param boolean $visible
* @return boolean
*/
- private function update_visible($visible = null){
+ private function update_visible($visible = null) {
global $DB;
- if (!empty($visible)){
+ if (!empty($visible)) {
$this->_visible = $visible;
}
- else if (!isset($this->_visible)){
+ else if (!isset($this->_visible)) {
throw new repository_exception('updateemptyvisible', 'repository');
}
@@ -283,14 +282,14 @@ class repository_type {
* @param integer $sortorder
* @return boolean
*/
- private function update_sortorder($sortorder = null){
+ private function update_sortorder($sortorder = null) {
global $DB;
- if (!empty($sortorder) && $sortorder!=0){
+ if (!empty($sortorder) && $sortorder!=0) {
$this->_sortorder = $sortorder;
}
//if sortorder is not set, we set it as the ;ast position in the list
- else if (!isset($this->_sortorder) || $this->_sortorder == 0 ){
+ else if (!isset($this->_sortorder) || $this->_sortorder == 0 ) {
$sql = "SELECT MAX(sortorder) FROM {repository}";
$this->_sortorder = 1 + $DB->get_field_sql($sql);
}
@@ -310,35 +309,35 @@ class repository_type {
*/
public function move_order($move) {
global $DB;
- //retrieve all types
- $types = repository_get_types();
- //retrieve this type into the returned array
- $i = 0;
- while (!isset($indice) && $iget_typename() == $this->_typename){
+ $types = repository_get_types(); // retrieve all types
+
+ /// retrieve this type into the returned array
+ $i = 0;
+ while (!isset($indice) && $iget_typename() == $this->_typename) {
$indice = $i;
}
$i++;
}
- //retrieve adjacent indice
+ /// retrieve adjacent indice
switch ($move) {
case "up":
$adjacentindice = $indice - 1;
- break;
+ break;
case "down":
$adjacentindice = $indice + 1;
- break;
+ break;
default:
- throw new repository_exception('movenotdefined', 'repository');
+ throw new repository_exception('movenotdefined', 'repository');
}
//switch sortorder of this type and the adjacent type
//TODO: we could reset sortorder for all types. This is not as good in performance term, but
//that prevent from wrong behaviour on a screwed database. As performance are not important in this particular case
//it worth to change the algo.
- if ($adjacentindice>=0 && !empty($types[$adjacentindice])){
+ if ($adjacentindice>=0 && !empty($types[$adjacentindice])) {
$DB->set_field('repository', 'sortorder', $this->_sortorder, array('type'=>$types[$adjacentindice]->get_typename()));
$this->update_sortorder($types[$adjacentindice]->get_sortorder());
}
@@ -349,7 +348,7 @@ class repository_type {
* 2. Update the type
* @return
*/
- public function switch_and_update_visibility(){
+ public function switch_and_update_visibility() {
$this->_visible = !$this->_visible;
return $this->update_visible();
}
@@ -361,17 +360,17 @@ class repository_type {
* @global object $DB
* @return boolean
*/
- public function delete(){
+ public function delete() {
global $DB;
//delete all instances of this type
$instances = repository_get_instances(array(),null,false,$this->_typename);
- foreach($instances as $instance){
+ foreach ($instances as $instance) {
$instance->delete();
}
//delete all general options
- foreach ($this->_options as $name => $value){
+ foreach ($this->_options as $name => $value) {
set_config($name, null, $this->_typename);
}
@@ -385,10 +384,10 @@ class repository_type {
* @param string $typename the type name
* @return integer
*/
-function repository_get_type_by_typename($typename){
+function repository_get_type_by_typename($typename) {
global $DB;
- if(!$record = $DB->get_record('repository',array('type' => $typename))) {
+ if (!$record = $DB->get_record('repository',array('type' => $typename))) {
return false;
}
@@ -401,10 +400,10 @@ function repository_get_type_by_typename($typename){
* @param string $typename the type name
* @return integer
*/
-function repository_get_type_by_id($id){
+function repository_get_type_by_id($id) {
global $DB;
- if(!$record = $DB->get_record('repository',array('id' => $id))) {
+ if (!$record = $DB->get_record('repository',array('id' => $id))) {
return false;
}
@@ -418,7 +417,7 @@ function repository_get_type_by_id($id){
* @param boolean $visible can return types by visiblity, return all types if null
* @return array Repository types
*/
-function repository_get_types($visible=null){
+function repository_get_types($visible=null) {
global $DB;
$types = array();
@@ -426,7 +425,7 @@ function repository_get_types($visible=null){
if (!empty($visible)) {
$params = array('visible' => $visible);
}
- if($records = $DB->get_records('repository',$params,'sortorder')) {
+ if ($records = $DB->get_records('repository',$params,'sortorder')) {
foreach($records as $type) {
$types[] = new repository_type($type->type, (array)get_config($type->type), $type->visible, $type->sortorder);
}
@@ -452,7 +451,7 @@ abstract class repository {
* @param integer $contextid
* @param array $options
*/
- public function __construct($repositoryid, $contextid = SITEID, $options = array()){
+ public function __construct($repositoryid, $contextid = SITEID, $options = array()) {
$this->id = $repositoryid;
$this->context = get_context_instance_by_id($contextid);
$this->options = array();
@@ -485,7 +484,7 @@ abstract class repository {
* @return mixed
*/
public function __get($name) {
- if (array_key_exists($name, $this->options)){
+ if (array_key_exists($name, $this->options)) {
return $this->options[$name];
}
trigger_error('Undefined property: '.$name, E_USER_NOTICE);
@@ -524,20 +523,20 @@ abstract class repository {
if (!file_exists($CFG->dataroot.'/temp/download')) {
mkdir($CFG->dataroot.'/temp/download/', 0777, true);
}
- if(is_dir($CFG->dataroot.'/temp/download')) {
+ if (is_dir($CFG->dataroot.'/temp/download')) {
$dir = $CFG->dataroot.'/temp/download/';
}
- if(empty($file)) {
+ if (empty($file)) {
$file = uniqid('repo').'_'.time().'.tmp';
}
- if(file_exists($dir.$file)){
+ if (file_exists($dir.$file)) {
$file = uniqid('m').$file;
}
$fp = fopen($dir.$file, 'w');
$c = new curl;
$c->download(array(
- array('url'=>$url, 'file'=>$fp)
- ));
+ array('url'=>$url, 'file'=>$fp)
+ ));
return $dir.$file;
}
@@ -549,7 +548,7 @@ abstract class repository {
* @return
*/
public function print_listing($listing = array(), $print=true) {
- if(empty($listing)){
+ if (empty($listing)) {
$listing = $this->get_listing();
}
if (empty($listing)) {
@@ -557,7 +556,7 @@ abstract class repository {
} else {
$count = 0;
$str = '
';
- foreach ($listing as $v){
+ foreach ($listing as $v) {
$str .= '