/**
  * check if values $_REQUEST[''] exist then - get thing by id(existing thing)
  * if values not exist then create a new thing and assigns to the friend whose id is set
  * @return array
  */
 protected function run()
 {
     if (array_key_exists('id', $_REQUEST) and $_REQUEST['id'] > 0) {
         $thing = Things::getThingByID($_REQUEST['id']);
     } else {
         $thing = new Thing();
         $thing->setFriendID($_REQUEST['friendid']);
     }
     /**
      * if $_POST_[""] is not empty then set the values into the template
      * else set error massage if one of the $_POST[""] is empty
      */
     if (!empty($_POST["description"]) and !empty($_POST["statebeforelent"])) {
         $thing->setDescription($_POST["description"]);
         $thing->setStateBeforeLent($_POST["statebeforelent"]);
         $thing->setDateOfLent(date('Y-m-d'));
         /**
          * records can be saved after editing or creating
          * exit the program after a successful storage
          * error massage when one of the $_POST fields is empty
          */
         if ($thing->save()) {
             header('location:index.php?module=lentthingslist&friendid=' . $thing->getFriendId());
             exit;
         } else {
             $var = array('fehler' => "Etwas stimmt mit der Eingabe nicht!");
         }
     } elseif (!empty($_POST["description"]) or !empty($_POST["statebeforelent"])) {
         $var = array('fehler' => "Es sind nicht alle Datenfelder ausgefüllt");
     }
     $var['thing'] = $thing;
     return $var;
 }
 /**
  * check if values $_REQUEST[''] exist then - get thing by id
  * fetches only the data whose ID is queried
  * @return array
  */
 protected function run()
 {
     if (array_key_exists('id', $_REQUEST) and $_REQUEST['id'] > 0) {
         $thing = Things::getThingByID($_REQUEST['id']);
     }
     /**
      * set options when thing is returned
      */
     if (!empty($_POST["stateafterreturn"])) {
         $thing->setStateAfterReturn($_POST["stateafterreturn"]);
         $thing->setDateOfReturn(date('Y-m-d'));
         /**
          * records can be saved after editing
          * exit the program after a successful storage
          * error massage when one of the $_POST field is empty
          */
         if ($thing->save()) {
             header('location:index.php?module=lentthingslist&friendid=' . $thing->getFriendId());
             exit;
         }
     } elseif (!empty($_POST["stateafterreturn"])) {
         $var = array('fehler' => "Bitte das leere Feld ausfüllen");
     }
     $var['thing'] = $thing;
     return $var;
 }
 public function viewAction($id = null)
 {
     $thing = Things::findFirst($id);
     if (!$thing) {
         return $this->response->redirect('thing/index');
     }
     $this->view->setVar('thing', $thing);
 }
Example #4
0
 public function updateAction($id = null)
 {
     if ($this->request->isPost()) {
         $imageCheckpoint = array();
         $userSession = $this->session->get("userSession");
         $id = $this->request->getPost('id');
         $details = $this->request->getPost('details');
         $price = str_replace(',', '', $this->request->getPost('price'));
         $condition = $this->request->getPost('thing_condition_id');
         $category = $this->request->getPost('thing_category_id');
         $thing = Things::findFirst($id);
         $thing->modified = date('Y-m-d H:i:s');
         $thing->member_id = $userSession['id'];
         $thing->name = $this->request->getPost('name');
         $thing->details = $details;
         $thing->thing_category_id = $category;
         $thing->thing_condition_id = $condition;
         //$this->view->disable();
         if ($thing->update()) {
             for ($i = 1; $i <= 7; $i++) {
                 $fileId = $this->request->getPost('fileId' . $i);
                 if (!empty($fileId)) {
                     $eventPhotos = ThingPhotos::findFirst($fileId);
                     $eventPhotos->created = date('Y-m-d H:i:s');
                     $eventPhotos->modified = date('Y-m-d H:i:s');
                     $eventPhotos->member_id = $userSession['id'];
                     $eventPhotos->caption = $this->request->getPost('caption' . $i);
                     $eventPhotos->update();
                 }
                 $imageCheckpoint[] = $fileId;
             }
             $this->view->disable();
             print_r($imageCheckpoint);
             $params = implode("','", $imageCheckpoint);
             $robots = ThingPhotos::query()->where("id NOT IN (:params:)")->bind(array("params" => $params))->execute();
             foreach ($robots as $toBeDeletedImg) {
                 $trashImg = 'img/thing/' . $toBeDeletedImg->filename;
                 unlink($trashImg);
                 $d = ThingPhotos::findFirst($toBeDeletedImg->id);
                 $d->delete();
             }
             if ($this->request->hasFiles() == true) {
                 //ini_set('upload_max_filesize', '64M');
                 set_time_limit(1200);
                 $uploads = $this->request->getUploadedFiles();
                 $isUploaded = false;
                 #do a loop to handle each file individually
                 foreach ($uploads as $upload) {
                     $imageName = $upload->getKey();
                     //$this->request->getPost('image'.$ctr);
                     $inputRow = str_replace('image', '', $imageName);
                     $fileId = $this->request->getPost('fileId' . $inputRow);
                     #define a “unique” name and a path to where our file must go
                     $fileName = $upload->getName();
                     $fileInfo = new SplFileInfo($fileName);
                     $fileExt = $fileInfo->getExtension();
                     $fileExt = strtolower($fileExt);
                     $newFileName = substr(md5(uniqid(rand(), true)), 0, 10) . date('ymdhis') . '.' . $fileExt;
                     //$fileExt = $upload->getExtension();
                     $fileImageExt = array('jpeg', 'jpg', 'png');
                     $fileType = '';
                     $filePath = '';
                     $path = '';
                     if (in_array($fileExt, $fileImageExt)) {
                         $path = 'img/thing/' . $newFileName;
                         $recentPhotos[] = 'img/thing/' . $newFileName;
                         $filePath = 'img/thing/';
                         //$fileType = 'Image';
                     }
                     #move the file and simultaneously check if everything was ok
                     $upload->moveTo($path) ? $isUploaded = true : ($isUploaded = false);
                     if ($isUploaded) {
                         if (!empty($fileId)) {
                             $realtyPhotos = ThingPhotos::findFirst($fileId);
                             $realtyPhotos->modified = date('Y-m-d H:i:s');
                             $realtyPhotos->member_id = $userSession['id'];
                             $realtyPhotos->file_path = $filePath;
                             $realtyPhotos->filename = $newFileName;
                             $realtyPhotos->update();
                         } else {
                             $realtyPhotos = new ThingPhotos();
                             $realtyPhotos->created = date('Y-m-d H:i:s');
                             $realtyPhotos->modified = date('Y-m-d H:i:s');
                             $realtyPhotos->member_id = $userSession['id'];
                             $realtyPhotos->thing_id = $id;
                             $realtyPhotos->file_path = $filePath;
                             $realtyPhotos->filename = $newFileName;
                             $realtyPhotos->caption = $this->request->getPost('caption' . $inputRow);
                             $realtyPhotos->create();
                         }
                     }
                 }
                 #if any file couldn't be moved, then throw an message
                 // $realtyPhotos = RealtyPhotos::find('realty_id ="'.$id.'"');
                 // foreach ($realtyPhotos as $photo) {
                 //     if (in_array($photo->filename, $recentPhotos)) {
                 //         $check = "okay";
                 //     } else {
                 //         if (unlink('img/realty/'. $photo->filename)) {
                 //             $check = "okay";
                 //         } else {
                 //             $this->view->disable();
                 //             echo "unable to remove image from img folder.";
                 //         }
                 //     }
                 // }
             }
             //$this->view->disable();
             return $this->response->redirect('thing/view/' . $id);
         }
         // thing update
     }
     // is post
     //$this->view->disable();
     $thing = Things::findFirst($id);
     if (!$thing) {
         return $this->response->redirect('thing/index');
     }
     $this->view->setVar('thing', $thing);
     $thingPhotos = ThingPhotos::find('thing_id =' . $id);
     $this->view->setVar('thingPhotos', $thingPhotos);
     $thingConditions = ThingConditions::find();
     $this->view->setVar('thingConditions', $thingConditions);
     $thingCategories = ThingCategories::find();
     $this->view->setVar('thingCategories', $thingCategories);
 }
Example #5
0
 public function searchAction()
 {
     $keyword = $this->request->get("find");
     $location = $this->request->get("near");
     $searchWords = '';
     $this->view->setVar('find', $keyword);
     $this->view->setVar('near', $near);
     $country = Countries::findFirst(array('columns' => '*', 'conditions' => 'country LIKE :country:', 'bind' => array('country' => $location)));
     $countryId = '';
     if ($country) {
         $countryId = $country->id;
     }
     $conditions = '';
     if (!empty($keyword)) {
         $conditions .= ' OR name LIKE :name:';
         $bind['name'] = '%' . $keyword . '%';
         $searchWords .= ', ' . $keyword;
     }
     if (!empty($location)) {
         $conditions .= ' OR street LIKE :street: OR city LIKE :city:';
         $bind['street'] = '%' . $location . '%';
         $bind['city'] = '%' . $location . '%';
         $searchWords .= ', ' . $location;
     }
     if (!empty($countryId)) {
         $conditions .= ' OR country_id = :country_id:';
         $bind['country_id'] = $countryId;
         $searchWords .= ', ' . $country->country;
     }
     $searchWords = substr($searchWords, 2);
     $business = Business::find(array('columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind));
     $this->view->setVar('business', $business);
     //CARS and TRUCKS
     $conditions = '';
     $bind = array();
     if (!empty($keyword)) {
         $conditions = ' OR name LIKE :name:';
         $bind['name'] = '%' . $keyword . '%';
     }
     if (!empty($keyword)) {
         $conditions .= ' OR brand LIKE :brand:';
         $bind['brand'] = '%' . $keyword . '%';
     }
     if (!empty($keyword)) {
         $conditions .= ' OR model LIKE :model:';
         $bind['model'] = '%' . $keyword . '%';
     }
     if (!empty($location)) {
         $conditions .= ' OR location LIKE :location:';
         $bind['location'] = $location;
     }
     $autos = Automotives::find(['columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind]);
     $this->view->setVar('autos', $autos);
     $conditions = '';
     $bind = array();
     if (!empty($keyword)) {
         $conditions = 'name LIKE :name:';
         $bind['name'] = '%' . $keyword . '%';
     }
     $things = Things::find(['columns' => '*', 'conditions' => $conditions, 'bind' => $bind]);
     $this->view->setVar('things', $things);
     //JOBS
     $conditions = '';
     $bind = array();
     if (!empty($keyword)) {
         $conditions .= ' OR position LIKE :position:';
         $bind['position'] = '%' . $keyword . '%';
         $searchWords .= ', ' . $keyword;
     }
     if (!empty($keyword)) {
         $conditions .= ' OR company LIKE :company:';
         $bind['company'] = '%' . $keyword . '%';
         $searchWords .= ', ' . $keyword;
     }
     if (!empty($location)) {
         $conditions .= ' OR street LIKE :street:';
         $bind['street'] = '%' . $location . '%';
         $conditions .= ' OR city LIKE :city:';
         $bind['city'] = '%' . $location . '%';
         $searchWords .= ', ' . $location;
     }
     if (!empty($countryId)) {
         $conditions .= ' OR country_id LIKE :country_id:';
         $bind['country_id'] = $countryId;
         $searchWords .= ', ' . $country->country;
     }
     $jobs = Jobs::find(array('columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind));
     $this->view->setVar('jobs', $jobs);
 }
Example #6
0
 /**
  * get list of things lent to this friend
  * @return array of Thing
  */
 public function getThings()
 {
     return Things::getThingsByFriendID($this->id);
 }