Exemplo n.º 1
0
 /**
  * Generate and updates mails.
  * @param  String $template HTML template to serve as a base.
  * @param  Array $data      New datas for emails and footer to use
  *                          to generate and update emails in oc_t_pages.
  * @return int 				Number of locales updated.
  */
 public function update($template, $id, $newDatas, $nEmail)
 {
     $m = new Mustache_Engine();
     $activeLocales = Madhouse_Utils_Collections::getFieldsFromList(osc_get_locales(), "pk_c_code");
     if ($nEmail["s_internal_name"] == "exemple_page") {
         mdh_error_log(array($nEmail));
     }
     $i = 0;
     foreach ($nEmail["locales"] as $l) {
         // Find the correct footer content.
         $footer = Madhouse_Utils_Collections::findByField($newDatas["footer"]["locales"], "fk_c_locale_code", $l["fk_c_locale_code"]);
         if (in_array($l["fk_c_locale_code"], $activeLocales) && !Madhouse_EmailMagick_Utils::isLocaleEmpty($l)) {
             // Updates the description using DAO method.
             Page::newInstance()->updateDescription($id, $l["fk_c_locale_code"], $l["s_title"], $m->render($template, array("CONTENT" => $l["s_text"], "TITLE" => $l["s_title"], "EXCERPT" => $l["s_excerpt"], "FOOTER" => $footer["s_text"])));
             $i++;
         }
     }
     return $i;
 }
Exemplo n.º 2
0
 /**
  * Computes the filling rate (percentage) of an email.
  * @param  Email $e  The email to compute the filling rate for.
  * @return Int    	 An integer, from 0 to 100%.
  */
 public static function computeFillingRate($e)
 {
     $activeLocales = Madhouse_Utils_Collections::getFieldsFromList(osc_get_locales(), "pk_c_code");
     // Make some calculation on ACTIVES locales.
     // (non-active locales are not considered, see array_filter)
     $filled = array_map(function ($l) {
         $sum = 0;
         if (!empty($l["s_title"])) {
             $sum += 0.5;
         }
         if (!empty($l["s_text"])) {
             $sum += 0.5;
         }
         return $sum;
     }, array_values(array_filter($e["locales"], function ($l) use($activeLocales) {
         if (!in_array($l["fk_c_locale_code"], $activeLocales)) {
             return false;
         }
         return true;
     })));
     return ceil(array_sum($filled) * 100 / count($filled));
 }