Beispiel #1
0
 public function afterSave($created, $options = array())
 {
     parent::afterSave($created, $options);
     if (isset($this->data["Combination"]['Combination'][0])) {
         $x = $this->Combination->find("first", array("conditions" => array("Combination.id" => $this->data["Combination"]['Combination'][0])));
         $x2 = $this->Combination->find("all", array("contain" => false, "conditions" => array("Combination.reviewkey" => $x['Combination']['reviewkey']), "fields" => array("id")));
         foreach ($x2 as $v) {
             App::uses("CombinationsReview", "Model");
             $a = new CombinationsReview();
             $a->create();
             if (!$a->hasAny(array("CombinationsReview.combination_id" => $v['Combination']['id'], "CombinationsReview.review_id" => $this->getLastInsertID()))) {
                 $a->save(array("CombinationsReview" => array('combination_id' => $v['Combination']['id'], 'review_id' => $this->getLastInsertID())));
             }
         }
     } elseif ($this->data["Review"]['combination_reviewkey']) {
         $x2 = $this->Combination->find("all", array("contain" => false, "conditions" => array("Combination.reviewkey" => $this->data["Review"]['combination_reviewkey']), "fields" => array("id")));
         foreach ($x2 as $v) {
             App::uses("CombinationsReview", "Model");
             $a = new CombinationsReview();
             $a->create();
             if (!$a->hasAny(array("CombinationsReview.combination_id" => $v['Combination']['id'], "CombinationsReview.review_id" => $this->getLastInsertID()))) {
                 $a->save(array("CombinationsReview" => array('combination_id' => $v['Combination']['id'], 'review_id' => $this->getLastInsertID())));
             }
         }
     }
 }
 public function generate()
 {
     Configure::write('debug', 2);
     $this->loadModel('Recipe');
     $this->Recipe->recursive = 0;
     $recipes = $this->Recipe->find('all', array("order" => "Recipe.recipe_name ASC"));
     $r = array();
     foreach ($recipes as $d) {
         $r[] = $d['Recipe'];
     }
     $this->set("recipes", $r);
     $this->loadModel('Vendor');
     $this->Vendor->recursive = 0;
     $vendors = $this->Vendor->find('all');
     $r = array();
     foreach ($vendors as $d) {
         $r[] = $d['Vendor'];
     }
     $this->set("vendors", $r);
     if ($this->request->is('post')) {
         App::uses("HtmlHelper", "View/Helper");
         $html = new HtmlHelper(new View());
         foreach ($this->request->data as $data) {
             ///-------------Create Thali image start
             $is_thali = true;
             $dishArr = array();
             foreach ($data['Combination']['CombinationItem'] as $v) {
                 $dishArr[] = ltrim($v['image'], 'https://www.pickmeals.com/');
                 if ($v['is_thali'] == 'false') {
                     $is_thali = false;
                 }
             }
             if (count($dishArr) == 1) {
                 //for same dish in both 2 bowls
                 $dishArr[] = $dishArr[0];
             }
             $thali_pngs = $this->createThali($dishArr, $is_thali, 150);
             $data['Combination']['image'] = $html->url("/" . $thali_pngs[2], true);
             ///-------------Create Thali image end
             //------------Vendor Cost and Price Logic starts
             //vendor_cost
             //------------Vendor Cost and Price Logic ends
             $this->Combination->saveAssociated($data, array('deep' => true));
             $this->loadModel('Review');
             debug($this->Combination->getLastInsertID());
             $x = $this->Combination->find("first", array("conditions" => array("Combination.id" => $this->Combination->getLastInsertID())));
             $x2 = $this->Review->find("all", array("contain" => false, "conditions" => array("Review.combination_reviewkey" => $x['Combination']['reviewkey']), "fields" => array("id")));
             foreach ($x2 as $v) {
                 App::uses("CombinationsReview", "Model");
                 $a = new CombinationsReview();
                 //$a->create();
                 if (!$a->hasAny(array("CombinationsReview.combination_id" => $this->Combination->getLastInsertID(), "CombinationsReview.review_id" => $v['Review']['id']))) {
                     $a->save(array("CombinationsReview" => array('combination_id' => $this->Combination->getLastInsertID(), 'review_id' => $v['Review']['id'])));
                 }
             }
         }
     }
 }