Esempio n. 1
0
 /**
  * Return paged project files
  *
  * @param Project $project
  * @param ProjectFolder $folder
  * @param boolean $hide_private Don't show private files
  * @param string $order Order files by name or by posttime (desc)
  * @param integer $page Current page
  * @param integer $files_per_page Number of files that will be showed per single page
  * @param boolean $group_by_order Group files by order field
  * @return array
  */
 static function getProjectFiles(Project $project, $folder = null, $hide_private = false, $order = null, $page = null, $files_per_page = null, $group_by_order = false)
 {
     trace(__FILE__, 'getProjectFiles()');
     if ($order == self::ORDER_BY_POSTTIME) {
         $order_by = '`created_on` DESC';
     } else {
         $order_by = '`filename`';
     }
     // if
     // #PAGE# is reserved as a placeholder
     //if (!($page == '#PAGE#')) {
     if ((int) $page < 1) {
         $page = 1;
     }
     if ((int) $files_per_page < 1) {
         $files_per_page = 10;
     }
     //} // if
     $folder_ids = array();
     if ($folder instanceof ProjectFolder && $folder->getProjectId() == $project->getId()) {
         if ($hide_private) {
             $conditions = array('`project_id` = ? AND `folder_id` = ? AND `is_private` = ? AND `is_visible` = ?', $project->getId(), $folder->getId(), false, true);
         } else {
             $conditions = array('`project_id` = ? AND `folder_id` = ? AND `is_visible` = ?', $project->getId(), $folder->getId(), true);
         }
         // if
     } else {
         if ($hide_private) {
             $conditions = array('`project_id` = ? AND `is_private` = ? AND `is_visible` = ?', $project->getId(), false, true);
         } else {
             $conditions = array('`project_id` = ? AND `is_visible` = ?', $project->getId(), true);
         }
         // if
     }
     // if
     list($files, $pagination) = ProjectFiles::paginate(array('conditions' => $conditions, 'order' => $order_by), $files_per_page, $page);
     if ($group_by_order) {
         $grouped_files = array();
         if (is_array($files) && count($files)) {
             $today = DateTimeValueLib::now();
             foreach ($files as $file) {
                 $group_by_str = '';
                 if ($order == self::ORDER_BY_POSTTIME) {
                     $created_on = $file->getCreatedOn();
                     if ($created_on->getYear() == $today->getYear()) {
                         $group_by_str = format_descriptive_date($created_on);
                     } else {
                         $group_by_str = format_date($created_on);
                     }
                     // if
                 } else {
                     $group_by_str = strtoupper(substr_utf($file->getFilename(), 0, 1));
                 }
                 // if
                 if (!isset($grouped_files[$group_by_str]) || !is_array($grouped_files[$group_by_str])) {
                     $grouped_files[$group_by_str] = array();
                 }
                 $grouped_files[$group_by_str][] = $file;
             }
             // foreach
         }
         // if
         $files = is_array($grouped_files) ? $grouped_files : null;
     }
     // if
     return array($files, $pagination);
 }
 /**
  * Return paged project files
  *
  * @param Project $project
  * @param ProjectFolder $folder
  * @param boolean $hide_private Don't show private files
  * @param string $order Order files by name or by posttime (desc)
  * @param integer $page Current page
  * @param integer $files_per_page Number of files that will be showed per single page
  * @param boolean $group_by_order Group files by order field
  * added by msaiz 03/10/07:
  * @param string for tag filter
  * @return array
  * 
  */
 static function getProjectFiles($project = null, $folderId = null, $hide_private = false, $order = null, $orderdir = 'ASC', $page = null, $files_per_page = null, $group_by_order = false, $tag = null, $type_string = null, $userId = null, $archived = false)
 {
     if ($order == self::ORDER_BY_POSTTIME) {
         $order_by = '`created_on` ' . $orderdir;
     } else {
         if ($order == self::ORDER_BY_MODIFYTIME) {
             $order_by = '`updated_on` ' . $orderdir;
         } else {
             $order_by = '`filename`' . $orderdir;
         }
     }
     // if
     if ((int) $page < 1) {
         $page = 1;
     }
     // if
     if ((int) $files_per_page < 1) {
         $files_per_page = 10;
     }
     // if
     if ($project instanceof Project) {
         $pids = $project->getAllSubWorkspacesQuery(!$archived);
         $projectstr = " AND " . self::getWorkspaceString($pids);
     } else {
         $projectstr = "";
     }
     if ($tag == '' || $tag == null) {
         $tagstr = "";
     } else {
         $tagstr = " AND (select count(*) from " . TABLE_PREFIX . "tags where " . TABLE_PREFIX . "project_files.id = " . TABLE_PREFIX . "tags.rel_object_id and " . TABLE_PREFIX . "tags.tag = " . DB::escape($tag) . " and " . TABLE_PREFIX . "tags.rel_object_manager ='ProjectFiles' ) > 0 ";
     }
     if ($type_string == '' || $type_string == null) {
         $typestr = "";
     } else {
         $types = explode(',', $type_string);
         $typessql = '( ';
         $cant = count($types);
         $n = 0;
         foreach ($types as $type) {
             $type .= '%';
             $typessql .= ' ' . TABLE_PREFIX . "project_file_revisions.type_string LIKE " . DB::escape($type);
             $n++;
             $n != $cant ? $typessql .= ' OR ' : ($typessql .= ' )');
         }
         $typestr = " AND  (select count(*) from " . TABLE_PREFIX . "project_file_revisions where " . $typessql . " AND " . TABLE_PREFIX . "project_files.id = " . TABLE_PREFIX . "project_file_revisions.file_id)";
     }
     if ($userId == null || $userId == 0) {
         $userstr = "";
     } else {
         $userstr = " AND `created_by_id` = " . DB::escape($userId) . " ";
     }
     $permissionstr = ' AND ( ' . permissions_sql_for_listings(ProjectFiles::instance(), ACCESS_LEVEL_READ, logged_user()) . ') ';
     if ($archived) {
         $archived_cond = " AND `archived_by_id` <> 0";
     } else {
         $archived_cond = " AND `archived_by_id` = 0";
     }
     $otherConditions = $projectstr . $tagstr . $typestr . $userstr . $permissionstr . $archived_cond;
     if ($hide_private) {
         $conditions = array('`is_visible` = ?' . $otherConditions, true);
     } else {
         $conditions = array(' true ' . $otherConditions);
     }
     list($files, $pagination) = ProjectFiles::paginate(array('conditions' => $conditions, 'order' => $order_by), $files_per_page, $page);
     return array($files, $pagination);
 }