@@ -29,12 +29,12 @@ public function getSource()
29
29
30
30
/**
31
31
* get an array of block info
32
- * @param $blockId
32
+ * @param $identifier
33
33
* @return mixed
34
34
*/
35
- public function getBlockInfo ($ blockId )
35
+ public function getBlockInfo ($ identifier )
36
36
{
37
- $ modelBlock = Mage::getModel ('cms/block ' )->load ($ blockId );
37
+ $ modelBlock = Mage::getModel ('cms/block ' )->load ($ identifier , ' identifier ' );
38
38
39
39
return $ modelBlock ->getData ();
40
40
@@ -43,31 +43,73 @@ public function getBlockInfo($blockId)
43
43
44
44
/**
45
45
* check if the block exists in remote
46
- * @param $data array
46
+ * @param $identifier string
47
47
* @return mixed
48
48
*/
49
- public function checkBlockExists ( $ data )
49
+ public function checkForNewBlock ( $ identifier )
50
50
{
51
- $ identifier = $ data ['identifier ' ];
52
- $ storeIds = $ data ['storeIds ' ];
53
51
54
- $ collection = Mage::getModel ('cms/block ' )->getCollection ()
55
- ->addFilter ('identifier ' , $ identifier )
56
- ->addFieldToFilter ('block_id ' , array ('in ' => $ storeIds ));
57
52
58
- Mage::log ('identifier to search : ' . $ identifier );
59
- Mage::log ($ storeIds );
60
- Mage::log ($ collection ->getData ());
61
- return $ collection ->getSize ();
53
+ $ blockModel = Mage::getModel ('cms/block ' )->load ($ identifier , 'identifier ' );
54
+
55
+
56
+ if ($ blockModel ){
57
+
58
+ return false ;
59
+ }
60
+ return true ;
62
61
}
63
62
64
63
/**
65
64
* Create new block
66
65
* @param $data
66
+ * @return Mage_Core_Model_Abstract
67
67
*/
68
68
public function createBlock ($ data )
69
69
{
70
- Mage::log ($ data );
70
+ if (!empty ($ data )){
71
+
72
+ $ staticBlock = array (
73
+ 'title ' => $ data ['title ' ],
74
+ 'identifier ' => $ data ['identifier ' ],
75
+ 'content ' => $ data ['content ' ],
76
+ 'store_id ' => $ data ['store_id ' ],
77
+ 'is_active ' => $ data ['is_active ' ]
78
+ );
79
+
80
+ $ blockModel = Mage::getModel ("cms/block " );
81
+
82
+
83
+ $ blockModel ->setData ($ staticBlock );
84
+ $ result = $ blockModel ->save ();
85
+ return $ result ;
86
+ }
87
+
88
+ return false ;
89
+ }
90
+
91
+ /**
92
+ * Update static block
93
+ * @param $data
94
+ * @return $this|bool
95
+ */
96
+ public function updateBlock ($ data )
97
+ {
98
+ $ identifier = $ data ['identifier ' ];
99
+
100
+ $ staticBlock = array (
101
+ 'title ' => $ data ['title ' ],
102
+ 'content ' => $ data ['content ' ],
103
+ 'is_active ' => $ data ['is_active ' ]
104
+ );
105
+
106
+ $ blockModel = Mage::getModel ('cms/block ' )->load ($ identifier , 'identifier ' );
107
+
108
+ if ($ blockModel ){
109
+ $ blockModel ->addData ($ staticBlock )->save ();
110
+ return true ;
111
+ }
112
+ return false ;
71
113
72
114
}
73
115
0 commit comments