/**
  * delete current widget data from the DB config
  * @return boolean 
  */
 public function delete()
 {
     if ($this->loaded) {
         // save widget to DB
         $confw = new Model_Config();
         $confw->where('group_name', '=', 'widget')->where('config_key', '=', $this->widget_name)->limit(1)->find();
         if ($confw->loaded()) {
             try {
                 $confw->delete();
                 //remove from previous placeholder, only if they are different
                 $confp = new Model_Config();
                 $confp->where('group_name', '=', 'placeholder')->where('config_key', '=', $this->placeholder)->limit(1)->find();
                 if ($confp->loaded()) {
                     //remove the key
                     $wid = json_decode($confp->config_value);
                     if (is_array($wid)) {
                         $wid = array_diff($wid, array($this->widget_name));
                         $confp->config_value = json_encode(array_values($wid));
                         $confp->save();
                     }
                 }
                 $this->data = array();
                 $this->loaded = FALSE;
                 return TRUE;
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
         }
     }
     return FALSE;
 }
Exemple #2
0
 /**
  * delete current widget data from the DB config
  * @return boolean 
  */
 public function delete()
 {
     if ($this->loaded) {
         // save widget to DB
         $confw = new Model_Config();
         $confw->where('group_name', '=', 'widget')->where('config_key', '=', $this->widget_name)->limit(1)->find();
         if ($confw->loaded()) {
             try {
                 $confw->delete();
                 //remove from previous placeholder, only if they are different
                 $confp = new Model_Config();
                 $confp->where('group_name', '=', 'placeholder')->where('config_key', '=', $this->placeholder)->limit(1)->find();
                 if ($confp->loaded()) {
                     //remove the key
                     $wid = json_decode($confp->config_value);
                     if (is_array($wid)) {
                         $key = array_search($this->widget_name, $wid);
                         if ($key !== FALSE) {
                             unset($wid[$key]);
                         }
                         $confp->config_value = json_encode($wid);
                         $confp->save();
                     }
                 }
                 $this->data = array();
                 $this->loaded = FALSE;
                 return TRUE;
             } catch (Exception $e) {
                 throw new HTTP_Exception_500($e);
             }
         }
     }
     return FALSE;
 }