示例#1
0
 public function indexAction()
 {
     $projectId = (int) $this->getRequest()->getParam('projectId', 0);
     $range = $this->getRequest()->getHeader('range');
     sscanf($range, 'items=%d-%d', $start, $end);
     $count = $end - $start + 1;
     $sort = $this->getRequest()->getParam('sort', null);
     $recursive = $this->getRequest()->getParam('recursive', 'false');
     $recursive = $recursive === 'true';
     $model = $this->newModelObject();
     $moduleId = Phprojekt_Module::getId($this->getRequest()->getModuleName());
     $isGlobal = Phprojekt_Module::saveTypeIsGlobal($moduleId);
     if (empty($projectId) && !$isGlobal) {
         throw new Zend_Controller_Action_Exception('projectId not given for non-global module', 422);
     } else {
         if (!empty($projectId) && $isGlobal) {
             throw new Zend_Controller_Action_Exception('projectId given for global module', 422);
         }
     }
     $recursive = $isGlobal ? false : $recursive;
     $records = array();
     $recordCount = 0;
     if ($recursive) {
         $tree = new Phprojekt_Tree_Node_Database(new Project_Models_Project(), $projectId);
         $tree->setup();
         $where = $this->getFilterWhere();
         $records = $tree->getRecordsFor($model, $count, $start, $where, $sort);
         $recordCount = $tree->getRecordsCount($model, $where);
     } else {
         if (!empty($projectId) && $model->hasField('projectId')) {
             $where = Phprojekt::getInstance()->getDb()->quoteInto('project_id = ?', (int) $projectId);
         } else {
             $where = null;
         }
         $where = $this->getFilterWhere($where);
         $records = $model->fetchAll($where, $sort, $count, $start);
         $recordCount = $model->count($where);
     }
     $end = min($end, $recordCount);
     $this->getResponse()->setHeader('Content-Range', "items {$start}-{$end}/{$recordCount}");
     Phprojekt_CompressedSender::send(Zend_Json::encode(Phprojekt_Model_Converter::convertModels($records)));
 }
示例#2
0
 /**
  * Delete the tree cache after delete.
  *
  * @return void
  */
 public function delete()
 {
     parent::delete();
     Phprojekt_Tree_Node_Database::deleteCache();
 }
示例#3
0
 /**
  * Returns the project tree.
  *
  * The return is a tree compatible format, with identifier, label,
  * and the list of items, each one with the name, id, parent, path and children´s id.
  *
  * The tree is stored as a file until a user add, edit or delete a project
  * (tmp/ZendCache/zend_cache---Phprojekt_Tree_Node_Database_setup).
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonTreeAction()
 {
     $model = Phprojekt_Loader::getModel('Project', 'Project');
     $tree = new Phprojekt_Tree_Node_Database($model, 1);
     Phprojekt_Converter_Json::echoConvert($tree->setup());
 }
 /**
  * Returns the list of items for one model.
  *
  * The return have:
  *  - The metadata of each field.
  *  - The data of all the rows.
  *  - The number of rows.
  *
  * The function use Phprojekt_ModelInformation_Default::ORDERING_LIST for get and sort the fields.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b>     List only this id.
  *  - integer <b>nodeId</b> List all the items with projectId == nodeId.
  *  - integer <b>count</b>  Use for SQL LIMIT count.
  *  - integer <b>offset</b> Use for SQL LIMIT offset.
  *  - boolean <b>recursive</b> Include items of subprojects.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonListAction()
 {
     $itemId = (int) $this->getRequest()->getParam('id', null);
     $projectId = (int) $this->getRequest()->getParam('nodeId', null);
     $count = (int) $this->getRequest()->getParam('count', null);
     $offset = (int) $this->getRequest()->getParam('start', null);
     $recursive = $this->getRequest()->getParam('recursive', 'false');
     $this->setCurrentProjectId();
     if (!empty($itemId)) {
         $where = sprintf('id = %d', (int) $itemId);
     } else {
         if (!empty($projectId) && $this->getModelObject()->hasField('projectId')) {
             $where = sprintf('project_id = %d', (int) $projectId);
         } else {
             $where = null;
         }
     }
     /* recursive is only supported if nodeId is specified */
     if (!empty($projectId) && $this->getModelObject()->hasField('projectId') && 'true' === $recursive) {
         $tree = new Phprojekt_Tree_Node_Database(new Project_Models_Project(), $projectId);
         $tree->setup();
         Phprojekt_Converter_Json::echoConvert($tree->getRecordsFor($this->getModelObject(), null, null, $this->getFilterWhere()), Phprojekt_ModelInformation_Default::ORDERING_LIST);
     } else {
         $where = $this->getFilterWhere($where);
         $records = $this->getModelObject()->fetchAll($where, null, $count, $offset);
         Phprojekt_Converter_Json::echoConvert($records, Phprojekt_ModelInformation_Default::ORDERING_LIST);
     }
 }
示例#5
0
 /**
  * Returns the tree node for this project.
  *
  * The node allows navigating to subprojects and other operations on the project tree.
  *
  * @return Phprojekt_Tree_Node_Database A Tree node belonging to this project.
  */
 public function getTree()
 {
     $tree = new Phprojekt_Tree_Node_Database($this);
     $tree->setup();
     return $tree;
 }
示例#6
0
 /**
  * Rebuild the paths of a subtree.
  *
  * @param Phprojekt_Tree_Node_Database $node     Node to rebuild.
  * @param string                       $basePath Path of the parent.
  *
  * @return void
  */
 protected function _rebuildPaths(Phprojekt_Tree_Node_Database $node, $basePath)
 {
     if ($node->_activeRecord->path != $basePath) {
         $node->getActiveRecord()->path = $basePath;
         foreach ($node->getChildren() as $id => $child) {
             $node->_children[$id] = $this->_rebuildPaths($child, $basePath . $node->id . self::NODE_SEPARATOR);
             $this->getRootNode()->_index[$child->id] = $node->_children[$id];
             $node->_children[$id]->getActiveRecord()->parentSave();
             self::deleteCache();
         }
     }
     return $node;
 }