Moved common code to the parent class

pull/1/head
Victor Dubiniuk 11 years ago
parent c4bf4b6a78
commit f4fadd3bcc

@ -0,0 +1,26 @@
<?php
/**
* ownCloud - Documents App
*
* @author Victor Dubiniuk
* @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
namespace OCA\Documents;
class Db {
/**
* Build placeholders for the query with variable input data
* @param Array $array data
* @return String string of '?' placeholders matching the number of elements in array
*/
public function buildPlaceholders($array){
$count = count($array);
$placeholders = array_fill(0, $count, '?');
$stmt = implode(', ', $placeholders);
return $stmt;
}
}

@ -12,7 +12,7 @@
namespace OCA\Documents;
class Member {
class Member extends Db{
const ACTIVITY_THRESHOLD = 60; // 10 Minutes
@ -46,8 +46,7 @@ class Member {
return array();
}
$placeholders = array_fill(0, $memberCount, '?');
$stmt = implode(', ', $placeholders);
$placeholders = self::buildPlaceholders($ids);
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*documents_member` WHERE `member_id` IN (' . $stmt . ')');
$result = $query->execute($ids);
return $result->fetchAll();

@ -11,7 +11,7 @@
namespace OCA\Documents;
class Session {
class Session extends Db{
public static function add($genesis, $hash, $fileId){
$query = \OCP\DB::prepare('
@ -86,9 +86,8 @@ class Session {
if (!is_array($fileIds)){
$fileIds = array($fileIds);
}
$fileIdCount = count($fileIds);
$placeholders = array_fill(0, $fileIdCount, '?');
$stmt = implode(', ', $placeholders);
$stmt = self::buildPlaceholders($fileIds);
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*documents_session` WHERE `file_id` IN (' . $stmt .')');
$result = $query->execute($fileIds);
$sessions = $result->fetchAll();
@ -99,13 +98,15 @@ class Session {
}
public static function getInfoByFileid($fileIds){
$fileIdCount = count($fileIds);
if (!$fileIdCount || !is_array($fileIds)){
if (!is_array($fileIds)){
return array();
}
$stmt = self::buildPlaceholders($fileIds);
if (!$stmt){
return array();
}
$placeholders = array_fill(0, $fileIdCount, '?');
$stmt = implode(', ', $placeholders);
$query = \OCP\DB::prepare('
SELECT `s`.*, COUNT(`m`.`member_id`) AS `users`
FROM `*PREFIX*documents_session` AS `s`
@ -114,8 +115,7 @@ class Session {
WHERE `s`.`file_id` IN (' . $stmt .')
GROUP BY `m`.`es_id`
');
$result = $query->execute($fileIds
);
$result = $query->execute($fileIds);
$info = $result->fetchAll();
if (!is_array($info)){

@ -40,5 +40,20 @@ class Storage {
return $list;
}
/**
* @brief Copy files to trash bin
* @param array
*
* This function is connected to the delete signal of OC_Filesystem
* to copy the file to the trash bin
*/
public static function onDelete($params) {
if ( \OCP\App::isEnabled('files_trashbin') ) {
$path = $params['path'];
Trashbin::move2trash($path);
}
}
}

Loading…
Cancel
Save