public function testGetTitle() { $wn = new WebNotification($this->container); $p = new Project($this->container); $tf = new TaskFinder($this->container); $tc = new TaskCreation($this->container); $s = new Subtask($this->container); $c = new Comment($this->container); $f = new File($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1))); $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1))); $this->assertEquals(1, $f->create(1, 'test', 'blah', 123)); $task = $tf->getDetails(1); $subtask = $s->getById(1, true); $comment = $c->getById(1); $file = $c->getById(1); $this->assertNotEmpty($task); $this->assertNotEmpty($subtask); $this->assertNotEmpty($comment); $this->assertNotEmpty($file); foreach (Subscriber\NotificationSubscriber::getSubscribedEvents() as $event_name => $values) { $title = $wn->getTitleFromEvent($event_name, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array())); $this->assertNotEmpty($title); } $this->assertNotEmpty($wn->getTitleFromEvent(Task::EVENT_OVERDUE, array('tasks' => array(array('id' => 1))))); $this->assertNotEmpty($wn->getTitleFromEvent('unkown', array())); }
public function testGetMailContent() { $en = new EmailNotification($this->container); $p = new Project($this->container); $tf = new TaskFinder($this->container); $tc = new TaskCreation($this->container); $s = new Subtask($this->container); $c = new Comment($this->container); $f = new File($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1))); $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1))); $this->assertEquals(1, $f->create(1, 'test', 'blah', 123)); $task = $tf->getDetails(1); $subtask = $s->getById(1, true); $comment = $c->getById(1); $file = $c->getById(1); $this->assertNotEmpty($task); $this->assertNotEmpty($subtask); $this->assertNotEmpty($comment); $this->assertNotEmpty($file); foreach (Subscriber\NotificationSubscriber::getSubscribedEvents() as $event => $values) { $this->assertNotEmpty($en->getMailContent($event, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array()))); $this->assertNotEmpty($en->getMailSubject($event, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array()))); } }
public function testCreationFileNameTooLong() { $p = new Project($this->container); $f = new File($this->container); $tc = new TaskCreation($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); $this->assertTrue($f->create(1, 'test', '/tmp/foo', false, 10)); $this->assertTrue($f->create(1, str_repeat('a', 1000), '/tmp/foo', false, 10)); $files = $f->getAll(1); $this->assertNotEmpty($files); $this->assertCount(2, $files); $this->assertEquals(str_repeat('a', 255), $files[0]['name']); $this->assertEquals('test', $files[1]['name']); }
function index($parent_file_id) { $app = get_app(); $file = File::find_by_id($parent_file_id); $units = Unit::find_all_by_file_id($parent_file_id, array('order' => 'priority asc')); $app->render('Units/list.php', compact('units', 'file')); }
/** * 流程处理 * * @return boolean * @throws \Lib\Exception */ public function process() { if ($this->_state === false) { if (\Lib\Params::getInstance()->showHelp() === true) { $this->getHelp(); } return false; } $db = $this->getDbResponse(); $op = \Lib\Options::getInstance(); if (empty($this->_dbname)) { \Lib\State::error('The database is not specified'); } \Lib\State::notice('Scanning the database table...'); $tables = $op->getTable(); if (empty($tables)) { $tables = $db->findTables(); } else { foreach ($tables as $table) { if ($db->isExistTable($table) === false) { \Lib\State::warning('Unkown table \'' . $table . '\''); } } } if (empty($tables)) { \Lib\State::warning('Not found any tables'); } \Lib\State::notice('Found ' . sizeof($tables) . ' table(s)'); $modelFile = \Model\File::getInstance(); $modelContents = \Model\Content::getInstance(); $replaceArr = $op->getReplace() ?: []; foreach ($tables as $table) { $tableName = \Lib\Func::uc($table); $className = $tableName; if (!empty($replaceArr['source']) && !empty($replaceArr['target'])) { $className = str_ireplace($replaceArr['source'], ucfirst($replaceArr['target']), $className); } if (preg_match('/^[0-9]+/', $tableName)) { $tableName = ltrim(preg_replace('/^[0-9]+/', '', $tableName), '_'); } \Lib\State::notice('-----------------'); \Lib\State::notice('Processing [' . $table . ']'); $modelContents->setTableInfo($db->findTableInfo($table)); $modelContents->setClassName($className); $modelContents->setTableName($tableName); $modelContents->setColumns($db->findCols($table)); $modelContents->build(); \Lib\State::notice('Done'); $modelFile->setFileName($className)->build(); $modelContents->reset(); $modelFile->reset(); } return true; }
public function upload() { $view = Input::get('view', 'uploader'); if ($view === 'list' || $view === 'list-content') { //need fix $part = Input::get('part'); $list = File::get(Input::get('model'), Input::get('model_id', 0))->files($part)->orderBy('sort', 'asc')->get(); } else { $list = File::orderBy('sort', 'asc')->get(); } return view($this->templatePath() . '.' . $view, array('list' => $list)); }
function index($id) { // folder_id $nodes = array(); if ($id) { $folder = Folder::find_by_id($id); $sub_folders = $folder->folders; $sub_files = $folder->files; } else { // id: 0 // root folder $sub_folders = Folder::find_all_by_parent_folder_id(0); $sub_files = File::find_all_by_folder_id(0); } // 子分类 foreach ($sub_folders as $sub_folder) { $nodes[] = array('id' => $sub_folder->id, 'name' => $sub_folder->name . ' (' . (string) (count($sub_folder->folders) + count($sub_folder->files)) . ')', 'type' => 'folder', 'isParent' => count($sub_folder->files) || count($sub_folder->folders) ? true : false, 'icon' => get_path('/webroot/css/img/diy/folder-close.jpg', true), 'iconOpen' => get_path('/webroot/css/img/diy/folder-open.jpg'), 'iconClose' => get_path('/webroot/css/img/diy/folder-close.jpg')); } // 子零件 foreach ($sub_files as $sub_file) { $nodes[] = array('id' => $sub_file->id, 'name' => $sub_file->name . ' (' . count($sub_file->units) . ')', 'type' => 'file', 'isParent' => count($sub_file->units) ? true : false, 'icon' => get_path('/webroot/css/img/diy/3.png', true)); } echo json_encode($nodes); }
public function testRemove() { $p = new Project($this->container); $f = new File($this->container); $tc = new TaskCreation($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo1', 10)); $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo2', 10)); $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo3', 10)); $this->container['objectStorage']->expects($this->at(0))->method('remove')->with($this->equalTo('/tmp/foo2'))->will($this->returnValue(true)); $this->container['objectStorage']->expects($this->at(1))->method('remove')->with($this->equalTo('/tmp/foo1'))->will($this->returnValue(true)); $this->container['objectStorage']->expects($this->at(2))->method('remove')->with($this->equalTo('/tmp/foo3'))->will($this->returnValue(true)); $this->assertTrue($f->remove(2)); $files = $f->getAll(1); $this->assertNotEmpty($files); $this->assertCount(2, $files); $this->assertEquals('B.pdf', $files[0]['name']); $this->assertEquals('D.doc', $files[1]['name']); $this->assertTrue($f->removeAll(1)); $files = $f->getAll(1); $this->assertEmpty($files); }
function import_from_lib($part_id, $file_id) { $file = File::find_by_id($file_id); $part = Part::find_by_id($part_id); if (empty($file)) { $results['is_success'] = false; $results['error'] = '对不起,工艺库中找不到您所指定的零件!'; } else { if (!count($file->units)) { $results['is_success'] = false; $results['error'] = '对不起,您所指定的零件不包含任何工序!'; } if (count($part->processes)) { $results['is_success'] = false; $results['error'] = '对不起,只能为没有制定任何工序的零件节点从工艺库中导入模板!'; } if (!isset($results['error'])) { $nodes = array(); $units = Unit::find_all_by_file_id($file->id, array('order' => 'priority asc')); // import lib parts model's procs foreach ($units as $unit) { // create db node $item = array(); $item['priority'] = $unit->priority; $item['name'] = $unit->name; $item['content'] = $unit->content; $item['part_id'] = $part->id; $item['takt_time'] = ''; //$unit->takt_time; $item['preparation_time'] = ''; // $unit->preparation_time; $item['price'] = $unit->price; $item['production_date'] = ''; $item['planned_completion_date'] = ''; $item['remark'] = $unit->remark; $item['is_done'] = 0; $item['count'] = $part->count; $item['count_done'] = 0; // save db node $_proc = Process::create($item); $_proc->save(); // create ztree node $node = array(); $node['id'] = $_proc->id; $node['priority'] = $_proc->priority; $node['name'] = $_proc->priority . '# ' . get_proc_name($_proc->name) . ' (0)'; $node['isParent'] = false; $node['type'] = 'proc'; $node['moveFirst'] = false; $node['icon'] = get_path('/webroot/css/img/diy/4.png', true); $nodes[] = $node; } $results['is_success'] = true; $results['nodes'] = $nodes; } } echo json_encode($results); }
public function testRemove() { $p = new Project($this->container); $f = new File($this->container); $tc = new TaskCreation($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo', 10)); $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo', 10)); $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo', 10)); $this->assertTrue($f->remove(2)); $files = $f->getAll(1); $this->assertNotEmpty($files); $this->assertCount(2, $files); $this->assertEquals('B.pdf', $files[0]['name']); $this->assertEquals('D.doc', $files[1]['name']); $this->assertTrue($f->removeAll(1)); $files = $f->getAll(1); $this->assertEmpty($files); }
/** * Form vars preparing * * @param array $errors * @param string $successMessage * * @return array */ protected function getVarsArray($errors = [], $successMessage = '') { $file = new File(); try { $files = $file->getUserFiles($_SESSION['uid']); } catch (\Exception $e) { // TODO: log it $errors[] = "Ошибка загрузки списка файлов"; } return ['uploadedFiles' => $files, 'errors' => $errors, 'successMessage' => $successMessage]; }
function upload_for_file($file_id) { $app = get_app(); // GET if ($app->request()->isGet()) { $app->render('Images/upload.php', array('type' => 'file', 'id' => $file_id)); } // POST if ($app->request()->isPost()) { $file = File::find_by_id($file_id); if ($file) { $results = \Controller\Images::upload(); if ($results['is_success']) { $file->image = $results['md5_name']; $file->save(); } echo json_encode($results); } } }
function import($folder_id, $part_id) { $folder = Folder::find_by_id($folder_id); $part = Part::find_by_id($part_id); if ($folder && $part) { // 复制零件节点 $file = File::create(array('folder_id' => $folder_id, 'name' => $part->name, 'graphic_num' => $part->graphic_num, 'image' => $part->image)); // 添加零件工序节点 foreach ($part->processes as $p) { $unit = Unit::create(array('file_id' => $file->id, 'priority' => $p->priority, 'name' => $p->name, 'content' => $p->content, 'price' => $p->price, 'image' => $p->image, 'takt_time' => $p->takt_time, 'preparation_time' => $p->preparation_time, 'remark' => $p->remark)); $unit->save(); } // $node = array('id' => $file->id, 'name' => $file->name . ' (' . count($file->units) . ')', 'type' => 'file', 'isParent' => count($file->units) ? true : false, 'icon' => get_path('/webroot/css/img/diy/3.png', true)); echo json_encode($node); } }