|
7 | 7 | */
|
8 | 8 | class ItemModel extends ItemModelBase
|
9 | 9 | {
|
10 |
| - |
| 10 | + /** Delete an item */ |
| 11 | + function delete($itemdao) |
| 12 | + { |
| 13 | + if(!$itemdao instanceof ItemDao) |
| 14 | + { |
| 15 | + throw new Zend_Exception("Error param."); |
| 16 | + } |
| 17 | + |
| 18 | + $deleteType=array( |
| 19 | + MIDAS_FEED_CREATE_ITEM,MIDAS_FEED_CREATE_LINK_ITEM |
| 20 | + ); |
| 21 | + $sql=$this->database->select() |
| 22 | + ->setIntegrityCheck(false) |
| 23 | + ->from(array('p' => 'feed')) |
| 24 | + ->where('ressource = ?', $itemdao->getKey()); |
| 25 | + |
| 26 | + $rowset=$this->database->fetchAll($sql); |
| 27 | + $this->ModelLoader = new MIDAS_ModelLoader(); |
| 28 | + $feed_model=$this->ModelLoader->loadModel('Feed'); |
| 29 | + $revision_model=$this->ModelLoader->loadModel('ItemRevision'); |
| 30 | + foreach($rowset as $row) |
| 31 | + { |
| 32 | + $feed=$this->initDao('Feed', $row); |
| 33 | + if(in_array($feed->getType(), $deleteType)) |
| 34 | + { |
| 35 | + $feed_model->delete($feed); |
| 36 | + } |
| 37 | + } |
| 38 | + $revisions=$itemdao->getRevisions(); |
| 39 | + foreach($revisions as $revision) |
| 40 | + { |
| 41 | + $revision_model->delete($revision); |
| 42 | + } |
| 43 | + |
| 44 | + $keywords=$itemdao->getKeywords(); |
| 45 | + foreach($keywords as $keyword) |
| 46 | + { |
| 47 | + $this->removeKeyword($itemdao,$keyword); |
| 48 | + } |
| 49 | + |
| 50 | + $policy_group_model=$this->ModelLoader->loadModel('Itempolicygroup'); |
| 51 | + $policiesGroup=$itemdao->getItempolicygroup(); |
| 52 | + foreach($policiesGroup as $policy) |
| 53 | + { |
| 54 | + $policy_group_model->delete($policy); |
| 55 | + } |
| 56 | + |
| 57 | + $policy_user_model=$this->ModelLoader->loadModel('Itempolicyuser'); |
| 58 | + $policiesUser=$itemdao->getItempolicyuser(); |
| 59 | + foreach($policiesUser as $policy) |
| 60 | + { |
| 61 | + $policy_user_model->delete($policy); |
| 62 | + } |
| 63 | + parent::delete($itemdao); |
| 64 | + unset($itemdao->item_id); |
| 65 | + $itemdao->saved=false; |
| 66 | + }//end delete |
| 67 | + |
11 | 68 | /** check if the policy is valid*/
|
12 | 69 | function policyCheck($itemdao,$userDao=null,$policy=0)
|
13 | 70 | {
|
@@ -195,6 +252,20 @@ function addKeyword($itemdao,$keyworddao)
|
195 | 252 | }
|
196 | 253 | $this->database->link('keywords',$itemdao,$keyworddao);
|
197 | 254 | } // end addKeyword
|
198 |
| - |
| 255 | + |
| 256 | + /** Remove a keyword to an item |
| 257 | + * @return void*/ |
| 258 | + function removeKeyword($itemdao,$keyworddao) |
| 259 | + { |
| 260 | + if(!$itemdao instanceof ItemDao) |
| 261 | + { |
| 262 | + throw new Zend_Exception("First argument should be an item"); |
| 263 | + } |
| 264 | + if(!$keyworddao instanceof ItemKeywordDao) |
| 265 | + { |
| 266 | + throw new Zend_Exception("Second argument should be a keyword"); |
| 267 | + } |
| 268 | + $this->database->removeLink('keywords',$itemdao,$keyworddao); |
| 269 | + } // end addKeyword |
199 | 270 | } // end class
|
200 | 271 | ?>
|
0 commit comments