public function deleteAction()
 {
     if ($this->request->isPost()) {
         $element = Mediumtypes::findFirstByUid($this->request->getPost('uid'));
         $element->deleted = 1;
         $element->save();
     }
 }
 public function requestInitialize($controllerName)
 {
     $this->view->setTemplateAfter('main');
     $this->view->setVars(array('version' => $this->config->application->version));
     if ($this->config->application->debug) {
         $baseUrl = $this->config->application->development->baseUri;
     } else {
         $baseUrl = $this->config->application->production->baseUri;
     }
     /**
      * Docs path and CDN url
      */
     $lang = $this->getUriParameter('language');
     $lang = $lang ? $lang : 'de';
     /**
      * Find the languages available
      */
     $languages = $this->config->languages;
     $languagesAvailable = '';
     $selected = '';
     $url = $this->request->getScheme() . '://' . $this->request->getHttpHost() . $baseUrl;
     $uri = $this->router->getRewriteUri();
     foreach ($languages as $key => $value) {
         $selected = $key == $lang ? " selected='selected'" : '';
         $href = $url . str_replace("/{$lang}", "{$key}", $uri);
         $languagesAvailable .= "<option value='{$href}'{$selected}>{$value}</option>";
     }
     $projectTypes = Projecttypes::find(array('conditions' => 'deleted = 0 AND hidden = 0', 'order' => 'tstamp ASC'));
     $mediumtypes = Mediumtypes::find(array('conditions' => 'deleted = 0 AND hidden = 0'));
     $this->lang = $lang;
     $this->view->setVar('mediumtypes', $mediumtypes);
     $this->view->setVar('projecttypes', $projectTypes);
     $this->view->setVar('controller', $controllerName);
     $this->view->setVar('language', $this->lang);
     $this->view->setVar('baseurl', $baseUrl);
     $this->view->setVar('languages_available', $languagesAvailable);
     $this->host = 'http://' . $_SERVER['SERVER_NAME'];
     $this->view->setVar('host', $this->host);
 }
 public function updateAction()
 {
     if ($this->request->isPost()) {
         $mediumUid = $this->request->hasPost('uid') ? $this->request->getPost('uid') : 0;
         $medium = Medium::findFirstByUid($mediumUid);
         if ($medium) {
             $medium->assign(array('tstamp' => time(), 'title' => $this->request->hasPost('title') ? $this->request->getPost('title') : '', 'description' => $this->request->hasPost('description') ? $this->request->getPost('description') : '', 'mediumtype' => $this->request->getPost('mediumtype'), 'reach' => $this->request->getPost('reach'), 'mediumstatus' => $this->request->getPost('status')));
             if (!$medium->update()) {
                 $this->flashSession->error($medium->getMessages());
             } else {
                 $medium->icon = $this->littlehelpers->saveImages($this->request->getUploadedFiles(), 'medium', $medium->uid);
                 $medium->update();
                 $this->flashSession->success($this->translate('successUpdate'));
             }
         }
     } else {
         $mediumUid = $this->dispatcher->getParam("uid") ? $this->dispatcher->getParam("uid") : 0;
     }
     $medium = Medium::findFirstByUid($mediumUid);
     $mediumtypes = Mediumtypes::find(array('conditions' => 'deleted=0 AND hidden=0'));
     $this->view->setVar('mediumtypes', $mediumtypes);
     $this->view->setVar('medium', $medium);
 }
 private function getData()
 {
     $currentyear = $this->littlehelpers->getCurrentYear();
     $bindArray = array();
     $aColumns = array('projecttitle', 'projecttopic', 'mediumtitle', 'mediumtype', 'reach', 'publicationdate', 'clippingtype', 'filelink', 'projectdate');
     $aColumnsSelect = array('clippingtype', 'filelink');
     $aColumnsFilter = array('projects.title', 'projects.topic', 'medium.title', 'clipping.title');
     $time = time();
     /* Indexed column (used for fast and accurate table cardinality) */
     $sIndexColumn = "clipping.uid";
     /* DB table to use */
     $sTable = "reportingtool\\Models\\Clippings as clipping LEFT JOIN reportingtool\\Models\\Medium as medium ON clipping.mediumuid = medium.uid LEFT JOIN reportingtool\\Models\\Projects as projects ON projects.uid = clipping.pid";
     /* 
      * Paging
      */
     $sLimit = "";
     if (isset($_POST['iDisplayStart']) && $_POST['iDisplayLength'] != '-1') {
         $sLimit = "LIMIT " . intval($_POST['iDisplayStart']) . ", " . intval($_POST['iDisplayLength']);
     }
     /*
      * Ordering
      */
     $sOrder = "";
     if (isset($_POST['iSortCol_0'])) {
         $dateSort = false;
         $sOrder = "ORDER BY  ";
         for ($i = 0; $i < intval($_POST['iSortingCols']); $i++) {
             if ($_POST['bSortable_' . intval($_POST['iSortCol_' . $i])] == "true") {
                 $sOrder .= $aColumns[intval($_POST['iSortCol_' . $i])] . " " . ($_POST['sSortDir_' . $i] === 'asc' ? 'asc' : 'desc') . ", ";
                 if ('date' == $aColumns[intval($_POST['iSortCol_' . $i])]) {
                     $dateSort = true;
                 }
             }
         }
         $sOrder = substr($sOrder, 0, -2) . ' ';
     }
     /* 
      * Filtering
      * NOTE this does not match the built-in DataTables filtering which does it
      * word by word on any field. It's possible to do here, but concerned about efficiency
      * on very large tables, and MySQL's regex functionality is very limited
      */
     $sWhere = "WHERE clipping.deleted=0 AND clipping.hidden=0 AND clipping.tstamp >= :starttstamp: AND clipping.tstamp <= :endtstamp: AND projects.deleted=0 AND projects.hidden =0 AND clipping.usergroup = :usergroup: ";
     if (isset($_POST['sSearch']) && $_POST['sSearch'] != "") {
         $sWhere .= " AND (";
         for ($i = 0; $i < count($aColumnsFilter); $i++) {
             $sWhere .= "" . $aColumnsFilter[$i] . " LIKE :searchTerm: OR ";
             //$_POST['sSearch']
         }
         $sWhere = substr_replace($sWhere, "", -3);
         $sWhere .= ')';
     }
     $filterArray = array('topics' => array('colname' => 'projects.topic', 'type' => 4), 'startdate' => array('colname' => 'projects.starttime', 'type' => 2), 'enddate' => array('colname' => 'projects.endtime', 'type' => 3), 'projects' => array('colname' => 'projects.uid', 'type' => 1), 'projecttype' => array('colname' => 'projects.projecttype', 'type' => 1));
     foreach ($filterArray as $postname => $columnname) {
         if ($this->request->hasPost($postname) && $this->request->getPost($postname)) {
             if (is_array($this->request->getPost($postname)) && count($this->request->getPost($postname)) > 1) {
                 switch ($columnname['type']) {
                     case 1:
                         $sWhere .= " AND " . $columnname['colname'] . " IN (" . implode(',', $this->request->getPost($postname)) . ')';
                         break;
                     case 4:
                         $sWhere .= " AND " . $columnname['colname'] . ' IN ("' . implode('","', $this->request->getPost($postname)) . '")';
                         break;
                 }
             } else {
                 switch ($columnname['type']) {
                     case 1:
                         $sWhere .= " AND " . $columnname['colname'] . " = " . implode(',', $this->request->getPost($postname)) . '';
                         break;
                     case 2:
                         $sWhere .= " AND " . $columnname['colname'] . " > " . $this->littlehelpers->processDateOnly($this->request->getPost($postname));
                         break;
                     case 3:
                         $sWhere .= " AND " . $columnname['colname'] . " < " . $this->littlehelpers->processDateOnly($this->request->getPost($postname));
                         break;
                     case 4:
                         $sWhere .= " AND " . $columnname['colname'] . " LIKE '" . $this->request->getPost($postname)[0] . "'";
                         break;
                 }
             }
         }
     }
     /*
      * SQL queries
      * Get data to display
      */
     $phql = "SELECT " . str_replace(" , ", " ", implode(", ", $aColumnsSelect)) . ", clipping.uid as clippinguid, medium.title AS mediumtitle,mediumtype,reach,clipping.tstamp as publicationdate, clipping.title AS clippingtitle, clipping.url as clippingurl, projects.title AS projecttitle, projects.starttime AS projectdate,projects.topic as projecttopic FROM {$sTable} " . $sWhere . " " . $sOrder . " " . $sLimit;
     $bindArray['usergroup'] = $this->session->get('auth')['usergroup'];
     $bindArray['starttstamp'] = $currentyear[0];
     $bindArray['endtstamp'] = $currentyear[1];
     if ($this->request->getPost('sSearch') != '') {
         $bindArray['searchTerm'] = '%' . $this->request->getPost('sSearch') . '%';
     }
     $sQuery = $this->modelsManager->createQuery($phql);
     $rResults = $sQuery->execute($bindArray);
     $resultSet = array();
     $clippingtypes = array('online', 'print', 'newsletter');
     foreach ($rResults as $aRow) {
         $row = array();
         for ($i = 0; $i < count($aColumns); $i++) {
             /* General output */
             $rowArray = (array) $aRow;
             if ($aColumns[$i] == 'publicationdate') {
                 $row[] = date('d/m/Y', $rowArray[$aColumns[$i]]);
             } elseif ($aColumns[$i] == 'clippingtype') {
                 $row[] = $clippingtypes[$rowArray[$aColumns[$i]]];
             } elseif ($aColumns[$i] == 'filelink') {
                 $row[] = '<a href="' . $this->host . $this->baseUri . $rowArray[$aColumns[$i]] . '" target="_blank">Download</a>';
             } elseif ($aColumns[$i] == 'projectdate') {
                 $row[] = date('d/m/Y', $rowArray[$aColumns[$i]]);
             } elseif ($aColumns[$i] == 'mediumtype') {
                 $mediumtype = \reportingtool\Models\Mediumtypes::findFirstByUid($rowArray[$aColumns[$i]]);
                 $row[] = $mediumtype->title;
             } elseif ($aColumns[$i] == 'reach' && $rowArray[$aColumns[$i]] == 0) {
                 $row[] = 'k.A.';
             } else {
                 $row[] = $rowArray[$aColumns[$i]];
             }
         }
         $resultSet[] = $row;
     }
     /* Data set length after filtering */
     $rResultFilterTotal = count($resultSet);
     /* Total data set length */
     $lphql = "SELECT COUNT(" . $sIndexColumn . ") AS countids FROM {$sTable}\t" . $sWhere;
     $lQuery = $this->modelsManager->createQuery($lphql);
     $rResultTotal = $lQuery->execute($bindArray);
     foreach ($rResultTotal as $aRow) {
         $iTotal = (array) $aRow;
     }
     $iTotal = $iTotal['countids'];
     //$GLOBALS['TYPO3_DB']->sql_fetch_assoc($rResultTotal);
     /*
      * Output
      */
     $output = array("sEcho" => intval($_POST['sEcho']), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iTotal, "aaData" => $resultSet);
     return $output;
 }