Ejemplo n.º 1
0
 /**
  * Displays a form for editing a translation.
  *
  * Route: admin/multilanguage/modules/manage/:slug/:slug/:num
  *
  * @param string $module The module the content belongs to
  * @param string $type The type of content within the module we are editing
  * @param int $typeId The id of $type to create a new language version for
  * @param int $contentId The if of the translation to edit.
  */
 public static function editContent($module, $type, $typeId, $contentId)
 {
     $typeInfo = Multilanguage::getContentType($module, $type);
     if (isset($_POST['update_content']) && Html::form()->validate()) {
         $status = true;
         $data = $_POST;
         unset($data['language_id']);
         unset($data['update_content']);
         unset($data['form_id']);
         foreach ($data as $k => $v) {
             $tmpId = null;
             switch ($typeInfo[$k]) {
                 case 'text':
                     $tmpId = Multilanguage::text()->where('content_id', '=', $contentId)->update(array('name' => $k, 'content' => $v));
                     break;
                 case 'textarea':
                     $tmpId = Multilanguage::textarea()->where('content_id', '=', $contentId)->update(array('name' => $k, 'content' => $v));
                     break;
                 case 'file':
                     $tmpId = Multilanguage::file()->where('content_id', '=', $contentId)->update(array('name' => $k, 'file_id' => $v));
                     break;
                 default:
                     Log::error('multilanguage', 'Attempting to update content of unkown type "' . $k . '"');
                     Message::error('Error updating content, unkown content type encountered.');
             }
             if ($tmpId < 0) {
                 Message::error('Error updating content for the "' . $k . '" type, please try again.');
                 $status = false;
                 break;
             }
         }
         if ($status) {
             Message::ok('Content updated successfully.');
         }
     }
     $data = array();
     // Data to be injected into the form
     $content = Multilanguage::content()->find($contentId);
     $data['language_id'] = $content->language_id;
     $texts = Multilanguage::text()->where('content_id', '=', $contentId)->all();
     if ($texts) {
         foreach ($texts as $t) {
             $data[$t->name] = $t->content;
         }
     }
     $textareas = Multilanguage::textarea()->where('content_id', '=', $contentId)->all();
     if ($textareas) {
         foreach ($textareas as $t) {
             $data[$t->name] = $t->content;
         }
     }
     return array('title' => 'Edit Translation', 'content' => self::_buildForm($module, $type, $typeId, $typeInfo, $data));
 }