Exemplo n.º 1
0
 function listAction()
 {
     $this->view->title = 'Template Resource List';
     $template_id = $this->_request->getParam('template_id');
     $this->view->template_id = $template_id;
     $resource_class = new Resources();
     $resources = $resource_class->fetchAll($resource_class->select());
     $this->view->form = new ResourceForm(array('template_id' => $template_id));
     $this->view->form->submit->setLabel('Upload');
     if ($this->_request->isPost()) {
         $form_data = $this->_request->getPost();
         if ($this->view->form->isValid($form_data)) {
             $resource_class = new Resources();
             // look at each template resource to see if it was uploaded
             $resources = $resource_class->fetchAll($resource_class->select()->where('template_id = ?', $template_id));
             foreach ($resources as $resource) {
                 $field = 'resource_' . $resource->id;
                 if (is_uploaded_file($_FILES[$field]['tmp_name'])) {
                     $resource->data = join('', file($_FILES[$field]['tmp_name']));
                     $resource->file_type = $_FILES[$field]['type'];
                     $resource->save();
                 }
             }
             $this->_redirect('/resource/list/template_id/' . $template_id);
         } else {
             $this->view->form->populate($form_data);
         }
     }
     $this->_helper->viewRenderer('form');
 }
Exemplo n.º 2
0
 function getResourceFileName($resource)
 {
     $filename = '';
     // this regular expression matches the filename and discards the preceding path
     if (preg_match('#(\\w+/)*(\\w+\\.\\w+)#', $resource->name, $matched)) {
         $filename = $matched[2];
     } else {
         $filename = $resource->id;
     }
     // make sure that the filename is unique
     $resource_class = new Resources();
     $resources = $resource_class->fetchAll('template_id=' . $this->template_id);
     $unique = 1;
     do {
         foreach ($resources as $other_resource) {
             if ($resource->id != $other_resource->id && array_key_exists($other_resource->id, $this->resource_id_to_filename) && strcmp($filename, $this->resource_id_to_filename[$other_resource->id]) == 0) {
                 $unique = 0;
                 $filename = $resource->id . '_' . $filename;
             }
         }
     } while ($unique == 0);
     return $filename;
 }
Exemplo n.º 3
0
 function resourcesToDb($resources, $template_id)
 {
     $resource_class = new Resources();
     foreach ($resources as $resource) {
         $select = $resource_class->select()->where('name = ?', $resource)->where('template_id = ?', $template_id);
         $existing_resource = $resource_class->fetchAll($select);
         if (sizeof($existing_resource) == 0) {
             $row = $resource_class->createRow();
             $row->name = $resource;
             $row->template_id = $template_id;
             $row->save();
         }
     }
 }