محمد زاهر غيبة

مزود التغذية

عنصر تاريخ الميلاد في زيند

04.16.2010, برمجيات مفتوحة المصدر, تقينة المعلومات, مصروفي, بواسطة : .

تم تحديث الكود على الرابط التالي : اضغط هنا

في خلال مراحل تطوير مشروع مصروفي ، عانينا من انشاء عنصر لتحديد تاريخ الولادة كما هو الحال مثلاً في موقع facebook أو اي موقع آخر ..
كان من الممكن ان نقوم بكتابة هذا العنصر بالشكل العادي ضمن الكود الخاص بالـ HTML ، و لكننا قررنا الاعتماد على ماتقدمه منصة عمل زيند من امكانيات ، ألا و هي امكانية انشاء العنصر برمجياً ..
حاولنا و قرأنا و بعد جهد جهيد حصلنا على مانريد ..
قد يكون الكود البرمجي الحالي ضعيف لكنه يقوم حالياً بأداء العمل …
و اليكم الكود البرمجي ..

1- الكود البرمجي لـ View Helper الخاص بالعنصر :

/*
 *     This file was created by Creative Web Group Syria , Developement Team
 *     website : http://www.creativewebgroup-sy.com
 *     email : info@creativewebgroup-sy.com
*/

/**
 *
 * @author Creative Web Group Syria
 */
class Msrofi_View_Helper_BirthElement
    extends Zend_View_Helper_FormElement
{
    protected $html = '';

    public function birthElement($name, $value = null, $attribs = null , $options = null)
    {
        $day = $month = $year = '';

        if (is_array($value)){
                $day = (isset($value['day'])) ? $value['day'] : '';
                $month = (isset($value['month'])) ? $value['month'] : '';
                $year = (isset($value['year'])) ? $value['year'] : '';
        }else{
            list($year, $month , $day) = split('-',$value);
        }

        $helper = new Zend_View_Helper_FormSelect();
        $helper->setView($this->view);

        $this->html .= $helper->formSelect($name . '[day]', $day , null, $options['day']);
        $this->html .= ' / ' .$helper->formSelect($name . '[month]', $month , null, $options['month']);
        $this->html .= ' / ' .$helper->formSelect($name . '[year]', $year , null, $options['year']);

        return $this->html;
    }

}

2- الكود البرمجي لعنصر تاريخ الميلاد :

/*
 *     This file was created by Creative Web Group Syria , Developement Team
 *     website : http://www.creativewebgroup-sy.com
 *     email : info@creativewebgroup-sy.com
*/

/**
 *
 * @author Creative Web Group Syria
 */
class Msrofi_Form_Element_Birth extends Zend_Form_Element_Multi {

    public $helper = 'birthElement';

    protected $_dateFormat = '%year%-%month%-%day%';
    protected $_day = null;
    protected $_month = null;
    protected $_year = null;

    public function setDay($num)
    {
        $this->_day = $num;
        return $this;
    }

    public function setMonth($num)
    {
        $this->_month =  $num;
        return $this;
    }

    public function setYear($num)
    {
        $this->_year = $num;
        return $this;
    }

    public function setValue($value)
    {
        if (is_array($value)
                      && (isset($value['day'])
                          && isset($value['month'])
                          && isset($value['year'])
                      )
            ) {
            $this->setYear($value['year'])
                    ->setMonth($value['month'])
                    ->setDay($value['day']);

            $value = str_replace(
                array('%year%', '%month%', '%day%'),
                array($this->_year, $this->_month, $this->_day),
                $this->_dateFormat
            );

        }else {
            throw new Exception('Invalid date value provided');
        }

        return parent::setValue($value);
    }

    public function getValue()
    {
        if(!isset($this->_year) || !isset($this->_month) || !isset($this->_day)){

            $data = false;

        }else{

            $data= str_replace(
                array('%year%', '%month%', '%day%'),
                array($this->_year, $this->_month, $this->_day),
                $this->_dateFormat
            );
        }
        return $data ;
    }
}

3- الكود البرمجي الخاص بانشاء العنصر ضمن النموذج :

        $dateOfBirth = new Msrofi_Form_Element_Birth('dateOfBirth');
        $dateOfBirth->setLabel('تاريخ الولادة ')
                ->addValidator('NotEmpty',true,array('messages'=>array('isEmpty'=>'لايمكن ان تكون القيمة فارغة')))
                ->addValidator(new Zend_Validate_Date(array('format' => 'Y-n-j')))
                ->setRequired(true);

و النتيجة :
Msrofi Date Of Birth Element
و هانحن نشارككم الكود البرمجي ، كي تستفيدوا مما نستخدم و تستخدمون ، و في حالة كتبتم ام استفدتم مما كتبنا فلا تنسونا من الدعاء .
و إن طورتم ما كتبنا بطريقة افضل فاخبرونا كي نستفيد من تجاربكم ايضاً .

رد واحد على عنصر تاريخ الميلاد في زيند

  1. التنبيهات: [تحديث] عنصر تاريخ الميلاد في منصة عمل زيند « محمد زاهر غيبة

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>